
An open-source engine that turns AI into a real Game Master - with deterministic dice, persistent NPCs, and full campaign tracking.
"You push open the iron door. The hinges scream. Inside, the throne room stretches wide - cracked marble, toppled pillars, and at the far end, an ogre chieftain sitting on a chair made of shields. He looks up. He doesn't seem surprised."
You: I draw my sword and step forward.
The GM calls
encounter_start, rolls initiative, places you in the Entrance zone and the ogre in the Throne Room. Combat begins.
That's not a scripted demo. It's a real session - an AI running a tabletop RPG campaign through a terminal, using the same kind of tools a human GM would: dice, character sheets, initiative trackers, story notes. Except these tools are MCP endpoints, and the GM is Claude.
I built LoreKit to make this work.
LoreKit is an open-source TTRPG game engine designed for AI agents. It tracks everything needed to run full campaigns: characters, sessions, story arcs, regions, combat encounters, NPC memories, and more.
The AI doesn't wing it. It connects to an MCP server and uses tools the way a human GM would use a VTT - rolling dice, starting encounters, tracking story arcs. Most of the heavy lifting is abstracted. Resolving an attack is a single tool call that handles the roll, damage, conditions, and state updates. An NPC interaction call assembles context, spawns the NPC agent, and stores new memories. The GM calls the shots. The tools handle the complexity.
The key design decision: the AI handles narrative, but a deterministic engine handles all the math. The GM never picks numbers. It never "decides" damage. It calls the rules engine, gets results, and narrates what happened. If something goes wrong - a failed tool call, an unexpected result - the GM stops, tells the player what happened, and waits. No silent fixes. No narrative smoothing.
<!-- IMAGE: Screenshot of TUI showing a combat exchange with dice results visible -->When you send a message, the AI Game Master:
What it does NOT do:
You play through a terminal TUI built with React and Ink. It starts the engine, spawns the GM, and streams the session as text.
<!-- IMAGE: GIF of TUI gameplay showing a full exchange - player input, GM narration, tool calls, dice results -->The flow is simple: you type what your character does, the GM responds. Behind the scenes, tool calls fire, the database updates, and the narrative reflects what actually happened mechanically.
<!-- IMAGE: Screenshot showing the HUD - character status, HP, conditions -->LoreKit ships as two Python packages:
cruncher - a standalone, zero-dependency rules engine. It parses formulas, stacks modifiers, rolls dice, builds characters, and computes derived stats. Pure computation: dataclasses in, dataclasses out. No database, no network, no AI.
lorekit - the full MCP game engine. Session management, combat orchestration, NPC agents, narrative tracking, semantic search. It depends on cruncher for all mechanical resolution.
This separation matters. The AI never touches the math. It calls tools, and those tools call cruncher, and cruncher returns deterministic results. The AI's job is to make those results feel like a story.
LoreKit ships with two game systems:
| System | License |
|---|---|
| Pathfinder 2e Remaster | ORC |
| d20 Hero SRD (3e) | OGL 1.0a |
Both are defined entirely in JSON - attributes, formulas, actions, tables, build rules, stacking policies. The engine doesn't know what Pathfinder is. It knows variables, formulas, and constraints. You could define your own system from scratch.
Combat currently uses zone-based positioning inspired by theater of the mind - no grid yet. Grid combat, a Discord bot, premade adventures, and support for other AI agents (Codex, Gemini CLI) are on the roadmap.
Head over to the repo - the README has setup instructions. Once you're running, make tui starts the terminal interface. The GM agent sets up the session and asks what kind of adventure you want.
This is Part 1 of a 4-part series. Next week, I'll dig into how the deterministic engine works - how a formula like floor(level / 2) + dex_mod gets parsed, evaluated, and fed back to the AI so it never has to guess what your attack bonus is.
If you try it, drop a comment - I'd love to hear how your session went.
LoreKit is Apache 2.0 licensed. System pack data (Pathfinder 2e, d20 Hero) is governed by its own license (ORC, OGL 1.0a) found in each system's directory.
aiMost of us have seen a coding agent fail to complete a task we know it can do. We just don't...
googlecloudWhen building Generative AI applications, developers often encounter a massive bottleneck: sequential...
discussI’ve been thinking about sharing some electronic circuit posts on Dev.to — small circuits, DIY...
agentsWhat nobody tells you about exporting your multi-agent prototype to a local workspace. Every...
agenticarchitectAutonomous agents are genuinely good at answering messy business questions. Give one an LLM and a set...
aiPR volume went up, ticket quality didn't, and the gap got filled with LLMs on both sides of the review: bots reviewing, bots replying, bots occasionally arguing with bots about priorities that only existed in a teammate's head. Our CEO named the actual problem, and it's bigger than code review.
Workflows from the Neura Market marketplace related to this Stable Diffusion resource