Simulation Streams: A Programming Paradigm for Controlling Large Language Models and Building Complex Systems with Generative AI

Peter Sunehag, Joel Z. LeiboarXiv 2025 · DOI

Abstract

Large Language Models (LLMs) demonstrate remarkable potential for simulating complex worlds and agents, yet they frequently encounter "agentic" failures such as format drift, model laziness, and context exhaustion. We introduce Simulation Streams, a novel programming paradigm that structures LLM interactions within a state-based framework. By utilizing an Entity-Component-System (ECS) architecture and selective "substreams," Simulation Streams enforce strict world rules and manage context efficiently. Our experiments across reinforcement learning benchmarks and complex social/economic simulations demonstrate that this paradigm significantly improves long-term stability and consistency, particularly with newer models like Gemini 2.0.

Introduction

Despite their reasoning capabilities, LLMs often fail in long-horizon simulations. Key challenges include format drift, where models stop adhering to required output structures; model laziness, where they summarize rather than simulate steps; and context bloat, where the accumulation of history leads to "omniscience" or context window exhaustion. Furthermore, LLMs struggle to enforce rigid physical or logical rules, such as inventory tracking or spatial constraints. Simulation Streams address these issues by treating simulations as a sequence of structured state updates rather than open-ended text generation.

Methods: The Simulation Streams Paradigm

The core of the Simulation Streams paradigm is the decomposition of a simulation into discrete Operators. Each operator is a modular program defining how a specific state variable evolves.

Table 1: Example of Simulation Stream Operators defining state transitions and LLM query conditions.

As shown in the table above, an operator includes:

  • Formula/Action: A deterministic rule (often Python-based) for state updates.
  • LLM Condition: A logic gate determining if the LLM needs to be invoked for a specific step.
  • Query: A mechanism to select relevant "substreams" of history, preventing context bloat by only providing the model with information pertinent to the current task.

The framework further adopts the Entity-Component-System (ECS) architecture from game development. Simulations are organized into Entities (actors) and Components (data/behaviors), allowing for high modularity. For instance, a "Communication" component can be swapped or added to an agent without re-engineering the entire system.

Evaluation and Results

The paradigm was evaluated across three environments: a suite of six reinforcement learning (RL) tasks (e.g., Windy Gridworld, Mountain Car), a multi-agent social simulation involving dialogue and physical actions, and a long-running market economy simulation with eight interacting markets.

Figure 1: Normalized average performance across various RL tasks, comparing different Gemini model versions.

Experimental results indicate that while Gemini 1.5 Pro-002 often achieves the highest peak performance in RL benchmarks, Gemini 2.0 Flash-Exp (including the "Thinking" variant) exhibits exceptional consistency. These models followed the structured stream format without errors over hundreds of steps, effectively solving the "format drift" problem.

Key findings include:

  • Long-Term Stability: The framework maintained coherent market dynamics and social interactions over thousands of iterations, avoiding the compounding inconsistencies typical of purely prompt-based methods.
  • Information Control: By filtering the output stream via queries, the authors successfully modeled "limited knowledge," preventing agents from acting on information they shouldn't possess.
  • Efficiency: Enforcing a specific format reduced "token waste," making the simulations more economical and faster.

Conclusion

Simulation Streams provide a robust "track" for LLMs, allowing them to focus on high-level reasoning while external logic handles "world physics." While the paradigm currently requires manual setup of operators and is sensitive to initial "exemplar" quality, it offers a scalable path toward building complex, multi-agent systems. Future work will explore the generation of high-quality synthetic data for training more advanced agentic models.

Summary updated

BibTeX
@misc{sunehag2025simulation,
  author = {Peter Sunehag and Joel Z. Leibo},
  title = {{Simulation Streams: A Programming Paradigm for Controlling Large Language Models and Building Complex Systems with Generative AI}},
  year = {2025},
  eprint = {2501.18668},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.18668},
}
Figure