Skip to main content

AI-powered Werewolf game with LLM integration and TUI interface

Project description

LLM Werewolf ๐Ÿบ

PyPI version python uv Ruff Pydantic v2 tests code-quality license PRs contributors

An AI Werewolf game that supports multiple LLM models, with a beautiful Terminal User Interface (TUI).

Other languages: English | ็น้ซ”ไธญๆ–‡ | ็ฎ€ไฝ“ไธญๆ–‡

Features

  • ๐ŸŽฎ Complete Game Logic: Full implementation of Werewolf rules with 20+ roles.
  • ๐Ÿค– LLM Integration: Unified agent interface for easy integration with any LLM (OpenAI, Anthropic, DeepSeek, local models, etc.).
  • โšก Streaming Responses: LLM agents use streaming API by default, reducing perceived wait time with faster first-token response.
  • ๐Ÿ–ฅ๏ธ Beautiful TUI: Real-time game visualization using the Textual framework, supporting an interactive terminal interface.
  • ๐Ÿ‘ค Human Players: Supports mixed games with human players and AIs.
  • โš™๏ธ Configurable: Flexibly configure players and game parameters through YAML configuration files.
  • ๐Ÿ“Š Event System: Complete event logging and game state tracking.
  • ๐Ÿงช Fully Tested: High code coverage and a complete test suite.

Quick Start

Installation

# Clone the repository
git clone https://github.com/Mai0313/LLMWereWolf.git
cd LLMWereWolf

# Install dependencies
uv sync

Running the Game

The project offers two execution modes, selectable through different command-line entries:

TUI Mode (Interactive Terminal Interface):

# Start TUI with the built-in demo configuration (using demo agents for testing)
uv run llm-werewolf-tui configs/demo.yaml

# Use LLM player configuration (requires setting API keys first)
uv run llm-werewolf-tui configs/gpt-5-chaos.yaml

# If the package is installed globally
llm-werewolf-tui configs/demo.yaml

# Using the werewolf-tui alias
uv run werewolf-tui configs/demo.yaml

Console Mode (Pure Text Logs):

# Use Console mode (automatic execution)
uv run llm-werewolf configs/demo.yaml

# Or use the alias
uv run werewolf configs/demo.yaml

YAML Configuration File Options:

  • language: <language-code>: Sets the game language (e.g., en-US, zh-TW, zh-CN). Default: en-US.
  • players: [...]: Defines the list of players. The number of players (6-20) will automatically determine the role composition.

Environment Configuration

Create a .env file to configure LLM API keys:

# OpenAI
OPENAI_API_KEY=sk-...

# Anthropic
ANTHROPIC_API_KEY=sk-ant-...

# DeepSeek
DEEPSEEK_API_KEY=sk-...

# xAI (Grok)
XAI_API_KEY=xai-...

# Local models (Ollama, etc.) do not require an API key
# Just set the base_url in the YAML file

Supported Roles

Werewolf Faction ๐Ÿบ

  • Werewolf: Standard werewolf that kills collectively at night.
  • AlphaWolf: Can take a player with them when eliminated.
  • WhiteWolf: Can kill another werewolf every other night to become a lone wolf.
  • WolfBeauty: Charms a player; if the Wolf Beauty dies, the charmed player also dies.
  • GuardianWolf: Can protect one werewolf each night.
  • HiddenWolf: Appears as a villager to the Seer.
  • BloodMoonApostle: Can be converted into a werewolf.
  • NightmareWolf: Can block a player's ability.

Villager Faction ๐Ÿ‘ฅ

  • Villager: A regular villager with no special abilities.
  • Seer: Can check one player's identity (werewolf or villager) each night.
  • Witch: Has a healing potion and a poison potion (each for one-time use).
  • Hunter: Can take a player with them when eliminated.
  • Guard: Can protect one player from a werewolf attack each night.
  • Idiot: If voted out, reveals their identity and survives but loses voting rights.
  • Elder: Requires two attacks to be killed.
  • Knight: Can duel a player once per game.
  • Magician: Can swap the roles of two players once.
  • Cupid: Links two players as lovers on the first night.
  • Raven: Marks a player to receive an extra vote.
  • GraveyardKeeper: Can check the identity of dead players.

