All projects
Game / AIactive

Paxhistoria

WWII grand strategy simulation where 95 nations are live LLM agents with historically-grounded personas — they negotiate alliances, declare wars, and respond to diplomatic overtures in real time via SSE streaming.

PythonFastAPINext.jsOllamaReact

Skills involved

PythonTypeScript/ReactBackend APIsGame Dev

What This Is

A WWII grand strategy simulation with AI-powered diplomatic agents, real-time battle logs, and territorial control across 95 nations. The premise: every country in the 1939 world is a live LLM agent with a historically-grounded persona. Alliances are negotiated, invasions are declared, and the course of the war can diverge wildly from history — all generated in real time.

The core question is whether LLMs can reason consistently about geopolitical constraint: a country agent should act in its national interest given military capacity, diplomatic standing, and historical context — not just produce plausible-sounding text.

The Simulation Engine

The world state is a turn-based system with season and year tracking. Each turn, every nation processes its current situation and produces diplomatic and military actions via an LLM call with a role-constrained system prompt encoding its national persona, current alliances, and territorial status.

95 countries are modelled with historical granularity — distinguishing sovereign states, colonies, and dominions. Special simulation rules handle historically pivotal dynamics:

  • Operation Barbarossa progression: the German eastern front is modelled as a distinct path with branching conditions
  • Italian East Africa: single-region occupation logic with historical accuracy
  • Colonial status tracking: transitions between colony and sovereign state as the war evolves

Real-Time Architecture

The backend uses Server-Sent Events (SSE) to stream simulation state to the frontend in real time — battle outcomes, diplomatic declarations, and territory changes appear as they're generated without page refreshes.

FastAPI Backend (SSE streaming)
      ↓
LLM via Ollama or OpenAI-compatible API
      ↓
Country Persona Templates → Action Generation
      ↓
Battle Resolution + Territory Updates
      ↓
Next.js Frontend (real-time event display)

AI Diplomacy

Each country has a structured persona template defining its leadership style, geopolitical goals, ideological alignment, and military doctrine. When another country makes a diplomatic overture, the agent receives the full context of recent actions and generates a response constrained by the persona.

The hard problem is positional consistency across turns: an agent that refuses a trade deal on turn 3 shouldn't accept the same deal on turn 7 without a reason. We track the diplomatic history per pair of nations and inject relevant prior interactions into each agent's context.

Interactive Diplomatic Chat

Users can interject directly into the simulation — requesting a meeting with any country's leadership and conducting live diplomatic negotiations. The agent responds in character, and the outcome of the negotiation feeds back into the simulation state.

Current Stack

  • Backend: FastAPI with Pydantic models, SSE streaming, configurable LLM integration
  • Frontend: Next.js / React with real-time event handling
  • LLM: Ollama (local) or any OpenAI-compatible endpoint
  • Data: JSON-based game state with Pydantic validation throughout

What's Next

  • Persistent game saves with full history replay
  • Multiplayer mode: human players take control of specific nations
  • Agent memory: country personas that evolve based on past simulation runs
  • Historical divergence scoring: quantify how far a run deviates from actual WWII history

Last updated Feb 12, 2026

← Back to all projects