Agentic Rules-based & Creative Autonomous Narrative Architecture
This document provides a detailed guide on how to set up, understand, and develop the A.R.C.A.N.A. project. It is intended for teammates joining the project.
- Docker Desktop: Must be installed and running.
- Google Gemini API Key: Required for the LLM agents.
-
Clone the repository.
-
Generate Environment Config: Run the start script once to generate the
.envfile.chmod +x start.sh ./start.sh
Note: The script will likely pause/fail initially because the API key is missing.
-
Configure API Key: Open
.envin the root directoryDndAgent/and add your key:GOOGLE_API_KEY=your_actual_api_key_here
Start the full stack (Frontend, Backend, Database):
./start.sh- Frontend: http://localhost:3000
- Backend API: http://localhost:8000/docs
- Neo4j Browser: http://localhost:7474 (User:
neo4j, Pass:password)
Critical Step: The database starts empty. You must seed it with initial locations, NPCs, and items. Run this command in a new terminal window while the app is running:
docker-compose exec backend python -m app.scripts.seedThe system is designed as an agentic loop where a central Orchestrator manages the flow of information between the user, the narrative LLM, and the game state (Neo4j).
Built with FastAPI and Python.
app/main.py: The entry point for the API.app/agents/orchestrator.py: The core brain. It manages the game loop, detects user intent, and coordinates other agents.app/agents/narrative_agent.py: Wraps the LLM to generate story text.app/agents/world_builder_agent.py: Interface for modifying the world state.app/memory/semantic_tkg.py: The "Temporal Knowledge Graph" (TKG). It interacts directly with Neo4j to store RPG stats (Health, Gold), Inventory, and Relationships.app/api/routes_play.py: API endpoints used by the frontend.
Built with Next.js, TypeScript, and Tailwind CSS.
app/play/page.tsx: The main game interface. Handles:- Starting a session.
- Sending user actions.
- Displaying the narrative feed.
- Updating the Stats and Inventory panels.
components/StatsPanel.tsx: Visualizes player health, gold, and stats.components/InventoryPanel.tsx: Displays items and handles Buy/Sell/Equip interactions.
- User Input: The user types an action (e.g., "I attack the goblin" or "Buy the sword") in the frontend.
- API Call: Frontend sends this to
POST /api/play/step. - Context Retrieval:
Orchestratorfetches current RPG state (Health, Gold, Inventory) fromsemantic_tkg.py(Neo4j).- It also retrieves relevant past memories or world info.
- Intent Detection (Key Feature):
- The
Orchestratorasks Gemini: "Given the user input and current state, which tool should I use?" - Tools:
attack,buy_item,sell_item(defined indnd_tools).
- The
- Execution:
- If Tool: The specific Python function is executed (e.g., deducting gold and adding item to inventory in Neo4j).
- If Narrative: The Rule/Narrative agents determine the outcome based on game logic.
- Response:
- The
Orchestratorbundles the New Scene Description, Action Log (combat results), and Updated Player Stats. - Frontend updates the UI instantly.
- The
- View Backend Logs:
docker-compose logs -f backend
- View Frontend Logs:
docker-compose logs -f frontend
- Rebuild Containers (after changing
requirements.txtorpackage.json):docker-compose up --build
- Backend:
- Define the new capability in
semantic_tkg.py(e.g.,cast_spell). - Add a tool definition for the LLM in
app/agents/tools.py(if applicable). - Handle the tool execution in
Orchestrator.process_turn.
- Define the new capability in
- Frontend:
- Update
StatsPanelor create a new component if you are displaying new data. - Ensure
PlayPagefetches user stats correctly viafetchRPGState.
- Update