Neutral Roles ๐Ÿ‘ป

  • Thief: Can choose a role from two extra role cards on the first night.
  • Lover: Linked by Cupid; if one dies, the other dies of a broken heart.
  • WhiteLoverWolf: A special werewolf variant that can form lover relationships.

Configuration

Automatic Role Assignment

The game automatically generates balanced role compositions based on the number of players (6-20). No need to manually configure presets!

How it works:

  • 6-8 players: 2 Werewolves + Seer, Witch + Villagers
  • 9-11 players: 3 Werewolves (including AlphaWolf) + Seer, Witch, Hunter, Guard + Villagers
  • 12-14 players: 4 Werewolves (including AlphaWolf, WhiteWolf) + Seer, Witch, Hunter, Guard, Cupid, Idiot + Villagers
  • 15+ players: 5 Werewolves + More divine roles (Elder, Knight, Raven, etc.) + Villagers

The system scales werewolf count and divine roles automatically to maintain game balance.

Custom Configuration

Player Configuration File

# Start from the demo configuration (all demo agents)
cp configs/demo.yaml my-game.yaml

# Or start from a template that supports LLMs
cp configs/gpt-5-chaos.yaml my-game.yaml

# Edit the configuration file
# configs/gpt-5-chaos.yaml contains field descriptions and examples

Example my-game.yaml:

language: en-US          # Language code (en-US, zh-TW, zh-CN)

players:
  # The game will automatically assign roles based on the number of players
  # 6 players example below will get: 2 Werewolves + Seer + Witch + 2 Villagers

  - name: GPT-4o Detective
    model: gpt-4o
    base_url: https://api.openai.com/v1
    api_key_env: OPENAI_API_KEY

  - name: GPT-4o-mini Player
    model: gpt-4o-mini
    base_url: https://api.openai.com/v1
    api_key_env: OPENAI_API_KEY

  - name: GPT-4 Analyst
    model: gpt-4
    base_url: https://api.openai.com/v1
    api_key_env: OPENAI_API_KEY

  - name: Claude Sonnet
    model: claude-sonnet-4-20250514
    base_url: https://api.anthropic.com/v1
    api_key_env: ANTHROPIC_API_KEY

  - name: DeepSeek Thinker
    model: deepseek-reasoner
    base_url: https://api.deepseek.com/v1
    api_key_env: DEEPSEEK_API_KEY

  - name: Claude Haiku
    model: claude-haiku-4-5-20251001
    base_url: https://api.anthropic.com/v1
    api_key_env: ANTHROPIC_API_KEY

  - name: Human Player
    model: human          # Human player

  - name: Local Llama
    model: llama3
    base_url: http://localhost:11434/v1
    # Local models do not need api_key_env

  - name: Test Bot
    model: demo           # Simple agent for testing

Configuration Description:

  • language: Optional, defaults to en-US, sets the game language (e.g., en-US, zh-TW, zh-CN).
  • players: Required, list of players (6-20 players). The game will automatically generate balanced role compositions based on player count.

Player Configuration Fields:

  • name: Player's display name.
  • model: Model type.
    • human: Human player (input via terminal).
    • demo: Simple agent for testing (random responses).
    • LLM model name: e.g., gpt-4o, gpt-4o-mini, claude-sonnet-4-20250514, claude-haiku-4-20250514, deepseek-reasoner, llama3, or any OpenAI-compatible model.
  • base_url: API endpoint (required for LLM models).
  • api_key_env: Environment variable name (required for authenticated endpoints).
  • reasoning_effort: Optional, reasoning effort level for models that support it (e.g., "low", "medium", "high").

Supported Model Types:

  • OpenAI-Compatible API: Any model that supports the OpenAI Chat Completions format.
  • Human Player: model: human
  • Test Agent: model: demo

Local Model Example:

If using a local model like Ollama, you can omit api_key_env:

  - name: Ollama Llama3
    model: llama3
    base_url: http://localhost:11434/v1

Agent System

Agent Types

