### Build Order Format Example Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v2/unformatted/order_instructions_adjustment_phase.txt Demonstrates the correct format for issuing build orders for armies and fleets, including specific unit types and locations. Covers standard builds and dual-coast province builds. ```text A PAR B F LON B F STP/NC B ``` -------------------------------- ### Start 3D Game Visualization Server (Bash) Source: https://context7.com/goodstartlabs/ai_diplomacy/llms.txt Provides instructions to set up and run the 3D game visualization server. This involves navigating to the animation directory, installing dependencies, and starting the development server. The visualization can then be accessed via a web browser. ```bash # Start interactive animation server cd ai_animation npm install npm run dev # Open http://localhost:5173 in browser # Click "Load Game" and select lmvsgame.json file ``` -------------------------------- ### Install and Run Web Interface (NPM) Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/README.md These commands guide the user through installing and launching the React-based web interface for the Diplomacy project. It involves installing NVM, cloning the repository, installing Python development dependencies, and then building and starting the Node.js modules for the React server. ```bash # Install NVM curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash # Clone repo git clone https://github.com/diplomacy/diplomacy.git # Install package locally # You may want to install it in a conda or virtualenv environment cd diplomacy/ pip install -r requirements_dev.txt # Build node modules cd diplomacy/web npm install . npm install . --only=dev # In a terminal window or tab - Launch React server npm start ``` -------------------------------- ### JSON Example: Multiple Supported Orders Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts_simple_optim_v1.0/order_instructions_movement_phase.txt Provides a complex JSON example showcasing multiple supported moves and holds, demonstrating how to coordinate support for various offensive and defensive actions. ```json { "orders": [ "F HEL - DEN", "F BAL S F HEL - DEN", # supports the F HEL - DEN move "A KIE S F HEL - DEN", # additional support means this move beats a unit supported by 1 or less "A MUN - BUR", "A RUH S A MUN - BUR", # supports the A MUN - BUR move "A BEL - HOL", "F NTH S A BEL - HOL", # supports the A BEL - HOL move "A BER H", "A PRU S A BER H" # supports the A BER H hold ] } ``` -------------------------------- ### JSON Example: Italian Attack Coordination Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts_simple_optim_v1.0/order_instructions_movement_phase.txt Shows a JSON example of coordinated Italian orders, including fleet attacks and army advancements, with supporting units to ensure successful maneuvers. ```json { "orders": [ "F ION - GRE", # ION fleet attacks GRE "F ADR S F ION - GRE", # ADR supports ION → GRE "A VEN - TYR", # VEN army advances to TYR "A PIE S A VEN - TYR", # PIE supports VEN → TYR "A ROM - PIE" ] } ``` -------------------------------- ### Setup Project Dependencies with uv Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/README.md These commands are used to set up project dependencies using uv, a fast Python package installer and virtual environment manager. It involves cloning the repository, installing dependencies, and activating the created virtual environment. ```bash # Clone the repository git clone https://github.com/your-repo/AI_Diplomacy.git cd AI_Diplomacy # Install dependencies and create virtual environment uv sync # Activate the virtual environment source .venv/bin/activate # On Unix/macOS # or .venv\Scripts\activate # On Windows ``` -------------------------------- ### Example Order Submission: Basic Moves Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/order_instructions_adjustment_phase.txt Provides a simple example of order submission with basic move and hold orders. This showcases the fundamental syntax for unit actions. ```json { "orders": [ "A PAR H", "A MAR - BUR", "F BRE - MAO" ] } ``` -------------------------------- ### Disband Order Format Example Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v2/unformatted/order_instructions_adjustment_phase.txt Illustrates the proper syntax for disbanding units, specifying the unit type (Army or Fleet) and the location from which it will be disbanded. ```text A PAR D F LON D ``` -------------------------------- ### JSON Example: Expansive English-Scandinavian Orders Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts_simple_optim_v1.0/order_instructions_movement_phase.txt Provides a JSON example of expansive English-Scandinavian orders, coordinating fleet and army movements across multiple fronts with essential support. ```json { "orders": [ "F ENG - MAO", # ENG fleet to MAO "F IRI S F ENG - MAO", # IRI supports ENG → MAO "A BRE S F ENG - MAO", # BRE adds second support to ENG → MAO "A LVP - WAL", # LVP army to WAL "F LON S A LVP - WAL", # LON supports LVP → WAL "F NTH - ENG", # NTH fleet to ENG "A EDI S F NTH - ENG", # EDI supports NTH → ENG "F BAR - NTH", # BAR fleet to NTH "A NWY - SWE", # NWY army to SWE "F HEL S A NWY - SWE" ] } ``` -------------------------------- ### Example Dual-Coast Fleet Order Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_benchmark/order_instructions_movement_phase.txt This example demonstrates the correct format for issuing a fleet order to a dual-coast province, including the required coast specification. Only fleets require coast specification. ```text F SPA/SC - MAO ``` -------------------------------- ### JSON Example: German-Nordic Sweep Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts_simple_optim_v1.0/order_instructions_movement_phase.txt Presents a JSON example of a broad German-Nordic offensive, detailing fleet movements and army advances with supporting units to secure territories. ```json { "orders": [ "F DEN - SWE", # DEN fleet drives on SWE "F BAL S F DEN - SWE", # BAL supports DEN → SWE "A KIE - DEN", # KIE army marches to DEN "A BER S A KIE - DEN", # BER supports KIE → DEN "F NTH - NWY", # NTH fleet sails to NWY "F SKA S F NTH - NWY", # SKA supports NTH → NWY "A MUN - KIE" ] } ``` -------------------------------- ### Run AI Diplomacy Game Animation Server Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/README.md Starts an interactive 3D animation server for visualizing game replays. This requires navigating to the 'ai_animation' directory, installing dependencies, and running the development server. The animation can then be accessed via a web browser. Dependencies include Node.js and npm. ```bash cd ai_animation npm install npm run dev ``` -------------------------------- ### Example Game Orders Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v2/order_instructions_movement_phase.txt A list of sample orders for game units, demonstrating attack, support, and movement commands. These orders are specific to a game's mechanics and unit types. ```text { "orders": [ "A VEN - TRI", "A APU S A VEN - TRI", "F ION S A VEN - TRI", "A ROM H", "F NAP - TYS" ] } ``` -------------------------------- ### Example 1: French Order Submission Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v1/order_instructions_movement_phase.txt Provides a concrete example of submitted orders for a player, likely representing France, including reasoning for the moves. ```JSON { "orders": [ "A PAR S A MAR - BUR", "A MAR - BUR", "F BRE - MAO" ] } ``` -------------------------------- ### Build Orders (AI Diplomacy) Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v3/unformatted/order_instructions_movement_phase.txt Specifies the format for build orders during the build phase. Units can only be built in home centers that are currently empty and were part of the player's starting units. Building in these critical locations is essential for maintaining army strength. ```text [UnitType] [Location3LetterCode] B UnitType: 'A' (Army) or 'F' (Fleet) Example: 'A PAR B', 'F LON B' ``` -------------------------------- ### Dual-Coast Province Order Example (Italy) Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v1/order_instructions_movement_phase.txt Demonstrates how to specify a coast for a fleet operating in a dual-coast province, as exemplified by the Italian player. ```Text F NAP - TYS ``` -------------------------------- ### Diplomacy AI Analysis: Example after Builds Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/state_update_prompt.txt An example JSON output following a naval buildup in the north with Russia posing a threat. Relationships are updated to Enemy with Russia and Unfriendly with Germany. ```json { "reasoning": "Naval buildup in north. Russia threatening.", "relationships": { "RUSSIA": "Enemy", "GERMANY": "Unfriendly", "FRANCE": "Neutral", "AUSTRIA": "Neutral", "TURKEY": "Neutral" }, "goals": [ "Control northern waters", "Take Denmark first", "Find anti-Russia ally" ] } ``` -------------------------------- ### JSON Example: Supporting a Hold Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts_simple_optim_v1.0/order_instructions_movement_phase.txt Illustrates how to use JSON orders to support an army holding its position in Berlin. The PRU and SIL armies provide support, increasing the hold strength. ```json { "orders": [ "A BER H", # BER army holds position "A PRU S A BER H", # PRU supports BER's hold "A SIL S A BER H" # SIL also supports the hold ] } ``` -------------------------------- ### Example Order Submission (JSON) Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v2/order_instructions_movement_phase.txt Provides a parsable JSON output for submitting orders, including a list of individual order strings. This format is required for all order submissions and should be accompanied by strategic reasoning. ```json { "orders": [ "A PAR - PIC", "A MAR - BUR", "F BRE - MAO" ] } ``` -------------------------------- ### Build Order Format - Diplomacy Game Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/unformatted/order_instructions_movement_phase.txt Specifies the format for submitting build orders during the build phase. Units can only be built in a nation's home centers if those centers are empty and were part of the starting set. Losing these critical centers prevents further unit construction. ```text [UnitType] [Location3LetterCode] B UnitType: 'A' (Army) or 'F' (Fleet) Example: 'A PAR B', 'F LON B' ``` -------------------------------- ### Build Order Format Example Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v2/order_instructions_movement_phase.txt Demonstrates the format for submitting build orders during the build phase. Unit types are 'A' for Army and 'F' for Fleet, followed by the 3-letter location code and 'B' for build. Builds are restricted to empty home centers. ```text A PAR B F LON B ``` -------------------------------- ### JSON Example: Supporting a Move or Attack Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts_simple_optim_v1.0/order_instructions_movement_phase.txt Demonstrates how to structure JSON orders to support a fleet's attack on Denmark. The BAL fleet and KIE army provide support, increasing the attack strength. ```json { "orders": [ "F HEL - DEN", # This fleet attacks Denmark "F BAL S F HEL - DEN", # BAL fleet supports the attack (strength = 2) "A KIE S F HEL - DEN" # KIE army also supports (total strength = 3) ] } ``` -------------------------------- ### Navigate to AI Animation Directory and Install Dependencies Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/README.md This command sequence changes the current directory to `ai_animation` and then installs the necessary Node.js dependencies for the game visualization tool using npm. ```bash cd ai_animation npm install ``` -------------------------------- ### Support Order Format Example Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v2/order_instructions_movement_phase.txt Illustrates the format for support orders, specifying the unit, its location, the type of order ('S' for support), the unit being supported, its origin, and its destination. Supporting your own or allied units is crucial for successful attacks. ```text [Unit] [Location] S [Unit] [From] - [To] Example: A PAR S F PIC - ENG ``` -------------------------------- ### France S1901 Expansion Orders Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v3/order_instructions_movement_phase.txt Example expansion orders for France in the first Spring turn (S1901). These orders prioritize capturing neutral centers (Spain, Belgium) and applying pressure on Germany, with zero defensive considerations. ```json { "orders": [ "A PAR - BUR", // Threaten Munich, force German defense "A MAR - SPA", // Guaranteed neutral capture "F BRE - MAO" // Position for Portugal/convoy options ] } ``` -------------------------------- ### Example Order Submission with Reasoning (JSON) Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v2/order_instructions_movement_phase.txt Demonstrates a more complex order submission with multiple units and a support order, reflecting strategic goals like aggressive expansion and support for attacks. The reasoning explains the intent behind each order. ```json { "orders": [ "A BER - SIL", "A MUN - TYR", "F KIE - DEN", "A RUH - HOL", "A SIL - WAR", "F HEL S F KIE - DEN" ] } ``` -------------------------------- ### Example 2: German Order Submission (Spring 1901) Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v1/order_instructions_movement_phase.txt Illustrates German orders for Spring 1901, focusing on early expansion into Denmark and Holland, with supporting moves. ```JSON { "orders": [ "A BER S F KIE - DEN", "A MUN - TYR", "F KIE - DEN", "A RUH - HOL", "A SIL - WAR", "F HEL S A RUH - HOL" ] } ``` -------------------------------- ### Example Order Submission: Italy, Autumn 1902 Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/order_instructions_adjustment_phase.txt Demonstrates a complete order submission for Italy in Autumn 1902, including strategic reasoning. This example showcases movement, support, and hold orders, with specific attention to defensive positioning. ```json { "orders": [ "A VEN - TRI", "A APU S A VEN - TRI", "F ION S A VEN - TRI", "A ROM H", "F NAP - TYS" ] } ``` -------------------------------- ### Diplomacy AI Analysis: Example after Cooperation Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/state_update_prompt.txt An example JSON output reflecting a scenario where Austria helped take Warsaw and Russia attacked Prussia. Relationships are updated to Ally with Austria, Enemy with Russia, and Unfriendly with Italy. ```json { "reasoning": "Austria helped take Warsaw. Russia attacked Prussia.", "relationships": { "AUSTRIA": "Ally", "RUSSIA": "Enemy", "TURKEY": "Neutral", "ITALY": "Unfriendly", "FRANCE": "Neutral" }, "goals": [ "Hold Warsaw against Russia", "Keep Austrian alliance", "Block Italian expansion" ] } ``` -------------------------------- ### Diplomacy AI Analysis: Example after Betrayal Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/state_update_prompt.txt An example JSON output for a betrayal scenario where France betrayed a Channel agreement, and Russia is cooperating in the north. Relationships reflect Enemy with France and Friendly with Russia. ```json { "reasoning": "France betrayed Channel agreement. Russia cooperating north.", "relationships": { "FRANCE": "Enemy", "RUSSIA": "Friendly", "GERMANY": "Unfriendly", "ITALY": "Neutral", "AUSTRIA": "Neutral" }, "goals": [ "Counter French fleet", "Secure Norway with Russia", "Build London fleet" ] } ``` -------------------------------- ### Run AI Animation Development Server Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/README.md This command starts the development server for the AI animation visualization tool. After running, the user can access the interactive 3D visualization by opening `http://localhost:5173` in their web browser and loading a game JSON file. ```bash npm run dev # Open http://localhost:5173 and load a game JSON ``` -------------------------------- ### Support Order Format - Allies Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v1/unformatted/order_instructions_movement_phase.txt Illustrates the format for supporting an ally's move. This helps in gaining diplomatic favor and coordinating board control. The example shows an army in Paris supporting a fleet in Brest to move to England. ```plaintext A PAR S F BRE - ENG ``` -------------------------------- ### Example of Dual-Coast Province Order Format Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_benchmark/order_instructions_adjustment_phase.txt Demonstrates the correct syntax for specifying coast preference when issuing fleet build orders in dual-coast provinces like St. Petersburg (STP), Spain (SPA), and Bulgaria (BUL). This is crucial for fleet placement to avoid conflicts or unintended positioning. ```text F [PROVINCE]/[COAST] Example: F STP/NC B ``` -------------------------------- ### Example Order Submission: Germany, Spring 1901 Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/order_instructions_adjustment_phase.txt Illustrates an order submission for Germany in Spring 1901, focusing on early expansion into Denmark and Holland, while securing home centers. Includes an opportunistic move towards Warsaw. ```json { "orders": [ "A BER H", "A MUN H", "F KIE - DEN", "A RUH - HOL", "A SIL - WAR", "F HEL H" ] } ``` -------------------------------- ### Install Matplotlib and Seaborn Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/experiments/plotting.ipynb Installs the matplotlib and seaborn Python libraries, which are commonly used for data visualization. This command is typically run in a Python environment or script. ```python !pip install matplotlib seaborn ``` -------------------------------- ### Example 2: German Spring 1901 Orders Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/order_instructions_movement_phase.txt Illustrates a set of parsable orders for Germany in Spring 1901, focusing on early expansion into Denmark and Holland, and securing home centers. Includes army and fleet movements and hold orders. ```json { "orders": [ "A BER H", "A MUN H", "F KIE - DEN", "A RUH - HOL", "A SIL - WAR", "F HEL H" ] } ``` -------------------------------- ### Dual-Coast Province Notation (AI Diplomacy) Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v3/unformatted/order_instructions_movement_phase.txt Illustrates how to specify the coast for units operating in dual-coast provinces. This is crucial for fleet positioning and ensuring orders resolve correctly in provinces like STP, SPA, and BUL. ```text Specify coast when needed: 'F [PROVINCE]/[COAST_CODE]' Example: 'F STP/NC B', 'A MAR S F SPA/SC - WES' Coast codes: NC (North), SC (South), EC (East), WC (West) ``` -------------------------------- ### Support Order Format (AI Diplomacy) Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v3/unformatted/order_instructions_movement_phase.txt Defines the structure for support orders, which must align with actual unit moves. A support order strengthens a specific move; therefore, the unit being supported must have a corresponding order to move as specified. ```text '[Unit] [Location] S [Unit] [From] - [To]' ``` -------------------------------- ### Support Order Format - Own Units Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v1/unformatted/order_instructions_movement_phase.txt Demonstrates the format for issuing a support order to bolster an allied unit's attack or defense. This is crucial for ensuring successful captures and controlling the board. The example shows an army in Paris supporting an army in Burgundy to move to Munich. ```plaintext A PAR S A BUR - MUN ``` -------------------------------- ### Dual-Coast Province Order Format - AI Diplomacy Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts_simple/order_instructions_movement_phase.txt Demonstrates the correct syntax for issuing orders to fleets in dual-coast provinces, requiring explicit coast specification (North, South, East, or West). ```text F [PROVINCE]/[COAST] - [UNIT_TYPE] Example: F SPA/SC - MAO ``` -------------------------------- ### Unit Build Order Format Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v1/unformatted/order_instructions_movement_phase.txt Specifies the format for building new units during the build phase. Units can only be built in home centers that are currently empty and were part of the starting units. The format includes the unit type (Army 'A' or Fleet 'F') followed by the home center's 3-letter code and 'B' for build. ```plaintext [UnitType] [Location3LetterCode] B Example: A PAR B, F LON B ``` -------------------------------- ### Define CSA Moment 1 Configurations (No Order History) in Python Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/support_explanation_ablations_csa.ipynb This snippet defines a list of dictionaries, `RUN_CONFIGS`, to configure analysis runs for CSA moment 1 without including order history in the prompt. Each configuration specifies the directory, a descriptive label, the game phase, and the power being analyzed. This setup is typically used for baseline comparisons or initial experimental runs. ```python # --- config --------------------------------------------------------------- # Define each analysis run here. Each dictionary groups all the information # for a single bar group in the final plot. # csa moment 1, order history NOT included in order generation prompt RUN_CONFIGS = [ { "dir": "/mnt/i/diplo/sam-exp087-csa", "label": "sam-exp087-csa baseline", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp087-csa-r", "label": "sam-exp087-csa-r baseline (repeat)", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp087-csa2", "label": "sam-exp087-csa2 supports explained v2 nshot3", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp087-csa3", "label": "sam-exp087-csa3 supports explained v2 nshot3 + condensed possible moves", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp087-csa4", "label": "sam-exp087-csa4 condensed possible moves", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp087-csa5", "label": "sam-exp087-csa5 supports explained v2 nshot6", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp087-csa6", "label": "sam-exp087-csa6 supports explained v2 nshot12", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp087-csa7", "label": "sam-exp087-csa7 supports explained v2 nshot6 + condensed possible moves", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp087-csa8", "label": "sam-exp087-csa8 supports explained v2 nshot12 + condensed possible moves", "phase": "F1907M", "power": "GERMANY", }, ] ``` -------------------------------- ### Convoys - Fleet Support for Army Move Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v1/unformatted/order_instructions_movement_phase.txt Shows how a fleet can support an army's convoyed move. This enables extended reach for army units. The example shows a fleet in the North Sea (NTH) convoying an army from London to Norway. ```plaintext F NTH C A LON - NWY ``` -------------------------------- ### Implement Custom LLM Client in Python Source: https://context7.com/goodstartlabs/ai_diplomacy/llms.txt Demonstrates how to implement a custom LLM client by extending the BaseModelClient. This involves defining initialization logic and overriding methods like `generate_response` and `get_orders` to interact with a specific LLM API. It includes example usage with built-in clients and highlights automatic CSV logging. ```python from ai_diplomacy.clients import BaseModelClient, ClaudeClient, OpenAIClient class CustomModelClient(BaseModelClient): """Custom LLM client implementation""" def __init__(self, model_name: str, prompts_dir: str = None): super().__init__(model_name, prompts_dir) # Initialize your client here async def generate_response( self, prompt: str, temperature: float = 0.0, inject_random_seed: bool = True ) -> str: """Generate raw text response from LLM""" # Your implementation response = await your_llm_api_call(prompt) return response async def get_orders( self, game, board_state, power_name: str, possible_orders: dict, conversation_text, model_error_stats: dict, log_file_path: str, phase: str, agent_goals: list = None, agent_relationships: dict = None, agent_private_diary_str: str = None ) -> list[str]: """Generate orders for given game state""" # Calls generate_response with constructed prompt # Parses JSON response into order list # Handles errors and falls back to valid orders return orders # Use custom client client = CustomModelClient("my-model-v1") agent = DiplomacyAgent("FRANCE", client) # Built-in clients support multiple models claude = ClaudeClient("claude-3-5-sonnet-20241022") openai = OpenAIClient("gpt-4o") gemini = GeminiClient("gemini-2.0-flash") # All clients automatically log to CSV # Format: timestamp,power,phase,type,prompt,response,success ``` -------------------------------- ### Dual-Coast Province Order Example Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v2/order_instructions_movement_phase.txt Shows how to specify the coast for units operating in dual-coast provinces like St. Petersburg, Spain, or Bulgaria. The format includes '/[COAST_CODE]' after the province code, with valid codes being NC, SC, EC, and WC. ```text F STP/NC B A MAR S F SPA/SC - WES ``` -------------------------------- ### Example JSON for Blocked Expansion Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v3/state_update_prompt.txt This JSON structure illustrates a blocked expansion scenario. The 'reasoning' field details the obstacles encountered and potential counter-moves. The 'relationships' object reflects negative interactions or lack of support from other powers, and the 'goals' array outlines strategies to overcome the blockades and identify new opportunities. ```json { "reasoning": "France blocked Belgium. Must break through. Russia vulnerable north.", "relationships": { "FRANCE": "Enemy", "RUSSIA": "Neutral", "GERMANY": "Enemy", "ITALY": "Friendly", "AUSTRIA": "Neutral" }, "goals": [ "Break into Belgium with Italian help", "Take Norway while Russia distracted", "Convoy army to Portugal" ] } ``` -------------------------------- ### Example JSON for Successful Expansion Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v3/state_update_prompt.txt This JSON structure represents a successful expansion phase. It includes a 'reasoning' field to explain the strategic outcome, a 'relationships' object to define interactions with other powers based on their support or hindrance during expansion, and a 'goals' array listing specific territorial objectives for the next phase. ```json { "reasoning": "Captured Munich and Denmark. Austria helped. France passive.", "relationships": { "AUSTRIA": "Ally", "FRANCE": "Neutral", "RUSSIA": "Unfriendly", "ITALY": "Neutral", "TURKEY": "Neutral" }, "goals": [ "Take Belgium next with Austrian support", "Invade Sweden before Russia consolidates", "Position for Holland capture" ] } ``` -------------------------------- ### Define CSA Moment 1 Configurations (With Order History) in Python Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/support_explanation_ablations_csa.ipynb This snippet defines a list of dictionaries, `RUN_CONFIGS`, to configure analysis runs for CSA moment 1 where order history IS included in the order generation prompt. Similar to the previous configuration, each dictionary specifies the directory, label, phase, and power for an experiment. This setup is useful for evaluating how historical context influences AI decision-making. ```python # csa moment 1, order history IS included in order generation prompt RUN_CONFIGS = [ { "dir": "/mnt/i/diplo/sam-exp094-csa", "label": "sam-exp094-csa baseline", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp094-csa-r", "label": "sam-exp094-csa-r baseline (repeat)", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp094-csa2", "label": "sam-exp094-csa2 supports explained v2 nshot3", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp094-csa3", "label": "sam-exp094-csa3 supports explained v2 nshot3 + condensed possible moves", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp094-csa4", "label": "sam-exp094-csa4 condensed possible moves", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp094-csa5", "label": "sam-exp094-csa5 supports explained v2 nshot6", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp094-csa6", "label": "sam-exp094-csa6 supports explained v2 nshot12", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp094-csa7", "label": "sam-exp094-csa7 supports explained v2 nshot6 + condensed possible moves", "phase": "F1907M", "power": "GERMANY", }, { "dir": "/mnt/i/diplo/sam-exp094-csa8", "label": "sam-exp094-csa8 supports explained v2 nshot12 + condensed possible moves", "phase": "F1907M", "power": "GERMANY", }, ] ``` -------------------------------- ### Italy A1902 Breakthrough Attack Orders Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v3/order_instructions_movement_phase.txt Example expansion orders for Italy in the second Autumn turn (A1902), focusing on a breakthrough attack into Trieste against Austria. Secondary goals include positioning for Balkan exploitation, with no units held defensively. ```json { "orders": [ "A VEN - TRI", // Primary assault "A APU S A VEN - TRI", // Guarantee success "F ION - ADR", // Future Balkan access "A ROM - VEN", // Backfill for continued pressure "F NAP - ION" // Mediterranean control ] } ``` -------------------------------- ### Germany S1901 Triple Threat Orders Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v3/order_instructions_movement_phase.txt Example expansion orders for Germany in the first Spring turn (S1901), aiming to capture three centers (Denmark, Holland, Belgium). Supports are used to guarantee captures, forcing neighbors into defensive positions. ```json { "orders": [ "F KIE - DEN", // Neutral capture "A BER - KIE", // Follow fleet for future support "A MUN - RUH", // Threaten Belgium/Holland "A RUH - HOL", // Neutral capture "F HEL S F KIE - DEN" // Guarantee Denmark ] } ``` -------------------------------- ### Support Order Format (Move) Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v1/order_instructions_movement_phase.txt Illustrates how to format a support order for a unit's move. This ensures a unit's move is successful by having another unit provide support. ```Text [Unit] [Location] S [Unit] [From] - [To] ``` -------------------------------- ### Diplomacy AI Analysis: Russia after Negotiating Passage Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/state_update_prompt.txt An example JSON output for Russia after successfully negotiating passage through the Black Sea with Turkey. Relationships reflect Enemy with Germany and Ally with Turkey. ```json { "reasoning": "Securing Rumania via Turkish agreement is a major success. This improves my southern position and Turkey is now a provisional ally. Germany's move into Silesia is a direct and immediate threat to Warsaw; they are now my primary adversary. Austria and France are posturing, but their conflict doesn't directly affect me yet, keeping them neutral. England's new fleet is a long-term concern but not immediate. Italy's westward focus means they are not a current threat or priority.", "relationships": { "GERMANY": "Enemy", "AUSTRIA": "Neutral", "TURKEY": "Ally", "ITALY": "Neutral", "FRANCE": "Neutral", "ENGLAND": "Unfriendly" }, "goals": [ "Defend Warsaw against Germany, possibly by moving Lvn-War or Mos-War.", "Solidify alliance with Turkey, potentially coordinating further moves in the south or against Austria if Germany allies with them.", "Monitor English fleet movements and prepare for a potential northern threat in future turns.", "Explore diplomatic options with France or Austria to counter German aggression." ] } ``` -------------------------------- ### Diplomacy AI Analysis: England after Failed Attack Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/state_update_prompt.txt An example JSON output for England after a failed attack on Belgium, supported by France and Germany. Relationships reflect Enemy status with France and Germany, and Unfriendly with Russia. ```json { "reasoning": "My attack on Belgium was decisively repulsed due to Franco-German cooperation, marking them as a significant threat bloc. Russia's acquisition of Sweden is concerning for my northern position. The Austro-Italian conflict seems localized for now, and Turkey's inactivity makes them an unknown variable, potentially open to diplomacy.", "relationships": { "FRANCE": "Enemy", "GERMANY": "Enemy", "RUSSIA": "Unfriendly", "AUSTRIA": "Neutral", "ITALY": "Neutral", "TURKEY": "Neutral" }, "goals": [ "Break the Franco-German alliance or find a way to counter their combined strength.", "Secure North Sea (NTH) and prevent further Russian expansion towards Norway (NWY).", "Seek dialogue with Turkey or Austria/Italy to create a counterweight to the dominant bloc." ] } ``` -------------------------------- ### Initialize Data Paths and Mappings Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/experiments/plotting.ipynb Sets up essential variables for the AI Diplomacy project. It defines the base path for data files and a mapping dictionary to convert relationship strings into numerical values. Adjust the 'path' variable to your specific data directory. ```python import json import matplotlib.pyplot as plt import seaborn as sns import os # --- Placeholder Setup (Adjust these) --- # Define the path to your data files path = "./" # e.g., '/path/to/your/data/' # Define a mapping for relationship strings to numerical values # (Example mapping, adjust based on your actual relationship strings) relationship_mapping = { "Ally": 2, "Friendly": 1, "Neutral": 0, "Unfriendly": -1, "Enemy": -2, None: 0 # Handle cases where relationship might be missing or None } # --- End Placeholder Setup --- ``` -------------------------------- ### Convoys - Army Move Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v1/unformatted/order_instructions_movement_phase.txt Defines the format for an army to move using a convoy. This allows for surprise attacks over long distances. The example shows an army in London attempting to move to Norway. ```plaintext A LON - NWY ``` -------------------------------- ### Adjustment Phase Build Order Format Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_benchmark/order_instructions_adjustment_phase.txt Specifies the format for issuing build orders during the adjustment phase of the game. This includes the unit type (Army 'A' or Fleet 'F') and the location where the unit will be built, followed by 'B' to indicate a build order. ```text [UnitType] [Location] B e.g. 'A PAR B', 'F LON B' ``` -------------------------------- ### Build Order Format Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v1/order_instructions_movement_phase.txt Specifies the format for build orders during the build phase. Units can only be built in empty home centers that were initially owned. '[UnitType] [Location3LetterCode] B' is the required format. ```Text [UnitType] [Location3LetterCode] B ``` -------------------------------- ### Convoy Order Format (AI Diplomacy) Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v3/unformatted/order_instructions_movement_phase.txt Details the syntax for convoy orders, used to transport armies across water. Fleets can initiate a convoy operation for an army, enabling deep strikes and strategic redeployments. ```text Army: 'A [From] - [To]' Fleet: 'F [Sea] C A [From] - [To]' ``` -------------------------------- ### Diplomacy AI Analysis Output Structure Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/state_update_prompt.txt The standard JSON structure returned by the AI after analyzing a Diplomacy game phase. It includes a reasoning string, an object mapping powers to their relationship status, and an array of actionable goals. ```json { "reasoning": "string", "relationships": { "POWER_NAME_1": "Relationship_Status", "POWER_NAME_2": "Relationship_Status" }, "goals": [ "Specific goal 1", "Specific goal 2" ] } ``` -------------------------------- ### Launch Diplomacy Server Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/README.md Launches the diplomacy server from the command line. This server hosts the web interface and manages network games. It does not require any input parameters. ```python python -m diplomacy.server.run ``` -------------------------------- ### Run Basic AI Game with Command Line Arguments Source: https://context7.com/goodstartlabs/ai_diplomacy/llms.txt Demonstrates how to run a basic AI Diplomacy game using the lm_game.py script with various command-line arguments. These arguments control game duration, negotiation rounds, strategic planning phases, output directories, model assignments, game resumption, and critical state analysis. ```bash python lm_game.py --max_year 1910 --num_negotiation_rounds 3 python lm_game.py --max_year 1910 --planning_phase --num_negotiation_rounds 2 --run_dir results/game_001 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" \ --max_year 1905 \ --num_negotiation_rounds 2 python lm_game.py --run_dir results/game_001 --resume_from_phase S1902M python lm_game.py \ --run_dir results/game_001 \ --critical_state_analysis_dir results/critical_001 \ --resume_from_phase F1903M \ --end_at_phase F1905M ``` -------------------------------- ### JSON Response Format for Negotiation Messages Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v2/conversation_instructions.txt This snippet demonstrates the required JSON structure for sending negotiation messages. It includes examples for both global messages and private messages, specifying the 'message_type', 'content', and optional 'recipient' fields. ```json [ { "message_type": "global", "content": "Your message text" }, ... ] ``` ```json [ { "message_type": "private", "recipient": "POWER_NAME", "content": "Your message text" }, ... ] ``` -------------------------------- ### Python Run Configurations (Order History Included) Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/support_explanation_ablations_csa.ipynb Defines an alternative list of dictionaries for AI Diplomacy experiments, where order history IS included in the prompt. These configurations mirror the structure of the first set but are intended for scenarios requiring historical context. ```python _RUN_CONFIGS = [ { "dir": "/mnt/i/diplo/sam-exp097-csa", "label": "sam-exp097-csa baseline", "phase": "S1912M", "power": "FRANCE", }, { "dir": "/mnt/i/diplo/sam-exp097-csa-r", "label": "sam-exp097-csa-r baseline (repeat)", "phase": "S1912M", "power": "FRANCE", }, { "dir": "/mnt/i/diplo/sam-exp097-csa2", "label": "sam-exp097-csa2 supports explained v2 nshot3", "phase": "S1912M", "power": "FRANCE", }, { "dir": "/mnt/i/diplo/sam-exp097-csa3", "label": "sam-exp097-csa3 supports explained v2 nshot3 + condensed possible moves", "phase": "S1912M", "power": "FRANCE", }, { "dir": "/mnt/i/diplo/sam-exp097-csa4", "label": "sam-exp097-csa4 condensed possible moves", "phase": "S1912M", "power": "FRANCE", }, { "dir": "/mnt/i/diplo/sam-exp097-csa5", "label": "sam-exp097-csa5 supports explained v2 nshot6", "phase": "S1912M", "power": "FRANCE", }, { "dir": "/mnt/i/diplo/sam-exp097-csa6", "label": "sam-exp097-csa6 supports explained v2 nshot12", "phase": "S1912M", "power": "FRANCE", }, { "dir": "/mnt/i/diplo/sam-exp097-csa7", "label": "sam-exp097-csa7 supports explained v2 nshot6 + condensed possible moves", "phase": "S1912M", "power": "FRANCE", }, { "dir": "/mnt/i/diplo/sam-exp097-csa8", "label": "sam-exp097-csa8 supports explained v2 nshot12 + condensed possible moves", "phase": "S1912M", "power": "FRANCE", }, ] ``` -------------------------------- ### Build Order Format for Diplomacy Game Source: https://github.com/goodstartlabs/ai_diplomacy/blob/main/ai_diplomacy/prompts/prompts_hold_reduction_v2/unformatted/order_instructions_movement_phase.txt This describes the format for submitting build orders during the build phase. It specifies the unit type (Army or Fleet) and the location code. Build orders can only be placed in empty home centers, and losing these home centers prevents further unit construction. ```plaintext [UnitType] [Location3LetterCode] B UnitType: 'A' (Army) or 'F' (Fleet) Example: 'A PAR B', 'F LON B' ```