Case study · Project 02
AI Dungeon Master
A choose-your-own-adventure where the dungeon master is a pipeline, not a free-form chatbot. Structured world state, validated turn deltas, streaming narrative, and a latency inspector for local models.
Problem
Most LLM roleplay demos are chat with flavor text. Over a long session they forget who rules the city, which door was locked, or whether the player is a disgraced knight. Free-form generation optimizes for the next paragraph, not for a coherent campaign. Players (and interviewers) can feel the drift immediately.
The goal was a system that still feels creative, but treats the world as data: factions, locations, NPCs, flags, and constraints that update in a controlled way every turn.
Approach
- World generation as structured state — build NPCs, locations, and constraints into a store, not a single system prompt dump.
- Turn contract — each turn returns narrative, exactly four choices, and a StateDelta that is validated before apply.
- Context assembly — lore, scene, flags, events, and a running summary; when the token budget tightens, older turns fold into that summary so long campaigns stay coherent.
- Model choice at setup — cloud Claude or local Ollama so demos work with or without an API key.
- SSE progress — the UI streams generation so players watch the realm write itself instead of staring at a spinner.
- Latency inspector — break down world gen, narrative stream, and choices+delta timings for local-model honesty.
Why this design
Validated deltas beat pure chat when consistency across long sessions matters. The product story is inspectability: you can reason about what the model changed, not only what it wrote. That matches a systems-first view of AI—architecture and state before “make it funnier.”
Stack
Frontend: React 19, TypeScript, Vite, Tailwind, Zustand, React Flow.
Backend: Python, FastAPI, SQLAlchemy, Pydantic, Alembic, SQLite, SSE.
Models: Anthropic Claude and/or local Ollama.
Role on the build
Product and systems direction: pipeline shape, state model, human-facing loop (setup → turn → inspect). Implementation steered heavily with AI coding agents; ML literacy informed model routing and latency expectations for local vs cloud. Graphic direction for the dark / gold “chronicle” feel.