
You tell the Dungeon Master what your hero does, in your own words. The AI tells the story. The dice and the D&D rules stay fair, because code decides them, not the model.
The problem: Language models are good storytellers but bad referees. Ask a chatbot to run a D&D game and it forgets your inventory, lets you win every fight, and gives you the legendary sword if you insist.
The solution: AI Dungeon Master splits the job. Each turn runs through a LangGraph pipeline:
Safety check: a judge model classifies the input. Harmful content, cheating and prompt-injection attempts get an in-character reply, not a lecture.
Plan: the model turns your message into an ordered queue of actions (“take the key, put on the chain mail, go down the stairs”). Through tool calling, it can only pick from the actions the engine offers.
Execute: a deterministic rules engine based on the D&D 5e SRD rolls the dice and applies checks, saves, items, conditions and rests. The game can pause for a roll you make yourself.
Narrate: the DM streams the result as story, and a narrator voice reads it aloud.
The model selects the action. The engine decides the outcome.
What you can do:
Create a character in a short chat. Describe an idea (“shy, strong, small, clever”). The agent asks one or two questions, the engine checks the sheet, and an image model paints the portrait.
Play persistent campaigns. Two ship with the game: The Silent Bell and Greenhollow. The DM searches its own past narration by meaning, so NPCs and clues come back sessions later.
Ask the rules guide. It answers from the SRD with citations and marks house rules as house rules.
Multi Language Support.
Look Behind the Screen (admin). For every turn you see the safety verdict, the plan, the tool calls, the memory hits, the secret rolls, the tokens and the cost.
Under the hood: Prompts are versioned Markdown files, published to Langfuse prompt management. Langfuse traces every model call, with the exact cost from OpenRouter. The planner context puts static content first, so the prompt cache can reuse it. More than 90 backend and frontend test files run without model calls. A separate live test set sends adversarial inputs to the real safety judge.
Tech stack: Python 3.12 · FastAPI · LangGraph · LangChain · PostgreSQL + pgvector · OpenRouter · Langfuse · React 19 · TypeScript · MUI · three.js · Docker
Honest scope: The game is in beta and single-player. Not all D&D mechanics are implemented yet. To keep model costs under control, usage is limited.