AI Civilization Sandbox is an agent-based civilization simulation where autonomous agents form settlements, organize labor, build infrastructure, and adapt over time under a Python simulation core.
The project aims to model emergent civilization behavior from local decision rules, resource constraints, and village-level governance.
Key principle:
- Python simulation is authoritative.
- Observer clients (web, Godot) are read-only.
world.pyowns mutable world state and tick progression.agent.pyandbrain.pydrive per-agent behavior and decision loops.systems/modules implement domain logic (farming, roads, buildings, villages, roles, AI policy, observability).worldgen/produces deterministic terrain layouts from seed/config.
state_serializer.pyconverts in-memory state into observer payloads.GET /stateis the canonical dynamic snapshot.GET /state/staticprovides static map payload (dimensions + tiles + optional seed).- Contract versioning is explicit via
schema_version,state_version, andstatic_state_version.
server.pyhosts FastAPI routes, starts the tick loop, and exposes observer endpoints.- The API is polling-oriented and returns JSON snapshots.
The core simulation loop coordinates these systems each tick:
farming_system: farm emergence, growth cycles, harvest flow, and farm viability logic.building_system: building catalogs, placement, construction sites, storage logistics, specialization, and build policy.road_system: movement usage tracking and transport network growth (path->road->logistics_corridor).village_system: village detection from structure clusters, continuity/stability tracking, and leadership/politics hooks.village_ai_system: village needs, market pressure, phase/priority selection, and proto-culture updates.role_system: workforce allocation, specialist balancing, and role continuity/reassignment constraints.observability: metrics snapshots/history for diagnostics and scenario evaluation.
- Located in
frontend/. - Fetches
/state/staticonce, then polls/state. - Builds local indexes for rendering (agents, villages, resources, buildings, roads).
- Located in
godot/. StateClient.gdfetches/state/staticand polls/state.- Merges static map fields into runtime payload for rendering convenience.
- Operates as read-only visualization/debug client.
GET /state returns the canonical runtime snapshot for observers. It includes:
- version fields (
schema_version,state_version,tick) - resource coordinates and counts (
food,wood,stone, counters) - farm data (
farms,farms_count) - built environment (
structures,roads,storage_buildings,buildings) - village objects (
villages,civ_stats) - agent objects (
agents) - aggregate population/leadership counters
- infrastructure observability summaries (
infrastructure_systems_available,transport_network_counts)
Reference docs:
docs/state_contract.mddocs/state_schema.json
- Create and activate a Python virtual environment.
- Install dependencies:
pip install -r requirements.txt- Start the server:
uvicorn server:app --reload- Open observers:
- Web:
http://127.0.0.1:8000/ - Godot: open
godot/project.godotand runres://scenes/Main.tscn
Quick /state inspection:
curl http://127.0.0.1:8000/state | python -m json.toolNear-term focus areas:
- stabilize village economy and food/material throughput
- improve logistics and construction delivery coherence
- harden multi-village emergence and persistence behavior
- continue observability and scenario-driven balancing workflows
- improve observer robustness as contract fields evolve