Created by Alex Duffy @Alx-Ai & Tyler Marques @Tylermarques
This repository extends the original Diplomacy project with sophisticated AI agents powered by Large Language Models (LLMs). Each power in the game is controlled by an autonomous agent that maintains state, forms relationships, conducts negotiations, and makes strategic decisions.
Each power is represented by a DiplomacyAgent with:
The following diagram illustrates the complete information flow and decision-making process for each AI agent:
graph TB
%% Game State Sources
subgraph "Game State Information"
GS[Game State
- Unit Positions
- Supply Centers
- Power Status]
GH[Game History
- Past Orders
- Past Messages
- Phase Results]
PS[Phase Summary
- Successful Moves
- Failed Moves
- Board Changes]
end
%% Agent Internal State
subgraph "Agent State (DiplomacyAgent)"
GOALS[Dynamic Goals
- Expansion targets
- Alliance priorities
- Defense needs]
REL[Relationships
Enemy ↔ Ally Scale]
subgraph "Memory System"
DIARY[Private Diary
Phase-prefixed entries]
ND[Negotiation Diary
- Message analysis
- Trust assessment
- Relationship changes]
OD[Order Diary
- Strategic reasoning
- Risk/reward analysis]
PRD[Phase Result Diary
- Outcome analysis
- Betrayal detection
- Success evaluation]
CONS[Diary Consolidation
Yearly summaries
via Gemini Flash]
end
JOURNAL[Private Journal
Debug logs only]
end
%% Context Building
subgraph "Context Construction"
POC[Possible Order Context
- BFS pathfinding
- Nearest enemies
- Uncontrolled SCs
- Adjacent territories]
BCP[build_context_prompt
Assembles all info]
RECENT[Recent Context
- Last 40 diary entries
- Current relationships
- Active goals]
end
%% LLM Interactions
subgraph "LLM Decision Points"
INIT_LLM[Initialization
Set initial goals
& relationships]
NEG_LLM[Negotiation
Generate messages
Update relationships]
PLAN_LLM[Planning
Strategic directives]
ORD_LLM[Order Generation
Choose moves]
STATE_LLM[State Update
Revise goals
& relationships]
end
%% Prompt Templates
subgraph "Prompt Templates"
PROMPTS[Power-specific prompts
+ Instruction templates
+ Context templates]
end
%% Information Flow
GS --> BCP
GH --> BCP
PS --> STATE_LLM
GOALS --> BCP
REL --> BCP
DIARY --> RECENT
RECENT --> BCP
POC --> BCP
BCP --> NEG_LLM
BCP --> ORD_LLM
BCP --> PLAN_LLM
PROMPTS --> INIT_LLM
PROMPTS --> NEG_LLM
PROMPTS --> PLAN_LLM
PROMPTS --> ORD_LLM
PROMPTS --> STATE_LLM
%% Diary Updates
NEG_LLM --> ND
ORD_LLM --> OD
PS --> PRD
ND --> DIARY
OD --> DIARY
PRD --> DIARY
%% State Updates
INIT_LLM --> GOALS
INIT_LLM --> REL
NEG_LLM --> REL
STATE_LLM --> GOALS
STATE_LLM --> REL
%% Consolidation
DIARY -->|Every 2 years| CONS
CONS -->|Summarized| DIARY
%% Styling
classDef gameState fill:#e74c3c,stroke:#333,stroke-width:2px,color:#fff
classDef agentState fill:#3498db,stroke:#333,stroke-width:2px,color:#fff
classDef context fill:#2ecc71,stroke:#333,stroke-width:2px,color:#fff
classDef llm fill:#f39c12,stroke:#333,stroke-width:2px,color:#fff
classDef memory fill:#9b59b6,stroke:#333,stroke-width:2px,color:#fff
class GS,GH,PS gameState
class GOALS,REL,JOURNAL agentState
class POC,BCP,RECENT context
class INIT_LLM,NEG_LLM,PLAN_LLM,ORD_LLM,STATE_LLM llm
class DIARY,ND,OD,PRD,CONS memory
Phase Summaries: Categorized analysis of what succeeded/failed each turn
Agent Memory Architecture
Journal: Unstructured logs for debugging (not used by LLMs)
Context Building
Historical Context: Recent diary entries provide continuity
LLM Decision Points
lm_game.py - Main game orchestratorSaves game state with phase summaries and agent relationships
ai_diplomacy/agent.py - Stateful agent implementation
DiplomacyAgent class with goals, relationships, and memoryState update logic based on game outcomes
ai_diplomacy/clients.py - LLM abstraction layer
BaseModelClient interface for all LLM providersRetry logic and error handling
ai_diplomacy/possible_order_context.py - Strategic analysis
Rich XML context generation for orders
ai_diplomacy/prompt_constructor.py - Centralized prompt building
Integrates with template system
ai_diplomacy/game_history.py - Phase-by-phase game tracking
The ai_diplomacy/prompts/ directory contains customizable templates:
france_system_prompt.txt)order_instructions.txt, conversation_instructions.txt)# Basic game with negotiations
python lm_game.py --max_year 1910 --num_negotiation_rounds 3
# With strategic planning phase
python lm_game.py --max_year 1910 --planning_phase --num_negotiation_rounds 2
# Custom model assignment (order: AUSTRIA, ENGLAND, FRANCE, GERMANY, ITALY, RUSSIA, TURKEY)
python lm_game.py --models "claude-3-5-sonnet-20241022,gpt-4o,claude-3-5-sonnet-20241022,gpt-4o,claude-3-5-sonnet-20241022,gpt-4o,claude-3-5-sonnet-20241022"
# Run until game completion or specific year
python lm_game.py --num_negotiation_rounds 2 --planning_phase
# Write all artefacts to a chosen directory (auto-resumes if it already exists)
python lm_game.py --run_dir results/game_run_001
# Resume an interrupted game from a specific phase
python lm_game.py --run_dir results/game_run_001 --resume_from_phase S1902M
# Critical-state analysis: resume from an existing run but save new results elsewhere
python lm_game.py \
--run_dir results/game_run_001 \
--critical_state_analysis_dir results/critical_analysis_001 \
--resume_from_phase F1903M
# End the simulation after a particular phase regardless of remaining years
python lm_game.py --run_dir results/game_run_002 --end_at_phase F1905M
# Set the global max_tokens generation limit
python lm_game.py --run_dir results/game_run_003 --max_tokens 8000
# Per-model token limits (AU,EN,FR,GE,IT,RU,TR)
python lm_game.py --run_dir results/game_run_004 \
--max_tokens_per_model "8000,8000,16000,8000,8000,16000,8000"
# Use a custom prompts directory
python lm_game.py --run_dir results/game_run_005 --prompts_dir ./prompts/my_variants
--models (quick guide)Pass one comma-separated list of up to seven model IDs in this fixed order: AUSTRIA, ENGLAND, FRANCE, GERMANY, ITALY, RUSSIA, TURKEY.
Model-ID syntax
<client prefix:>model[@base_url][#api_key]
prefix: – specify the client (openai, openai-requests, openai-responses, anthropic, gemini, deepseek, openrouter, together).@base_url – hit a proxy / alt endpoint.#api_key – inline key (overrides env vars).bash
# gpt-4o on openrouter for all powers:
--models "openrouter:gpt-4o"
# custom URL+apikey for Austria only:
--models "openai:llama-3.2-3b@http://localhost:8000#myapikey,openai:gpt-4o,openai:gpt-4o,openai:gpt-4o,openai:gpt-4o,openai:gpt-4o,openai:gpt-4o"
experiment_runner.pyexperiment_runner.py is a lightweight orchestrator: it spins up many lm_game.py runs in parallel, gathers their artefacts under one experiment directory, and then executes the analysis modules you specify.
All flags that belong to lm_game.py can be passed straight through; the runner validates them and forwards them unchanged to every game instance.
# Run 10 independent games (iterations) in parallel, using a custom prompts dir
# and a single model (GPT-4o) for all seven powers.
python3 experiment_runner.py \
--experiment_dir "results/exp001" \
--iterations 10 \
--parallel 10 \
--max_year 1905 \
--num_negotiation_rounds 0 \
--prompts_dir "ai_diplomacy/prompts" \
--models "gpt-4o,gpt-4o,gpt-4o,gpt-4o,gpt-4o,gpt-4o,gpt-4o"
# Critical-state analysis: resume every run from W1901A (taken from an existing
# base run) and stop after S1902M. Two analysis modules will be executed:
# • summary → aggregated results & scores
# • critical_state → before/after snapshots around the critical phase
python3 experiment_runner.py \
--experiment_dir "results/exp002" \
--iterations 10 \
--parallel 10 \
--resume_from_phase W1901A \
--end_at_phase S1902M \
--num_negotiation_rounds 0 \
--critical_state_base_run "results/test1" \
--prompts_dir "ai_diplomacy/prompts" \
--analysis_modules "summary,critical_state" \
--models "gpt-4o,gpt-4o,gpt-4o,gpt-4o,gpt-4o,gpt-4o,gpt-4o"
(Any other lm_game.py flags—--planning_phase, --max_tokens, etc.—can be added exactly where you’d use them on a single-game run.)
| Flag | Type / Default | Description |
|---|---|---|
--experiment_dir (required) |
Path |
Root folder for the experiment; sub-folders runs/ and analysis/ are managed automatically. Re-running with the same directory will resume existing runs and regenerate analysis. |
--iterations |
int, default 1 |
How many individual games to launch for this experiment. |
--parallel |
$ claude mcp add AI_Diplomacy \
-- python -m otcore.mcp_server <graph>