Inspiration

During quarantine, I developed an interest in history and spent time reading, listening to podcasts, and playing strategy games. Games like EU4 let players control a nation over long periods of history. One recurring problem was that the AI running other countries felt too simple, relying on basic rules like attacking whenever a neighbour seemed weak. This removed much of the historical depth. Ideally, a simulation running from 1444 to 2000 should produce a world that still looks broadly familiar. Instead, strategy games often create chaotic and unrealistic outcomes. Divergence is meant to address this problem.


What It Does

Divergence lets you rewrite history. You choose a pivotal moment, introduce a single “what if” divergence, and the system simulates the ripple effects across the next decade, drawing the changes on the map as you go.

The platform uses a multi-agent workflow to generate historically plausible alternate timelines:

  • Validation
    An AI filter rejects nonsensical or irrelevant divergences.

  • Historical Simulation
    A historian agent generates a decade of plausible events grounded in real-world context.

  • World Building
    A dreamer agent synthesizes these events into a coherent alternate reality.

  • Geographic Mapping
    A geographer agent translates territorial changes into precise modifications across 5,000+ provinces, rendered in real time on an interactive map.

  • Immersion
    Sub-agents generate period-appropriate quotes from key figures and AI-illustrated portraits to bring the timeline to life.

Users can continue simulating decade by decade or introduce new divergences at any point, creating branching timelines of infinite alternate histories.


How We Built It

Agentic Pipeline

We built a stateful, cyclic agent pipeline using LangGraph, where each agent operates as an independent node in a directed graph:

  • Filter Agent
    Validates divergences against historical context.

  • Historian Agent
    Retrieves and synthesizes decade-relevant events using RAG.

  • Dreamer Agent
    Generates plausible alternate futures with structured territorial outputs.

  • Geographer Agent
    Uses LLM tool-calling to query and manipulate a hierarchical geographic database
    (Regions → Areas → Provinces) with 5,000+ individually tracked territories.

  • Quote and Illustrator Agents
    Run in parallel to generate contextual quotes and pixel-art portraits using Gemini’s multimodal generation.

The workflow supports conditional branching, looping for multi-decade simulations, and persistent state via LangGraph checkpointing.


Frontend

The UI is built with Next.js 15 and React 19, featuring an interactive map that renders thousands of provinces with real-time ownership updates as the simulation progresses.


Data Pipeline

Province metadata is preprocessed from historical game data into optimized formats and JSON indices.

The backend exposes a FastAPI REST service that streams workflow state updates to the frontend in real time.


Challenges

The most difficult problem was the Geographer Agent.

Providing the names and context for all 5,000 provinces at once was impractical and exceeded context limits. Asking the agent to reason over the entire world simultaneously led to poor performance and hallucinations.


How We Solved It

We implemented a hierarchical mini-RAG system.

Instead of exposing all provinces, the Geographer Agent works through three abstraction layers:

  1. Regions
    Roughly 100 high-level regions (e.g., Arabia, Eastern America).

  2. Areas
    Each region returns several precisely named areas, typically collections of 5–7 provinces (e.g., Scotland, British Columbia).

  3. Provinces
    Only after narrowing down does the agent retrieve and modify individual provinces.

The agent selects relevant regions based on the Dreamer’s territorial output, drills down into areas, and finally applies changes at the province level.

This approach allows precise geographic edits without flooding the context window with irrelevant data.


What We Learned

  • LangGraph and LangChain enable powerful stateful, multi-agent workflows, but cyclic graphs require careful state management.
  • LangSmith was essential for debugging agent behavior.
  • Gemini’s tool-calling was reliable for structured outputs, though the Geographer Agent required iterative prompt refinement to prevent hallucinated locations.
  • Strict input/output contracts were necessary for multi-agent coordination. The Dreamer emits structured JSON that the Geographer can parse deterministically.
  • Streaming incremental province updates dramatically improved frontend UX compared to waiting for full simulation completion.
  • Gemini’s image generation produced strong pixel-art portraits with tuned prompts, though consistency remains a challenge.
  • Working at hackathon speed meant accepting rough abstractions early; LangGraph’s modular design made later refactors and agent swaps straightforward.

What’s Next for Divergence

  • Use stronger models for faster and more realistic simulations.
  • Improve world abstraction so smaller changes can be tracked meaningfully.
  • Expand the range of available historical starting points.

Built With

Share this project:

Updates