This project provides three built-in agent types:

  1. LLMAgent: Supports any LLM model with an OpenAI-compatible API (GPT-4, Claude, DeepSeek, Grok, local models, etc.).
  2. HumanAgent: Human player input via the terminal.
  3. DemoAgent: A simple agent for testing (random responses).

All agents are configured through YAML files (see the Configuration section). The game supports mixing different agent types in a single game.

TUI Interface

The TUI (Terminal User Interface) provides real-time game visualization with a modern terminal interface, built with the Textual framework.

Capturing Screenshots

To capture TUI screenshots for documentation:

# Method 1: Using terminal screenshot tool
# Run the game in TUI mode and use your terminal's screenshot feature
uv run llm-werewolf-tui configs/demo.yaml

# Method 2: Using textual's screenshot feature (if available)
# The Textual framework may provide built-in screenshot capabilities

# Method 3: Using asciinema for terminal recording
asciinema rec werewolf-demo.cast
uv run llm-werewolf-tui configs/demo.yaml
# Press Ctrl+D to stop recording

Interface Preview (Text Representation)

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ๐Ÿบ Werewolf Game                                                       AI-Powered Werewolf     โ”‚
โ”‚ q Quit  d Toggle Debug                                                           [00:02:34]     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                      โ”‚ โ•ญโ”€โ”€โ”€โ”€โ”€ Game Status โ”€โ”€โ”€โ”€โ”€โ•ฎ               โ”‚                               โ”‚
โ”‚    Players           โ”‚ โ”‚ ๐ŸŒ™ Round 2 - Night    โ”‚               โ”‚    Debug Info                 โ”‚
โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€   โ”‚ โ”‚                       โ”‚               โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€   โ”‚
โ”‚ Name      Model      โ”‚ โ”‚ Total Players: 8/9    โ”‚               โ”‚ Session ID:                   โ”‚
โ”‚           Status     โ”‚ โ”‚ Werewolves:    2      โ”‚               โ”‚   ww_20251019_163022          โ”‚
โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€   โ”‚ โ”‚ Villagers:     6      โ”‚               โ”‚                               โ”‚
โ”‚ Alice     gpt-4o     โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ                 โ”‚ Config: players.yaml          โ”‚
โ”‚           โœ“ ๐Ÿ›ก๏ธ      โ”‚                                          โ”‚                               โ”‚
โ”‚ Bob       claude     โ”‚                                          โ”‚ Players: 9                    โ”‚
โ”‚           โœ“          โ”‚                                          โ”‚ AI: 7  Human: 1  Demo: 1      โ”‚
โ”‚ Charlie   llama3     โ”‚                                          โ”‚                               โ”‚
โ”‚           โœ“          โ”‚                                          โ”‚ Roles:                        โ”‚
โ”‚ David     deepseek   โ”‚ โ•ญโ”€โ”€โ”€โ”€ Events / Chat โ”€โ”€โ”€โ”€โ•ฎ               โ”‚  - Werewolf x2                โ”‚
โ”‚           โœ“ โค๏ธ       โ”‚ โ”‚ [00:02:28] ๐ŸŽฎ Game Startโ”‚               โ”‚  - Seer x1                    โ”‚
โ”‚ Eve       grok       โ”‚ โ”‚ [00:02:29] โฐ Phase: Nightโ”‚               โ”‚  - Witch x1                   โ”‚
โ”‚           โœ“ โค๏ธ       โ”‚ โ”‚ [00:02:30] ๐Ÿบ Werewolves Discussโ”‚       โ”‚  - Hunter x1                  โ”‚
โ”‚ Frank     human      โ”‚ โ”‚            Target       โ”‚               โ”‚  - Guard x1                   โ”‚
โ”‚           โœ“          โ”‚ โ”‚ [00:02:31] โฐ Phase: Dayโ”‚               โ”‚  - Villager x3                โ”‚
โ”‚ Grace     claude     โ”‚ โ”‚ [00:02:32] ๐Ÿ’€ Iris Diedโ”‚               โ”‚                               โ”‚
โ”‚           โœ“          โ”‚ โ”‚ [00:02:33] ๐Ÿ’ฌ Alice:  โ”‚               โ”‚ Night Timeout: 60s            โ”‚
โ”‚ Henry     demo       โ”‚ โ”‚            "I think Bob โ”‚               โ”‚ Day Timeout: 300s             โ”‚
โ”‚           โœ“          โ”‚ โ”‚            is suspicious" โ”‚               โ”‚ Vote Timeout: 60s             โ”‚
โ”‚ Iris      demo       โ”‚ โ”‚ [00:02:34] ๐Ÿ’ฌ Bob:    โ”‚               โ”‚                               โ”‚
โ”‚           โœ—          โ”‚ โ”‚            "I'm a villager!โ”‚           โ”‚ Errors: 0                     โ”‚
โ”‚                      โ”‚ โ”‚            Alice is trying โ”‚           โ”‚                               โ”‚
โ”‚                      โ”‚ โ”‚            to deflect"    โ”‚           โ”‚ Source: YAML Config           โ”‚
โ”‚                      โ”‚ โ”‚ [00:02:35] ๐Ÿ’ฌ Charlie: โ”‚               โ”‚                               โ”‚
โ”‚                      โ”‚ โ”‚            "Last night's deathโ”‚       โ”‚                               โ”‚
โ”‚                      โ”‚ โ”‚            pattern is strange"โ”‚       โ”‚                               โ”‚
โ”‚                      โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ               โ”‚                               โ”‚
โ”‚                      โ”‚                                          โ”‚                               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Panel Descriptions

