<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: KaihuaHuang</title>
    <description>The latest articles on DEV Community by KaihuaHuang (@kaihuahuang).</description>
    <link>https://dev.to/kaihuahuang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3861971%2F6fb72169-0078-402c-83f4-72113a6c593b.jpeg</url>
      <title>DEV Community: KaihuaHuang</title>
      <link>https://dev.to/kaihuahuang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kaihuahuang"/>
    <language>en</language>
    <item>
      <title>How I Built a Multi-Agent Geopolitical Simulator with FastAPI + LiteLLM</title>
      <dc:creator>KaihuaHuang</dc:creator>
      <pubDate>Sun, 05 Apr 2026 08:04:42 +0000</pubDate>
      <link>https://dev.to/kaihuahuang/how-i-built-a-multi-agent-geopolitical-simulator-with-fastapi-litellm-42p9</link>
      <guid>https://dev.to/kaihuahuang/how-i-built-a-multi-agent-geopolitical-simulator-with-fastapi-litellm-42p9</guid>
      <description>&lt;p&gt;What happens when you give four LLM agents their own strategic doctrines, red lines, and constraints — then throw them into a geopolitical crisis?&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://game.peakstone-labs.com" rel="noopener noreferrer"&gt;Strait of Hormuz Simulator&lt;/a&gt; to find out. It's a multi-agent sandbox where four nations (Iran, US, Israel, Gulf States) are each controlled by an independent LLM, and the results are surprisingly realistic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotyv7lkairsx7hw9ovof.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotyv7lkairsx7hw9ovof.gif" alt="Demo" width="720" height="681"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Architecture
&lt;/h2&gt;

&lt;p&gt;Each country is a markdown file (a "soul") that defines its strategic doctrine and default parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;backend/souls/
├── iran.md        # Asymmetric warfare, Strait control
├── us.md          # Three bad options, escalation management
├── israel.md      # Nuclear red line, preemptive calculus
└── gulf_states.md # Oil leverage, diplomatic survival
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The backend runs each agent sequentially — every round, each nation receives:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A shared situation briefing&lt;/li&gt;
&lt;li&gt;Its own doctrine (system prompt)&lt;/li&gt;
&lt;li&gt;Rolling memory of prior rounds&lt;/li&gt;
&lt;li&gt;Active scenario modifiers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then it decides what to do. No script. No predetermined outcomes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why LiteLLM?
&lt;/h2&gt;

&lt;p&gt;I wanted users to bring their own API key and pick any model. LiteLLM gave me a unified interface across GPT-4o, Claude, Gemini, and DeepSeek with zero provider-specific code. One &lt;code&gt;litellm.completion()&lt;/code&gt; call handles all of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Chaos Slider
&lt;/h2&gt;

&lt;p&gt;A single float (0-1) injected into every agent's prompt:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Low chaos&lt;/strong&gt; → agents seek diplomatic exits&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High chaos&lt;/strong&gt; → bold moves, miscommunication, escalation spirals&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Emergent Behavior That Surprised Me
&lt;/h2&gt;

&lt;p&gt;In one run, Israel independently chose &lt;em&gt;not&lt;/em&gt; to strike Iranian nuclear facilities — reasoning that US strikes made unilateral action diplomatically counterproductive. Nobody programmed that.&lt;/p&gt;

&lt;p&gt;Gulf States withheld spare oil capacity to extract security guarantees, creating price feedback loops the oil market agent had to price in real-time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Oil Market Agent
&lt;/h2&gt;

&lt;p&gt;A separate LLM agent watches all military and diplomatic actions, then sets the oil price. Blockade the Strait? Price spikes. Ceasefire talks? Price dips. It adds a layer of economic consequences that feeds back into each nation's decision-making.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scenario Tags
&lt;/h2&gt;

&lt;p&gt;11 toggleable modifiers that inject additional context:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🚀 Nuclear Brinkmanship&lt;/li&gt;
&lt;li&gt;🏴‍☠️ Houthi Wildcard&lt;/li&gt;
&lt;li&gt;🇨🇳 China Mediator&lt;/li&gt;
&lt;li&gt;💰 Market Patience Clock&lt;/li&gt;
&lt;li&gt;🖥️ Cyber Offensive&lt;/li&gt;
&lt;li&gt;...and 6 more&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mix and match for different simulation dynamics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Backend&lt;/strong&gt;: Python 3.11, FastAPI, LiteLLM, Pydantic&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend&lt;/strong&gt;: Vue 3, Vite, TailwindCSS, DaisyUI&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Streaming&lt;/strong&gt;: SSE for real-time agent output&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deployment&lt;/strong&gt;: Docker + Cloudflare&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try It
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🎮 &lt;a href="https://game.peakstone-labs.com" rel="noopener noreferrer"&gt;Play free&lt;/a&gt; (20 rounds on DeepSeek V3)&lt;/li&gt;
&lt;li&gt;📦 &lt;a href="https://github.com/Peakstone-Labs/hormuz-agent-sandbox" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; (MIT license)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Adding a new country is just creating a markdown file in &lt;code&gt;backend/souls/&lt;/code&gt;. The system auto-discovers it on restart.&lt;/p&gt;

&lt;p&gt;Would love feedback — especially on agent behavior and scenario design.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>opensource</category>
      <category>python</category>
    </item>
  </channel>
</rss>
