How We Keep AI Dungeon Master Stories Coherent Across Dozens of Chapters

AI language models have a fundamental limitation (see how we built the Game Master for the broader architecture): they can only take in a fixed amount of text at once, the context window. For a game that can span hours of gameplay across dozens of chapters, this creates a real challenge.
The Problem
Imagine playing an adventure for three hours. You've made hundreds of choices, met dozens of NPCs, visited multiple locations, gained and lost items, and shaped the political landscape of a fantasy city. The full transcript of your adventure might be tens of thousands of words.
If we fed all of that to the model on every turn, it would either exceed the context window and fail, lose track of important details buried in the middle, or become prohibitively expensive to run, since more tokens means more cost on every single turn.
The Chapter Solution
Embertold breaks adventures into chapters. When a chapter completes, a summarization pass generates a detailed summary that captures:
- Key events — what happened, in what order
- Decisions made — what the player chose and why it mattered
- State changes — items gained/lost, health changes, NPC relationships
- Narrative threads — ongoing plotlines, unresolved questions, foreshadowing
These summaries are written to preserve the information that matters for future storytelling while being much more compact than the full transcript.
Chapter boundaries also serve as character checkpoints: the system snapshots health, inventory, currency, and status effects at the start of each chapter. Adventures configured with checkpoint death behavior can restore this snapshot on death, or the player can trigger a voluntary restart from the same checkpoint, letting them retry from the chapter start instead of losing everything.
How Context Is Built
On each turn, the model receives:
- Chapter summaries — condensed versions of all previous chapters
- Current chapter messages — the full transcript of the current chapter
- Character state — current stats, effective stats after equipment and status effects, inventory, health
- Adventure context — the premise, objectives, and key NPCs
This gives the model both the big picture (summaries) and the immediate detail (current chapter), the same way a human dungeon master remembers the broad strokes of past sessions while being fully present in the current one. It's assembled fresh from Postgres on every turn, not carried forward as conversation state.
What Gets Preserved
The summary system is designed to never lose information that could matter later: a seemingly minor NPC mentioned in chapter 2 who might return in chapter 15, a decision that seemed small but has cascading consequences, items picked up and not yet used, promises made to NPCs, overarching quest objectives and sub-goals.
Automatic Chapter Titles
Each chapter gets an AI-generated title when it completes. These titles serve as bookmarks in your adventure history, making it easy to find specific moments: "The Betrayal at Moonstone Bridge," "A Dark Bargain," "Into the Deep."
The Balance
There's a tension between compression and fidelity. Too much compression and the model forgets important details. Too little and you burn through context on backstory instead of current gameplay.
We've tuned this balance through testing. The summaries are detailed enough to maintain narrative threads but compact enough to leave plenty of room for the current chapter's interaction.
The Result
Players can run adventures that span dozens of chapters and hours of gameplay without the model "forgetting" what happened. The story stays coherent. NPCs remember their relationships with you. Your inventory stays consistent. Consequences from early choices ripple through late-game events.
It's not perfect, no compression is lossless. But it's good enough that most players never notice the machinery behind the curtain. They just experience a long, coherent, personalized story, whether they're exploring Waterdeep or delving into the Underdark.
And that's the point.
Related Posts

Designing a Fair Credit System for AI-Generated Content
How we built a monetization model that keeps core gameplay free while funding the AI features that make Embertold special, and the engineering decisions behind it.

How Does an AI Dungeon Master Work? Inside Embertold's Agent Architecture
The journey of building an AI that runs tabletop RPG sessions: the tool-calling agent architecture, the statelessness constraint, and the design philosophy behind Embertold's Game Master.

Every Tool in Embertold's AI Game Master Toolbox, Explained
The AI Game Master has a full toolkit of specialized, typed functions at its disposal. Here's what each one does and how they get orchestrated turn to turn.