Player Panel (Left)

Displays information for all players:

  • Name: Player's display name.
  • Model: The AI model used, or human/demo.
  • Status Indicators:
    • โœ“: Alive
    • โœ—: Dead
    • ๐Ÿ›ก๏ธ: Protected by the Guard
    • โค๏ธ: In a lover relationship
    • โ˜ ๏ธ: Poisoned by the Witch
    • ๐Ÿ”ด: Marked by the Raven

Game Panel (Top Center)

Displays the current game status:

  • Round and Phase:
    • ๐ŸŒ™ Night Phase
    • โ˜€๏ธ Day Discussion Phase
    • ๐Ÿ—ณ๏ธ Voting Phase
    • ๐Ÿ Game Over
  • Player Statistics: Number of surviving players by faction.
  • Vote Count (during voting phase): Shows the number of votes each player has received.

Chat Panel (Bottom Center)

A scrollable event log showing all events and dialogue in the game:

  • ๐Ÿ’ฌ Player Speech: AI-generated discussions, accusations, and defenses.
  • ๐ŸŽฎ Game Events: Game start, phase changes, etc.
  • โฐ Phase Changes: Night, Day, Voting, etc.
  • ๐Ÿ’€ Death Events: Player death notifications.
  • ๐Ÿบ Werewolf Actions: Werewolf discussions at night.
  • ๐Ÿ”ฎ Skill Usage: Records of each role's skill usage.

Events are color-coded by importance for quick identification of key information.

TUI Controls

  • q: Quit the game.
  • Mouse Wheel: Scroll through the chat history.
  • Arrow Keys: Move between focusable components.

The game runs automatically once started - no manual intervention is required.

Console Mode

If you prefer not to use the TUI, you can use the llm-werewolf or werewolf command, and the game will run automatically with output as plain text logs in the terminal.

Console mode displays real-time status indicators to help you track game progress:

  • ๐ŸŽฌ Night Phase: Shows each role taking action (e.g., ๐ŸŽฌ Seer(gpt-4) is acting...)
  • ๐Ÿ’ฌ Day Discussion: Shows each player preparing their speech (e.g., ๐Ÿ’ฌ Alice(gpt-4) is thinking...)
  • ๐Ÿ—ณ๏ธ Voting Phase: Shows each player preparing their vote (e.g., ๐Ÿ—ณ๏ธ Bob(gpt-4) is thinking about voting...)

These indicators help you understand the game is waiting for LLM API responses, not frozen. LLM responses typically take several seconds to tens of seconds.

Console Mode Example Output:

๐ŸŽฎ Game Starting with 9 players...
๐Ÿ“‹ Role Assignment Complete
   - Werewolf x2
   - Seer x1
   - Witch x1
   - Hunter x1
   - Guard x1
   - Villager x3

๐ŸŒ™ === Round 1: Night Phase ===
๐Ÿบ Werewolves are discussing their target...
๐ŸŽฌ Guard(gpt-4o) is acting...
   โ†’ Guard protected Alice
๐ŸŽฌ Seer(claude-sonnet) is acting...
   โ†’ Seer checked Bob: Villager
๐ŸŽฌ Werewolf(gpt-4o-mini) is acting...
   โ†’ Werewolves killed Charlie
๐ŸŽฌ Witch(deepseek-reasoner) is acting...
   โ†’ Witch used save potion on Charlie

โ˜€๏ธ === Round 1: Day Phase ===
๐Ÿ’ฌ Alice(gpt-4o) is thinking...
๐Ÿ’ฌ Alice: "Last night was quiet, but we need to find the werewolves."
๐Ÿ’ฌ Bob(claude-sonnet) is thinking...
๐Ÿ’ฌ Bob: "I noticed David acting suspicious yesterday."
...

๐Ÿ—ณ๏ธ === Voting Phase ===
๐Ÿ—ณ๏ธ Alice(gpt-4o) is thinking about voting...
   โ†’ Alice voted for David
๐Ÿ—ณ๏ธ Bob(claude-sonnet) is thinking about voting...
   โ†’ Bob voted for David
...

๐Ÿ“Š Vote Results:
   David: 5 votes
   Eve: 3 votes
   Frank: 1 vote

๐Ÿ’€ David was eliminated (Villager)

๐Ÿ === Game Over ===
๐ŸŽ‰ Werewolves Win!
   Remaining: Werewolf x2, Villager x2

Game Flow

  1. Preparation Phase: Players are randomly assigned roles.
  2. Night Phase:
    • ๐ŸŒ™ Narrator: "Night falls, everyone close your eyes..."
    • ๐Ÿบ Werewolf Discussion: Multiple werewolves discuss who to eliminate (skipped if only one werewolf)
    • ๐Ÿบ Werewolf Vote: Werewolves vote for their target
    • ๐ŸŽฌ Other Roles Act: Other roles with night abilities act in priority order (Seer, Witch, Guard, etc.)
    • ๐ŸŒ™ Narrator: "Werewolves, close your eyes..."
  3. Day Discussion:
    • โ˜€๏ธ Narrator: "The sun rises, everyone open your eyes..."
    • ๐Ÿ’ฌ Players speak in turn, discussing and sharing information
  4. Day Voting:
    • ๐Ÿ—ณ๏ธ Players vote to eliminate a suspect
  5. Victory Check: The game checks if any faction has won.
  6. Repeat steps 2-5 until victory conditions are met.

Victory Conditions

The game checks for victory conditions at the end of each phase:

  • Villager Faction Wins: All werewolves are eliminated.
  • Werewolf Faction Wins: The number of werewolves is greater than or equal to the number of villagers.
  • Lovers Win: Only the two lovers remain alive (lover victory takes precedence over faction victory).

Project Architecture

The project uses a modular architecture with clear responsibilities for each module:

