-
Notifications
You must be signed in to change notification settings - Fork 0
AI_DOCS
Concise reference for AI agents working on the MONITOR codebase.
FIRST: Read
ARCHITECTURE.mdandCLAUDE.mdat the repo root.
monitor2/
├── ARCHITECTURE.md ← READ FIRST: Layer rules
├── CLAUDE.md ← READ FIRST: AI instructions
├── docs/ # Documentation
├── infra/ # Docker infrastructure
├── packages/ # THE THREE LAYERS
│ ├── data-layer/ # Layer 1: MCP Server + DB clients
│ ├── agents/ # Layer 2: AI Agents
│ └── cli/ # Layer 3: User Interface
└── scripts/ # Dev utilities
┌─────────────────────────────┐
│ Layer 3: CLI │ packages/cli/
│ Depends on: agents ONLY │
└──────────────┬──────────────┘
│ imports
▼
┌─────────────────────────────┐
│ Layer 2: AGENTS │ packages/agents/
│ Depends on: data-layer │
└──────────────┬──────────────┘
│ imports
▼
┌─────────────────────────────┐
│ Layer 1: DATA-LAYER │ packages/data-layer/
│ Depends on: external only │
└─────────────────────────────┘
RULES:
- Dependencies flow DOWNWARD only
- No skip-layer imports (CLI cannot import data-layer directly)
- Each layer has its own
pyproject.toml
MONITOR = Multi-Ontology Narrative Intelligence Through Omniversal Representation
An Auto-GM system for tabletop RPGs that maintains canonical truth across multiple databases.
- Data-First - Databases define architecture, not code
- Canonization-Driven - Explicit gates control what becomes truth
- Agent-Agnostic - Stateless agents interact via MCP tools
- Provenance-Tracked - All canonical facts link to evidence
- Multi-Database - Each database serves a specific purpose
| Database | Role | Authoritative For |
|---|---|---|
| Neo4j | Canonical truth | Entities, facts, events, relationships |
| MongoDB | Narrative layer | Scenes, turns, proposals, memories |
| Qdrant | Semantic search | Vector embeddings (1536 dims, OpenAI) |
| MinIO | Binary storage | PDFs, images, raw files |
| OpenSearch | Full-text search | Precision keyword queries (optional) |
| Agent | Responsibility | Neo4j Write? |
|---|---|---|
| Orchestrator | Loop management | Limited (Story only) |
| ContextAssembly | Context retrieval | No (read-only) |
| Narrator | Narrative generation | No |
| Resolver | Rules/dice resolution | No |
| CanonKeeper | Canonization | Yes (exclusive) |
| MemoryManager | Character memories | No |
| Indexer | Background indexing | No |
User Input → MongoDB (Turn) → Proposals → [Canonization Gate] → Neo4j (Facts) → Qdrant (Embeddings)
Not everything becomes truth. The canonization gate is the explicit decision point where narrative (MongoDB) becomes canon (Neo4j).
When: End of scene (primary), mid-scene for critical events (optional)
What gets canonized:
- Facts/Events
- Entity creation
- Relationship changes
- State transitions
What stays narrative:
- Turn transcripts
- GM/player notes
- Rejected proposals
| Type | Description | Has state_tags? |
|---|---|---|
| EntityArchetype | Archetypes, concepts ("Wizard", "Orc") | No |
| EntityInstance | Specific instances ("Gandalf", "The One Ring") | Yes |
EntityInstance can derive from EntityArchetype via DERIVES_FROM relationship.
| Authority | Weight | Example |
|---|---|---|
source |
Highest | D&D PHB, official lore |
gm |
High | GM declarations |
player |
Medium | Player actions via resolution |
system |
Lowest | System inferences |
| Level | Meaning |
|---|---|
proposed |
Suggested, awaiting approval |
canon |
Accepted as truth |
retconned |
Superseded by newer fact |
Exception: Source nodes use authoritative instead of retconned (sources aren't revised, only facts from them).
- CanonKeeper is the only agent with Neo4j write access (except Orchestrator for Story)
-
All canonical facts must have evidence - via
SUPPORTED_BYedges orevidence_refsproperty - Scenes are canonization boundaries, not turns - batch writes at scene end
- Neo4j never references external DB primary keys - only UUIDs
- Qdrant is never authoritative - derived index only, rebuildable
-
Entities are never deleted - marked
retconnedinstead - State tags are only on EntityInstance - EntityArchetype is timeless
monitor2/
├── ARCHITECTURE.md # Layer rules (READ FIRST)
├── CLAUDE.md # AI agent instructions (READ FIRST)
├── README.md # Project overview
│
├── docs/
│ ├── architecture/ # System design (6 files)
│ │ ├── DATABASE_INTEGRATION.md
│ │ ├── CONVERSATIONAL_LOOPS.md
│ │ ├── AGENT_ORCHESTRATION.md
│ │ ├── DATA_LAYER_API.md
│ │ ├── MCP_TRANSPORT.md
│ │ └── VALIDATION_SCHEMAS.md
│ ├── ontology/ # Data model (3 files)
│ │ ├── ONTOLOGY.md
│ │ ├── ENTITY_TAXONOMY.md
│ │ └── ERD_DIAGRAM.md
│ ├── IMPLEMENTATION_GUIDE.md
│ └── AI_DOCS.md # This file
│
├── infra/ # Docker infrastructure
│ ├── docker-compose.yml
│ └── README.md
│
├── packages/ # THE THREE LAYERS
│ ├── data-layer/ # Layer 1: MCP server + DB clients
│ │ ├── pyproject.toml
│ │ └── src/monitor_data/
│ │ ├── db/ # Database clients
│ │ ├── tools/ # MCP tools
│ │ ├── schemas/ # Pydantic models
│ │ └── middleware/ # Auth enforcement
│ │
│ ├── agents/ # Layer 2: AI agents
│ │ ├── pyproject.toml
│ │ └── src/monitor_agents/
│ │ ├── orchestrator.py
│ │ ├── narrator.py
│ │ ├── canonkeeper.py
│ │ └── ...
│ │
│ └── cli/ # Layer 3: User interface
│ ├── pyproject.toml
│ └── src/monitor_cli/
│ ├── main.py
│ └── commands/
│
└── scripts/ # Dev utilities
| Node | Key Properties |
|---|---|
Omniverse |
id, name |
Multiverse |
id, omniverse_id, system_name |
Universe |
id, multiverse_id, genre, tone |
Source |
id, universe_id, doc_id, source_type |
Axiom |
id, universe_id, statement, domain |
EntityArchetype |
id, universe_id, name, entity_type, properties |
EntityInstance |
id, universe_id, name, entity_type, properties, state_tags |
Story |
id, universe_id, title, story_type, status |
Scene |
id, story_id, title, purpose |
Fact |
id, universe_id, statement, time_ref, confidence, authority |
Event |
id, scene_id, title, severity |
PlotThread |
id, story_id, title, thread_type |
| Collection | Purpose |
|---|---|
scenes |
Narrative scenes with turns array |
proposed_changes |
Canonization staging |
resolutions |
Dice/rules outcomes |
character_memories |
NPC/PC subjective memories |
documents |
Ingested source metadata |
snippets |
Document chunks |
character_sheets |
Character sheets |
story_outlines |
Narrative planning |
character, faction, location, object, concept, organization
- Life: alive, dead, unconscious, dying
- Health: healthy, wounded, poisoned
- Position: standing, prone, flying, hidden
- Social: hostile, friendly, allied, enemy
- Add to
entity_typeenum inVALIDATION_SCHEMAS.md - Define type-specific properties in
ENTITY_TAXONOMY.md - Update Neo4j constraints if needed
- Add to MongoDB schema validation
- Review
DATABASE_INTEGRATION.md§ Canonization Gate - Update
CanonKeeperinAGENT_ORCHESTRATION.md - Modify
composite_canonize_sceneinMCP_TRANSPORT.md
- Define schema in
VALIDATION_SCHEMAS.md - Add to appropriate section in
DATA_LAYER_API.md - Create MCP tool in
MCP_TRANSPORT.md - Update authority matrix in
AGENT_ORCHESTRATION.md
- Start with
ONTOLOGY.md(canonical model) - Update
ERD_DIAGRAM.md(visual representation) - If entity-related, update
ENTITY_TAXONOMY.md - Add Pydantic models to
VALIDATION_SCHEMAS.md
# Only CanonKeeper can write to Neo4j
@require_authority(["CanonKeeper"])
async def neo4j_create_fact(request: FactCreate) -> FactResponse:
...# Every fact needs evidence
class FactCreate(BaseModel):
evidence_refs: list[str] = Field(min_items=1) # Required!# Canonization happens at scene end, not per-turn
async def finalize_scene(scene_id: str):
proposals = await get_pending_proposals(scene_id)
for p in proposals:
if evaluate(p):
await neo4j_create_fact(p) # Batch write| Loop | Latency | Canonization |
|---|---|---|
| Main | < 100ms | None |
| Story | Hours-days | 1 write (Story) |
| Scene | 5-30 min | 1 batch write |
| Turn | < 2s | None (deferred) |
-
Primary design:
docs/architecture/DATABASE_INTEGRATION.md -
Data model:
docs/ontology/ONTOLOGY.md -
API spec:
docs/architecture/DATA_LAYER_API.md -
Implementation:
docs/IMPLEMENTATION_GUIDE.md