# An Open-Source Framework for Emergent Multi-Agent Social Simulations

> "This serves as a **complex** mirror to real-world systems of power, belief, and **emergent social behavior**.”

The architecture leverages **LangGraph** for cycle management and **ChromaDB** for persistent storage. It runs locally on consumer-grade hardware by utilizing **Gemma** models for their high intelligence-to-parameter ratio.

Interventions are managed asynchronously through a **Human-in-the-Loop (HITL)** interface, enabling real-time **state injections** that influence the simulation's trajectory via a Telegram-based command protocol.

### **Persistence and Long-Context Management**

To achieve infinite uptime, the framework implements **hierarchical recursive summarization**. This ensures the "World Engine" maintains historical awareness without exceeding context limits, while **LangGraph checkpointers** provide durability across system reboots.

* * *

### **Orchestration: LangGraph and the Router Pattern**

The backbone of this infinite loop is **LangGraph**, which facilitates a stateful, cyclic graph architecture. It allows nodes to represent distinct agents—such as the Logic Engine and Narrative agents—while edges define the flow of information through a persistent **Observe-Think-Act** loop.

To bypass the strict limits of consumer cards, the framework utilizes **llama.cpp’s router mode**. This implementation uses a **Least Recently Used (LRU) eviction policy**, dynamically swapping models between the GPU and the **system RAM**.

![](https://cdn.hashnode.com/uploads/covers/69d10b786792e486f66795a1/afb009a9-ff32-45b3-aa7e-65f502d62f34.png align="center")

### **The Quantization Standard**

By reducing model weights from 16-bit to 4-bit, we significantly lower the VRAM footprint—allowing a 9B model that would normally require **18GB** to fit into just **5.8GB** of VRAM, thus maintaining high reasoning capabilities on a local workstation.

This precision reduction preserves the vast majority of the model's emergent behavior while leaving critical headroom for the **KV Cache**, which stores the context of the current conversation. For extended simulations, we further utilize **4-bit KV cache quantization** to reduce context penalty by up to **50%**, enabling deeper historical awareness within the hardware's physical limits.

### **VRAM Reference by Model and Quantization**

*These figures are planning ranges for local use. Real usage will be slightly higher once the runtime, context window, and KV cache are active.*

<table style="min-width: 150px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1"><p><strong>Model</strong></p></td><td colspan="1" rowspan="1"><p><strong>Q2</strong></p></td><td colspan="1" rowspan="1"><p><strong>Q4 (Default)</strong></p></td><td colspan="1" rowspan="1"><p><strong>Q5</strong></p></td><td colspan="1" rowspan="1"><p><strong>FP16</strong></p></td><td colspan="1" rowspan="1"><p><strong>Practical Application</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>E2B</strong></p></td><td colspan="1" rowspan="1"><p>~0.8 GB</p></td><td colspan="1" rowspan="1"><p><strong>~1.5 GB</strong></p></td><td colspan="1" rowspan="1"><p>~1.8 GB</p></td><td colspan="1" rowspan="1"><p>~4 GB</p></td><td colspan="1" rowspan="1"><p>Minimal agents; CPU-heavy setups.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>E4B</strong></p></td><td colspan="1" rowspan="1"><p>~2 GB</p></td><td colspan="1" rowspan="1"><p><strong>~3.5 GB</strong></p></td><td colspan="1" rowspan="1"><p>~4.2 GB</p></td><td colspan="1" rowspan="1"><p>~8 GB</p></td><td colspan="1" rowspan="1"><p>Standard starting point for local agents.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>26B A4B</strong></p></td><td colspan="1" rowspan="1"><p>~9 GB</p></td><td colspan="1" rowspan="1"><p><strong>~14 GB</strong></p></td><td colspan="1" rowspan="1"><p>~17 GB</p></td><td colspan="1" rowspan="1"><p>~52 GB</p></td><td colspan="1" rowspan="1"><p>High-tier social complexity; requires 24GB GPU.</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>31B</strong></p></td><td colspan="1" rowspan="1"><p>~12 GB</p></td><td colspan="1" rowspan="1"><p><strong>~20 GB</strong></p></td><td colspan="1" rowspan="1"><p>~24 GB</p></td><td colspan="1" rowspan="1"><p>~62 GB</p></td><td colspan="1" rowspan="1"><p>Maximum local reasoning; 24GB VRAM required.</p></td></tr></tbody></table>

## Join the Experiment.

This is an invitation to build your own scenarios—whether they be utopian social experiments or harrowing studies of civilizational collapse.

%[https://soundcloud.com/mihai-vancea-909027674/building-persistent-ai]
