Agentic Rules-based & Creative Autonomous Narrative Architecture
"Erudite Automaton" โ A fully autonomous AI Dungeon Master (DM) for D&D 5e.
- Code Structure
- Installation
- Environment Setup Guide
- Usage Examples & Demonstrations
- Reproducible Experiments & Analysis
- Architecture & Implementation
- Quality Assurance & Testing
- Comprehensive Documentation
- Troubleshooting Guide
The project is divided into a Python-based backend (FastAPI + LangGraph) and a Next.js frontend.
/
โโโ backend/ # Core Logic
โ โโโ app/
โ โ โโโ agents/ # AI Agents (Orchestrator, Narrative, Rules, World)
โ โ โโโ api/ # FastAPI Routes (Play, Debug)
โ โ โโโ memory/ # Hybrid Memory (Neo4j + Vector Store)
โ โ โโโ models/ # Pydantic Schemas
โ โ โโโ rules/ # Rules Adjudication Engine
โ โโโ scripts/ # Utility scripts (Seeding, Testing)
โโโ frontend/ # UI
โ โโโ app/ # Next.js App Router Pages
โ โโโ components/ # React Components (CombatLog, InventoryPanel)
โโโ data/ # Data Storage
โ โโโ rules/ # D&D 5e Rules Data (JSON)
โ โโโ story/ # Story Modules
โ โโโ logs/ # Session Logs
โโโ scripts/ # Root-level experiment scripts
โโโ tests/ # Unit Tests
โโโ docker-compose.yml # Infrastructure Definition
โโโ evaluation.ipynb # Evaluation Process
Tip
For a detailed, step-by-step setup guide for new teammates, please refer to INSTRUCTION.md.
- Docker Desktop: Must be installed and running. Download from docker.
- Google Gemini API Key: Obtain one from Google AI Studio.
Run the startup script to initialize your environment file.
chmod +x start.sh
./start.shNote: The script will likely pause or fail the first time because your API key is missing.
Start the entire stack (Backend + Frontend + Neo4j):
./start.sh- Frontend: http://localhost:3000
- Backend API Docs: http://localhost:8000/docs
- Neo4j Browser: http://localhost:7474
The database starts empty. Populate it with initial locations, NPCs, and relationships:
docker-compose exec backend python -m app.scripts.seedThe project uses a .env file in the root directory.
| Variable | Description | Default |
|---|---|---|
GOOGLE_API_KEY |
Required. Your Gemini API Key. | None |
NEO4J_URI |
Address of the Neo4j database. | bolt://neo4j:7687 |
NEO4J_USER |
Database username. | neo4j |
NEO4J_PASSWORD |
Database password. | password |
LLM_MODEL_NAME |
Model to use for generation. | gemini-1.5-pro |
Navigate to http://localhost:3000, and you would see the start screen.

- Click "Start Adventure".
- Type actions like "I look around" or "I attack the goblin".
- View your Inventory and Stats updating in real-time.
You can interact directly with the backend via HTTP.
Start a Session:
curl -X POST "http://localhost:8000/api/play/start_session" \
-H "Content-Type: application/json" \
-d '{}'Take an Action:
curl -X POST "http://localhost:8000/api/play/step" \
-H "Content-Type: application/json" \
-d '{
"session_id": "YOUR_SESSION_ID",
"text": "I attack the goblin with my sword!"
}'We provide scripts to verify the core mechanics of the system, specifically the Combat Flow.
This experiment tests the end-to-end flow of:
- Initializing a session.
- Retrieving the current state.
- Processing a combat action ("I attack...").
- Verifying that the
action_log(combat resolution) is generated.
Run the Experiment:
Ensure the stack is running (./start.sh), then run:
python scripts/test_combat_flow.pyTo run the backend unit tests (ensuring API health and basic game flow):
python -m pytest tests/We have conducted a comparative analysis between A.R.C.A.N.A. and a baseline LLM (Gemini 1.5 Pro). The results, including score distributions and qualitative analysis, can be found in:
Key Findings:
- Performance: A.R.C.A.N.A. achieved a mean score of 4.62/5.0, significantly outperforming the baseline (3.90/5.0).
- Consistency: The agentic architecture demonstrated much lower variance in output quality.
Expected Output:
1. Starting Session...
Session ID: ...
2. Sending Attack Command...
Response received.
[SUCCESS] Action Log Found:
[
{
"type": "attack",
"description": "...",
"damage": ...
}
]
- OrchestratorAgent: Manages the game loop, detects user intent, and delegates tasks.
- NarrativeAgent: Generates immersive story text using Google Gemini.
- RulesLawyerAgent: Adjudicates actions based on D&D 5e rules.
- Memory System:
- Episodic: Vector Store (Chroma) for narrative history.
- Semantic: Temporal Knowledge Graph (Neo4j) for game state (HP, Inventory, Locations).
Visualize the game world and memory in the Neo4j Browser.
- Go to http://localhost:7474
- Login with
neo4j/password. - Run this query to see the entire graph:
MATCH (n) RETURN n
For a comprehensive guide on common issues (API keys, database connections, logging), please refer to TROUBLESHOOTING.md.
| Issue | Solution |
|---|---|
| API Key Error | Check .env file and ensure GOOGLE_API_KEY is set. |
| Database Empty | Run the seed command: docker-compose exec backend python -m app.scripts.seed |
| Connection Refused | Ensure Docker containers are running: docker-compose ps |
