Build generative agent simulations with deterministic physics and emergent behavior
Project description
Build generative agent simulations.
Miniverse is a Python-first simulation library inspired by Stanford's Generative Agents study. The goal is to give developers everything needed to build simulations with comparable fidelity: hard deterministic physics, partial observability, structured memories, and optional LLM cognition. It focuses on agent logic and state management rather than rendering.
You write the physics (SimulationRules), decide how much cognition stays deterministic versus LLM-driven, and the orchestrator composes those modules so you can run reproducible baselines or improvised experiments.
Alpha: APIs are still moving. Every breaking change is logged in CHANGELOG.md with context.
Setup
# clone the repository
git clone https://github.com/miniverse-ai/miniverse.git
cd miniverse
# install dependencies into a local uv environment
uv sync
Run examples with uv run .... A PyPI package is not published yet.
Tour the examples
Each example folder ships a README with prompts, flags, and debugging tips.
Workshop progression (examples/workshop/)
01_hello_world- Single deterministic agent, minimalSimulationRules. Run:uv run python -m examples.workshop.01_hello_world.run02_deterministic- Multiple agents with threshold logic and resource coupling.03_llm_single- Swaps inLLMExecutor; requiresLLM_PROVIDER,LLM_MODEL, and a provider API key.04_team_chat- Natural-language coordination via thecommunicationfield; memories capture transcripts.05_stochastic- Adds randomness to physics while LLM cognition adapts.monte_carlo.py- Batch runner executing many trials with different seeds, printing statistics (mean backlog, clearance rate, worst case).
examples/workshop/run.py ties these ideas together: deterministic baseline by default, --llm flag, cadence controls, optional world-engine calls, and per-tick analysis hooks.
Snake (examples/snake/run.py)
- Tier-2 grid world with deterministic movement and ASCII perception windows.
- Demonstrates how
customize_perception()can inject readable summaries while keeping structured data intact.
Run: uv run python -m examples.snake.run --ticks 40
Smallville Valentine's micro-replication (examples/smallville/)
- Recreates the Generative Agents Valentine's scenario with planning, execution, reflection, and memory streams.
- Debug flags (
DEBUG_LLM,DEBUG_MEMORY,MINIVERSE_VERBOSE) surface prompts, memories, and world updates.
Run:
export LLM_PROVIDER=openai
export LLM_MODEL=gpt-5-nano
export OPENAI_API_KEY=sk-your-key
uv run python examples/smallville/valentines_party.py
The folder includes a notebook and notes detailing the replication.
How a tick works
SimulationRules.apply_tick()updates deterministic physics (resource drains, stochastic events).build_agent_perception()enforces partial observability (own status, shared dashboards, broadcasts, direct messages, optional grid window).- Executors (deterministic or
LLMExecutor) return anAgentActionper agent. SimulationRules.process_actions()can resolve the world; otherwise the world-engine LLM processes the actions.- Persistence stores the new
WorldStateand actions (InMemoryPersistence,JsonPersistence, orPostgresPersistence). MemoryStrategyrecords observations so agents have context on the next tick.
Hooks such as customize_perception(), should_stop(), cadence utilities, and tick listeners let you adjust behavior without editing the orchestrator.
Minimal harness
from pathlib import Path
from miniverse import Orchestrator, SimulationRules, ScenarioLoader, build_default_cognition
from miniverse.schemas import AgentAction, WorldState
loader = ScenarioLoader(scenarios_dir=Path("examples/scenarios"))
world_state, profiles = loader.load("workshop_baseline")
agents = {profile.agent_id: profile for profile in profiles}
class WorkshopRules(SimulationRules):
def apply_tick(self, state: WorldState, tick: int) -> WorldState:
updated = state.model_copy(deep=True)
backlog = updated.resources.get_metric("task_backlog", default=6, label="Task Backlog")
backlog.value = max(0, int(backlog.value) - 1)
return updated
def validate_action(self, action: AgentAction, state: WorldState) -> bool:
return True
world_prompt = "You are the world engine. Apply validated actions deterministically."
agent_prompts = {
agent_id: f"You are {profile.name}, a {profile.role}. Return an AgentAction JSON."
for agent_id, profile in agents.items()
}
cognition = {agent_id: build_default_cognition() for agent_id in agents}
orchestrator = Orchestrator(
world_state=world_state,
agents=agents,
world_prompt=world_prompt,
agent_prompts=agent_prompts,
simulation_rules=WorkshopRules(),
agent_cognition=cognition,
)
result = await orchestrator.run(num_ticks=10)
Swap agents to LLMExecutor, add planners (LLMPlanner or deterministic alternatives), and wire reflection engines when you need higher-fidelity cognition.
Library map
- Orchestrator (
miniverse/orchestrator.py) - tick loop, prompt preflight, persistence/memory integration, cadence handling. - Simulation rules (
miniverse/simulation_rules.py) - deterministic physics, validation, optional deterministicprocess_actions(), lifecycle hooks. - Perception (
miniverse/perception.py) - Stanford-style partial observability with grid visibility and ASCII helpers. - Cognition (
miniverse/cognition/) - planners, executors, reflection engines, prompt rendering, cadence utilities, scratchpads. - Memory (
miniverse/memory.py) - FIFO default; extend for weighted or semantic retrieval. - Persistence (
miniverse/persistence.py) - async backends for state, actions, memories. - Environment helpers (
miniverse/environment/) - graph occupancy, BFS pathfinding, grid move validation, visibility rendering. - LLM utilities (
miniverse/llm_calls.py,miniverse/llm_utils.py) - structured calls with schema validation and retry feedback. - Scenario loader (
miniverse/scenario.py) - JSON-to-world-state converter.
Debugging and analysis
DEBUG_LLM=1prints prompts and responses.DEBUG_MEMORY=1logs memory writes and retrievals.- Tick listeners (
tick_listenersargument onOrchestrator) let you stream metrics or run custom analysis. - The Monte Carlo script shows how to batch runs with different seeds and summarize outcomes.
Documentation
docs/USAGE.md- scenario authoring, cognition wiring, cadence decisions.docs/PROMPTS.md- renderer placeholders, action catalog formatting, template conventions.docs/architecture/- deep dives on cognition flow, environment tiers, persistence design.docs/RESEARCH.md- research notes referencing Stanford Generative Agents, Smallville-inspired studies, branching narrative systems, structured simulation-state management, and other sources catalogued indocs/research/.ISSUES.md- active investigations and roadmap items.
Contributing
- Run
uv run pytestbefore opening a PR. - Keep changes scoped; include transcripts or logs when demonstrating new agent behavior.
- We welcome new scenarios, physics modules, cognition strategies, and tooling improvements.
Credits
- Creator: Kenneth / @local0ptimist
- Co-conspirators: GPT-5 Codex, Claude Code, and everyone building stranger simulations than we predicted.
- Research inspirations: detailed commentary lives in
docs/RESEARCH.mdanddocs/research/.
License
MIT. Fork responsibly.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file miniverse-0.2.0.tar.gz.
File metadata
- Download URL: miniverse-0.2.0.tar.gz
- Upload date:
- Size: 96.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31408db4fac3f22140e60b19229de62080cf9d9003d535a4834fd96f5d4b81ae
|
|
| MD5 |
d49ffa4705e72a10b3f0f25b2dd65224
|
|
| BLAKE2b-256 |
d9d3ca69191448fad635904ae029326ab2b6329c953a0b1009be5563b9bda1e1
|
File details
Details for the file miniverse-0.2.0-py3-none-any.whl.
File metadata
- Download URL: miniverse-0.2.0-py3-none-any.whl
- Upload date:
- Size: 88.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbf60172cf452121fc0d1853684bc6e619d355501406d04da592a1b1a3549914
|
|
| MD5 |
129c63e7b899f37d8cd85fdfdd8a0274
|
|
| BLAKE2b-256 |
5465a886d19cfd134e8c4d6080d2b908c5a276f0fc18029ae40bb3f0220e6faf
|