AI systems · 2025
PrivateDynamic Story
An AI narrator that runs a persistent world and can say no.
Overview
An interactive narrative engine where the player is the main character of a generated book. An AI game master narrates a world that persists in a database — locations, characters, goals — and characters remember what happened. Built early, when getting structured JSON back from a model reliably was still the hard part.
The hard part
Letting the model mutate the world without letting it corrupt it
A narrator that can only produce prose is a toy. This one emits a typed mutation array alongside its narration — changes to characters, to the player, to sub-goals, to the chapter — which the server validates and applies. That turns storytelling into a state machine the database can hold. Travel is adjudicated rather than assumed: the narrator can deny a move in-fiction, because you are still fighting the dragon. Locations form a three-level hierarchy with a connection graph carrying travel descriptions, so the world is navigable rather than a list of scenes. It is a multi-agent pipeline in practice — a quest-designer model, a narrator model and a chat model, each with a different job.
What it does
- Typed mutation array emitted by the narrator and validated server-side before it touches state
- Area connection graph with travel descriptions, plus a pannable and zoomable map
- Character memories persisted so NPCs reference what actually happened
- Goals and sub-goals as the story spine, with a checklist the player can also ignore
- Zod schemas as the contract between model output and the database
What it proves
- Working with LLMs as unreliable components inside a system with invariants
- Multi-agent decomposition before it was a common pattern
- Schema-first thinking applied to non-deterministic output
Stack
- Next.js
- TypeScript
- OpenAI API
- Zod
- Drizzle
- PostgreSQL
- next-auth
- Jotai
Related