← Back to Blog

Building an AI Game Master from Scratch

Lorenzo Lorenzo · · 3 min read
Building an AI Game Master from Scratch

Building Embertold's AI Game Master was the hardest and most rewarding technical challenge we've faced. Here's what we learned.

The Vision

We wanted to build something that feels like playing with a skilled human dungeon master — someone who knows the rules, knows the world, reacts to your choices, and tells a compelling story. Not a chatbot with a fantasy skin. A real Game Master.

The Core Challenge

A good Game Master does many things simultaneously:

  • Narrates the scene
  • Voices NPCs with distinct personalities
  • Tracks player inventory and health
  • Manages the pacing of the story
  • Generates appropriate challenges
  • Maintains world consistency
  • Creates atmosphere
  • Responds to unexpected player actions

Asking a single AI prompt to do all of this is a recipe for mediocrity. It does everything, but nothing well.

The Agent Approach

Instead of one monolithic prompt, we built the Game Master as an AI agent with specialized tools. The agent decides what needs to happen, then calls the appropriate tool:

  • Need to describe a scene? Use the narration tool.
  • NPC is speaking? Use the dialogue tool with voice generation.
  • Player found an item? Use the inventory tool.
  • Entering a new area? Use the scene image tool and ambient sound tool.
  • Need lore context? Query the knowledge base.

Each tool is focused and optimized for its specific task. The agent orchestrates them based on the game state and the player's actions.

The Narration Problem

Early versions had a common flaw: the AI would try to narrate everything in one massive text block. Walk into a room and you'd get three paragraphs of description, followed by NPC dialogue, followed by a combat encounter, all in one response.

Real dungeon masters don't do this. They set the scene, pause, let the player react, then continue.

We solved this by making the agent deliberate about pacing. It sends narration in pieces, interspersed with NPC dialogue, sound effects, and images. The result feels like a conversation, not a wall of text.

The Consistency Problem

AI models don't naturally track state. They don't remember that you picked up a key three chapters ago, or that the NPC you're talking to has a grudge from an earlier encounter.

We built systems to manage this:

  • Inventory tracking — A structured system that the AI updates through explicit tool calls
  • Health management — Hit points tracked and modified through the health tool
  • Chapter summaries — When chapters end, detailed summaries preserve key events for future context
  • NPC registration — Characters are formally registered with persistent traits and voice assignments

The AI doesn't have to "remember" — the system remembers for it and feeds relevant context on every turn.

What We Got Right

  • Specialized tools over monolithic prompts
  • Structured state management over relying on AI memory
  • Paced narration over text dumps
  • Lore grounding over unconstrained generation

What Surprised Us

The biggest surprise was how much personality emerges from constraints. By giving the AI clear rules about pacing, tool usage, and lore consistency, the stories became more creative, not less. Constraints breed creativity — even for AI.

Building a Game Master is never done. Every session teaches us something. But the foundation is solid, and the stories keep getting better.

Related Posts