-
-
Simulacra: Learn not just from the past, but also from the future!
-
Simulation of Economic Policy. 100 swarm agents with different personas, harnessed by orchestrator agent!
-
Report of Simulation's Economic Policy
-
Conversation with one NPC swarm agent
-
Social Graph Network displaying each personas relations
-
Built with Zed + Neovim + Opencode
-
Attach policy (pdf), latest economic trends (csv) any data needed for accurate simulation
Simulacra: The Autonomous Society
Inspiration
We were inspired by the massive gap between static economic whitepapers and the messy reality of human behavior. Traditional models often treat citizens as rational variables, but real-world policy shifts fail because of social contagion, irrational fear, and localized memory. We wanted to build a "living" laboratory where you could drop a 500-word policy and watch 100 unique AI lives react in real-time. Drawing from the Generative Agents research by Park et al., we envisioned a world where agents don't just calculate—they perceive, reflect, and influence their neighbors in a pixel-art city that breathes with every fiscal change.

How we built it
Simulacra is built on a full-stack generative agent pipeline orchestrated by LangGraph, powered by the K2-Think V2 model, and built using Zed. When a user submits a policy — via uploaded PDFs, video, text, or CSV trend data — the backend merges all sources into a unified context, then runs a structured LLM pipeline: first parsing the policy into economic entities and stakeholders, then spawning N NPC agents with procedurally generated personalities, relationships, and memories placed on a tile map. Each simulation round runs all NPCs in parallel via asyncio, with each agent following a perceive-retrieve-reflect-plan-act loop grounded in the generative agents architecture from Park et al. 2023. Post-round, opinion dynamics based on Deffuant bounded confidence and Baumann controversy amplification update political leanings and moods across the social graph. Results stream in real time over Socket.IO to a React frontend, where an EventBridge singleton decouples the data layer from a Phaser 3 pixel-art world — NPCs move, protest, and converse as events arrive, while dashboards, an event feed, a social graph, and an AI-generated economic report surface the simulation's downstream consequences.
The Math of Social Influence
A critical part of Simulacra is how opinions spread across the city. We implemented the Deffuant Bounded Confidence Model to determine if two NPCs will influence each other based on their current economic outlook. If the difference between two agents' opinions is within a certain threshold $\epsilon$, they move toward a consensus; otherwise, they remain polarized. The update rule for an agent’s opinion $x_i$ after interacting with agent $j$ is defined as:
$$x_i(t+1) = x_i(t) + \mu [x_j(t) - x_i(t)] \text{ if } |x_i(t) - x_j(t)| < \epsilon$$
We further amplified this with Baumann Controversy logic, where high-stakes policies like minimum wage hikes use a $tanh$ function to push agents toward extreme emotional states, visualized in-game as floating emoticons and bankruptcy markers.
The Memory Reflection Layer
Beyond raw social influence, Simulacra agents don't just accumulate experiences — they synthesize them. Inspired by the reflection architecture in Park et al. (2023), each NPC maintains an append-only memory stream of observations, plans, and prior reflections. Every round, the system scores each new memory with a heuristic importance value (e.g., a protest scores 8, a casual movement scores 2). When the cumulative importance of an agent's un-reflected memories crosses a threshold of 25, that agent enters a reflection phase — an LLM call that distills its recent experiences into 2–3 higher-level insights.
Challenges we faced
The primary technical hurdle was the memory bottleneck. As the simulation progressed through K rounds, each of the N agents accumulated hundreds of observations, threatening to blow out our context windows and slow down the WebSocket feed. We addressed this by implementing a scored retrieval system — ranking memories by recency decay, heuristic importance, and keyword relevance — so each agent only receives the most contextually relevant observations at inference time rather than its full history. This kept prompts lean without sacrificing coherence. We also leaned heavily on K2 Think as our inference backbone, whose low hallucination rate meant agents produced structured, parseable outputs consistently across hundreds of parallel LLM calls — critical when a single malformed response could desync an entire simulation round.
Powered by Zed
We built Simulacra using the Zed IDE, which was instrumental in maintaining our 24-hour development pace. Zed’s high-performance architecture allowed us review code at insanely fast speeds. The built-in AI features and the sheer speed of the editor made it possible to navigate the complex interactions between our FastAPI routers and Phaser scenes with zero friction.

Built With
- bun
- fastapi
- k2-think
- langgraph
- phaser.js
- tiled
- xai
Log in or sign up for Devpost to join the conversation.