Cenosis Documentation
Cenosis is a Rust behavior engine for always-live, socially believable NPCs. It integrates into Unity, Unreal, or any web engine via a stable C ABI or WebAssembly — and never blocks your game thread.
Quick Start
Three commands to get a running build:
PowerShell# 1. Build native DLL (Unity / Unreal)
.\build-ffi.ps1
# 2. Build WASM + JS glue (browser)
.\build-wasm.ps1
# 3. Run the test suite
.\test.ps1 unit
Generated bindings are committed at npc-ffi/bindings/NpcEngineV40.{cs,hpp,ts} — copy the appropriate file into your host project and you're type-safe against the frozen ABI.
What Cenosis gives you
The central value proposition is simple: every NPC in the world is always doing something believable, whether or not the player is watching.
- Persistent social world — NPCs evolve relationships, beliefs, memories, moods, and reputations independently of player interaction.
- Scalable simulation — 20-NPC village to 10,080-agent city, with deterministic and reproducible behavior at every scale.
- LLM-powered narrative — dialog, reflection, and wake summaries driven by cloud LLMs with hard budget governance.
- Clean host integration — non-blocking C ABI and WASM surface; all FFI is
catch_unwind-wrapped. - Extension API — replace any core decision in Rust or from C#/C++/JS without recompiling the engine.
What Cenosis is NOT
Out of scope by design — the host engine handles these:
- Pathfinding / navmesh
- Animation — the engine emits structured action descriptors
- Voice synthesis / ASR
- Combat or destructive mutation
- Procedural terrain, quest, or world generation
- Rendering
Workspace Crate Map
The workspace is 18 crates. npc-common is the leaf — everything depends on it. npc-ffi is the only outward-facing surface — the only thing host code links against.
| Crate | Layer | Purpose |
|---|---|---|
npc-common | Leaf | Shared types — AgentId, WorldTime, Need, TimelineEvent, EngineError, the 7 *Policy traits. Everything depends on this. |
npc-storage | Persistence | SQLite projections, WAL writer thread, HNSW vector index, NPCB v17 bundle format. |
npc-world | World state | World, WorldClock, location graph, SmartObject + Affordance definitions. |
npc-social | Social graph | RelationshipGraph (6 asymmetric dims), BeliefStore (theory-of-mind), gossip/rumor propagation. |
npc-agent | Agent model | Agent, Persona, Mood, Schedule, needs map with decay rates, custom needs registry. |
npc-runtime | The spine | FS/SS/Macro tier map, AgentRuntime::tick, SceneManager, tier transitions, reflection, wake summary. |
npc-planning | Decision | UtilitySelector (utility AI), GoalSelector, relationship-intent bias. |
npc-cognition | LLM | PromptBuilder, ConstraintEngine, local ONNX SLM, identity drift. |
npc-budget | Governance | Per-agent/session/hour caps, priority queue, prompt→response cache, circuit breaker. |
npc-director | Drama | StoryletEngine, tension pacing, storylines, factions, life/economic event pulses. |
npc-cloud | LLM client | rig-core 0.18 native (Anthropic, Synthetic.new) / fetch on WASM. |
npc-modding | WorldPacks | Pack loading, validation, DependencyResolver, NamespaceRegistry, URL pack install. |
npc-editor | Authoring | PackEditor — editable in-memory WorldPack, live validation, lossless save. |
npc-extend | Extension API | Extension trait, 7 policy + 4 service seams, ConformanceVerifier, DeepExtension. |
npc-ffi | Only outward | cdylib (C ABI) + wasm-bindgen. 65+ exported symbols. |
npc-replay | Repro | RPRO repro bundle capture + CLI replay with divergence localization. |
npc-codegen | Bindings gen | C# / C++ / TypeScript host bindings from the frozen ABI surface. |
npc-tests | Acceptance | Synthetic towns, deterministic replay, scale benchmarks, ABI/API stability gates. |
Technology Stack
| Layer | Technology |
|---|---|
| Language | Rust 1.95 (Edition 2024, resolver 3) |
| Persistence | SQLite (rusqlite bundled) + okaywal WAL + HNSW vector index |
| Cloud LLM | rig-core 0.18 → Anthropic / Synthetic.new (native); fetch (WASM) |
| Local inference | ONNX Runtime (ort 2.0) for embeddings + tactical SLM |
| Async | tokio (cloud path only); game-facing FFI is synchronous and non-blocking |
| Concurrency | crossbeam-channel (ingress), rayon (parallel social compute), parking_lot / dashmap |
| WASM storage | sqlite-wasm-rs + OPFS VFS (sahpool) inside Web Worker |
| Build | cargo-zigbuild for cross-platform native; wasm-pack for browser |
| Editor GUI | Tauri 2 desktop shell (detached workspace) |