Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pedrocurvo/TheTraitors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

TheTraitors

TheTraitors: A multi-agent LLM-based social deduction game framework

license python-version supported-models


πŸ“‹ Table of Contents


πŸ“– Overview

TheTraitors is a Python framework for simulating multi-agent social deduction games using Large Language Models (LLMs). It creates dynamic interactions between AI agents playing a social deduction game inspired by the popular TV show "The Traitors."

The framework allows researchers and developers to study:

  • Emergent behaviors in multi-agent LLM systems
  • Strategic reasoning and deception capabilities
  • Social dynamics and coalition formation
  • Theory of mind in language models

✨ Features

  • Agent-based Architecture: Each agent has its own memory, role, and LLM client
  • Multiple LLM Support: Compatible with various providers:
    • OpenAI API (GPT models)
    • Deepseek's API
    • Together AI's API
    • Hugging Face Inference API
    • Local MLX models for Mac with Apple Silicon
  • Extensible Design: Modular architecture makes it easy to customize game rules and agent behaviors
  • Detailed Logging: Comprehensive logs of discussions, votes, and game outcomes
  • Analysis Tools: Utilities for analyzing game dynamics and agent performance
  • Persona System: Agents can have rich backgrounds with traits like age, profession, and nationality
  • Configuration-based: Flexible configuration system using YAML files and command-line arguments
  • Role Enforcement: Option to enforce specific roles for certain agents in experiments
  • Structured Memory: Advanced memory system categorizing information for better agent reasoning

πŸ” Project Structure

TheTraitors/
β”œβ”€β”€ config.yaml             # Sample configuration file
β”œβ”€β”€ main.py                 # Main entry point
β”œβ”€β”€ src/                    # Core source code
β”‚   β”œβ”€β”€ agent.py            # Agent class definition
β”‚   β”œβ”€β”€ llm_client.py       # LLM client classes and factory
β”‚   β”œβ”€β”€ prompt_manager.py   # Manages structured prompts for agents
β”‚   └── traitors_game.py    # Main game engine
β”œβ”€β”€ utils/                  # Utility modules
β”‚   β”œβ”€β”€ config.py           # Configuration handling
β”‚   └── metrics.py          # Game metrics computation
β”œβ”€β”€ tests/                  # Test suite
β”œβ”€β”€ docs/                   # Documentation
└── results/                # Game results directory

πŸš€ Getting Started

πŸ“‹ Prerequisites

  • Python 3.8 or higher
  • API keys for the LLM providers you want to use

βš™οΈ Installation

Setting up a virtual environment

It's recommended to use a virtual environment to manage dependencies:

# Create a virtual environment
python -m venv venv

# Activate the virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

Installing dependencies

Once your virtual environment is activated, install the required dependencies:

pip install -r requirements.txt

For development purposes, you may want to install additional packages:

pip install pytest coverage

Setting up API keys

Create a .env file in the project root with your API keys:

OPENAI_API_KEY=your_openai_api_key
DEEPSEEK_API_KEY=your_deepseek_api_key
TOGETHER_API_KEY=your_together_api_key
HF_API_TOKEN=your_huggingface_token

πŸ“Š Usage

Basic Python API

from src.traitors_game import TraitorsGame

# Load a configuration from a YAML file
config = {
    'game': {
        'agent_count': 10,
        'traitor_count': 3,
        'seed': 42,
        'experiment_name': 'my_experiment'
    },
    'llm': {
        'model': 'gpt-3.5-turbo',
        'client_type': 'openai',
        'provider': 'openai'
    }
}

# Create and run the game
game = TraitorsGame(config=config)
game.run()
game.post_game_analysis()

Command Line Interface

You can also run the game using the command line interface:

# Run with a configuration file
python main.py --config path/to/config.yaml

# Or with direct arguments
python main.py --agents 10 --traitors 3 --model gpt-3.5-turbo --client openai --provider openai --seed 42

Configuration with YAML

Create a YAML configuration file with all game parameters:

game:
  agent_count: 10
  traitor_count: 3
  seed: 42
  experiment_name: experiment_1

llm:
  model: deepseek-chat
  client_type: openai
  provider: deepseek

agent_configs:
  - model: deepseek-chat
    client_type: openai
    enforce_role: Traitor
    traits:
      age: 45
      nationality: American
      profession: Lawyer
      ethnicity: Latino
      civil_status: Married
      gender_pronoun: He
      children: 3

πŸ§ͺ Testing

The project includes a comprehensive test suite. To run the tests:

# Run all tests
python tests/run_tests.py

# Run tests with coverage
python tests/run_tests.py --coverage

# Generate HTML coverage report
make test-html

Alternatively, you can use the provided Makefile:

# Run all tests
make test

# Run tests with coverage
make test-coverage

# Generate HTML coverage report
make test-html

πŸ“š Documentation

The documentation is built with Sphinx and can be found at https://thetraitors.readthedocs.io/.

To build the documentation locally:

# Install Sphinx
pip install sphinx sphinx-rtd-theme

# Build the documentation
cd docs
make html

# View the documentation
open build/html/index.html

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘€ Author

Pedro Curvo

About

The Traitors: Deception and Trust

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages