AI-powered Werewolf game with LLM integration and TUI interface
Project description
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 toen-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:
- LLMAgent: Supports any LLM model with an OpenAI-compatible API (GPT-4, Claude, DeepSeek, Grok, local models, etc.).
- HumanAgent: Human player input via the terminal.
- 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
- Preparation Phase: Players are randomly assigned roles.
- 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..."
- Day Discussion:
- โ๏ธ Narrator: "The sun rises, everyone open your eyes..."
- ๐ฌ Players speak in turn, discussing and sharing information
- Day Voting:
- ๐ณ๏ธ Players vote to eliminate a suspect
- Victory Check: The game checks if any faction has won.
- 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:
- Report Issues: Report bugs or suggest features on the Issues page.
- Submit Pull Requests: Fix bugs or add new features.
- Improve Documentation: Help improve the README and code comments.
- Share Feedback: Tell us about your experience using the project.
Contribution Flow
- Fork this project.
- Create a feature branch (
git checkout -b feature/amazing-feature). - Commit your changes (
git commit -m 'Add some amazing feature'). - Push to the branch (
git push origin feature/amazing-feature). - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32ce517488bcdd5facd8a397cccbac09430e0d6674c04cba5ce5f2a3efb13fd0
|
|
| MD5 |
b2dc55b50c8ebb79d56f085a60d45460
|
|
| BLAKE2b-256 |
b9ff07111d9a617f9a8a5145d17949677c8801cfdf7b69a6275f5fa8be7fc735
|
File details
Details for the file llm_werewolf-0.0.0-py3-none-any.whl.
File metadata
- Download URL: llm_werewolf-0.0.0-py3-none-any.whl
- Upload date:
- Size: 93.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c481f66d6f8eb45c4ebe09e99214200b9222bc2ae4fa93c09cac5eb8864433a1
|
|
| MD5 |
437c0a8799a56d843df13d7538c26560
|
|
| BLAKE2b-256 |
77a448a12699f0584ccde389e74b85e6cfedc21448772ab006d1cbeb6a712759
|