src/llm_werewolf/
โ”œโ”€โ”€ cli.py                 # Command-line entry point (console mode)
โ”œโ”€โ”€ tui.py                 # TUI entry point (interactive mode)
โ”œโ”€โ”€ ai/                    # Agent system
โ”‚   โ””โ”€โ”€ agents.py         # LLM agent implementation and config models
โ”œโ”€โ”€ core/                 # Core game logic
โ”‚   โ”œโ”€โ”€ agent.py          # Base agent, HumanAgent, and DemoAgent
โ”‚   โ”œโ”€โ”€ game_state.py     # Game state management
โ”‚   โ”œโ”€โ”€ player.py         # Player class
โ”‚   โ”œโ”€โ”€ action_selector.py # Action selection logic
โ”‚   โ”œโ”€โ”€ events.py         # Event system
โ”‚   โ”œโ”€โ”€ event_formatter.py # Event formatting for display
โ”‚   โ”œโ”€โ”€ locale.py         # Localization and language support
โ”‚   โ”œโ”€โ”€ victory.py        # Victory condition checking
โ”‚   โ”œโ”€โ”€ serialization.py  # Serialization utilities
โ”‚   โ”œโ”€โ”€ role_registry.py  # Role registration and validation
โ”‚   โ”œโ”€โ”€ engine/           # Game engine (split into mixins)
โ”‚   โ”‚   โ”œโ”€โ”€ game_engine.py     # Main game engine (combines mixins)
โ”‚   โ”‚   โ”œโ”€โ”€ base.py            # Core initialization and game loop
โ”‚   โ”‚   โ”œโ”€โ”€ night_phase.py     # Night phase execution logic
โ”‚   โ”‚   โ”œโ”€โ”€ day_phase.py       # Day discussion phase logic
โ”‚   โ”‚   โ”œโ”€โ”€ voting_phase.py    # Voting phase logic
โ”‚   โ”‚   โ”œโ”€โ”€ death_handler.py   # Death-related logic
โ”‚   โ”‚   โ””โ”€โ”€ action_processor.py # Processing game actions
โ”‚   โ”œโ”€โ”€ actions/          # Action system
โ”‚   โ”‚   โ”œโ”€โ”€ base.py       # Base action class
โ”‚   โ”‚   โ”œโ”€โ”€ common.py     # Common actions
โ”‚   โ”‚   โ”œโ”€โ”€ villager.py   # Villager faction actions
โ”‚   โ”‚   โ””โ”€โ”€ werewolf.py   # Werewolf faction actions
โ”‚   โ”œโ”€โ”€ config/           # Configuration system
โ”‚   โ”‚   โ”œโ”€โ”€ game_config.py    # Game configuration model
โ”‚   โ”‚   โ””โ”€โ”€ presets.py        # Auto role generation based on player count
โ”‚   โ”œโ”€โ”€ types/            # Type definitions
โ”‚   โ”‚   โ”œโ”€โ”€ enums.py      # Enums (Camp, Phase, Status, etc.)
โ”‚   โ”‚   โ”œโ”€โ”€ models.py     # Data models
โ”‚   โ”‚   โ””โ”€โ”€ protocols.py  # Protocol definitions
โ”‚   โ””โ”€โ”€ roles/            # Role implementations
โ”‚       โ”œโ”€โ”€ base.py       # Base role class
โ”‚       โ”œโ”€โ”€ werewolf.py   # Werewolf faction roles
โ”‚       โ”œโ”€โ”€ villager.py   # Villager faction roles
โ”‚       โ””โ”€โ”€ neutral.py    # Neutral roles
โ””โ”€โ”€ ui/                   # User interface
    โ”œโ”€โ”€ tui_app.py        # TUI application
    โ”œโ”€โ”€ styles.py         # TUI styles
    โ””โ”€โ”€ components/       # TUI components
        โ”œโ”€โ”€ player_panel.py
        โ”œโ”€โ”€ game_panel.py
        โ””โ”€โ”€ chat_panel.py

Module Descriptions

  • cli.py: Command-line interface for console mode, responsible for loading configurations and starting the game automatically.
  • tui.py: TUI entry point for interactive mode with terminal user interface.
  • ai/: LLM agent implementation and configuration models (PlayerConfig, PlayersConfig).
  • core/agent.py: Base agent protocol and built-in agents (HumanAgent, DemoAgent).
  • core/engine/: Game engine implementation split into mixins for clean separation of concerns:
    • game_engine.py: Main GameEngine class that combines all mixins
    • base.py: Core initialization, event handling, and main game loop
    • night_phase.py: Night phase execution logic (werewolf discussion, role actions)
    • day_phase.py: Day discussion phase logic
    • voting_phase.py: Voting phase logic
    • death_handler.py: Death-related logic (werewolf kills, lover deaths, etc.)
    • action_processor.py: Processing and applying game actions
  • core/actions/: Action system with base classes and faction-specific actions.
  • core/config/: Configuration system, containing game parameters and automatic role generation.
  • core/types/: Type definitions including enums, data models, and protocol definitions.
  • core/event_formatter.py: Centralized event formatting for consistent display across console and TUI modes.
  • core/locale.py: Localization support for multiple languages (en-US, zh-TW, zh-CN).
  • core/: Core game logic, including roles, players, game state, action selection, events, and victory checking.
  • ui/: Terminal user interface based on the Textual framework.

System Requirements

  • Python: 3.10 or higher
  • Operating System: Linux, macOS, Windows
  • Terminal: A modern terminal that supports ANSI colors and Unicode (for TUI).

Main Dependencies

  • pydantic (โ‰ฅ2.12.3): Data validation and settings management.
  • textual (โ‰ฅ6.3.0): TUI framework.
  • rich (โ‰ฅ14.2.0): Terminal formatting.
  • openai (โ‰ฅ2.5.0): OpenAI API client (for LLM integration).
  • python-dotenv (โ‰ฅ1.1.1): Environment variable management.
  • pyyaml (โ‰ฅ6.0.3): YAML configuration file parsing.
  • fire (โ‰ฅ0.7.1): Command-line interface.
  • logfire (โ‰ฅ4.13.2): Structured logging.

FAQ

How do I add more players?

Edit your YAML configuration file and add player configurations to the players list. The game will automatically generate balanced role compositions based on the total number of players (6-20 supported).

Can I mix different LLM models?

Yes! You can use different LLM providers and models in the same game, for example, using GPT-4, Claude, and a local Llama model simultaneously.

How do I let a human player join the game?

In the YAML configuration, set a player's model to human. During the game, that player will need to respond via terminal input.

How do I set up a local model (Ollama)?

Make sure Ollama is running, then set it up in the YAML file:

  - name: Ollama Player
    model: llama3
    base_url: http://localhost:11434/v1

You do not need to set api_key_env.

How do I customize game settings?

The game automatically generates balanced role compositions based on player count (6-20). Role assignments and timeouts are automatically adjusted as the number of players increases. For advanced customization of the role generation logic, see create_game_config_from_player_count() in src/llm_werewolf/core/config/presets.py.

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! You can participate in the following ways:

  1. Report Issues: Report bugs or suggest features on the Issues page.
  2. Submit Pull Requests: Fix bugs or add new features.
  3. Improve Documentation: Help improve the README and code comments.
  4. Share Feedback: Tell us about your experience using the project.

Contribution Flow

  1. Fork this project.
  2. Create a feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m 'Add some amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Open a Pull Request.

Please ensure your code:

  • Follows the project's code style (using Ruff).
  • Includes appropriate tests.
  • Updates relevant documentation.

Acknowledgements

This project is built with these excellent open-source tools:

  • Pydantic - Data validation and settings management.
  • Textual - Modern TUI framework.
  • Rich - Beautiful terminal output.
  • OpenAI Python SDK - LLM API client.
  • uv - A fast Python package manager.
  • Ruff - An extremely fast Python linter.

Related Links

Changelog

Please see the Releases page for the version update history.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_werewolf-0.0.0.tar.gz (267.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_werewolf-0.0.0-py3-none-any.whl (93.1 kB view details)

Uploaded Python 3

File details

Details for the file llm_werewolf-0.0.0.tar.gz.

File metadata

  • Download URL: llm_werewolf-0.0.0.tar.gz
  • Upload date:
  • Size: 267.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for llm_werewolf-0.0.0.tar.gz
Algorithm Hash digest
SHA256 32ce517488bcdd5facd8a397cccbac09430e0d6674c04cba5ce5f2a3efb13fd0
MD5 b2dc55b50c8ebb79d56f085a60d45460
BLAKE2b-256 b9ff07111d9a617f9a8a5145d17949677c8801cfdf7b69a6275f5fa8be7fc735

See more details on using hashes here.

File details

Details for the file llm_werewolf-0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_werewolf-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c481f66d6f8eb45c4ebe09e99214200b9222bc2ae4fa93c09cac5eb8864433a1
MD5 437c0a8799a56d843df13d7538c26560
BLAKE2b-256 77a448a12699f0584ccde389e74b85e6cfedc21448772ab006d1cbeb6a712759

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page