"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.
What is LoreKit
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.
What the GM Actually Does
When you send a message, the AI Game Master:
- Narrates the world, NPCs, and consequences of your actions
- Calls tools to roll dice, resolve attacks, apply damage, track conditions
- Manages story - sets up adventures, tracks acts and regions, logs timeline events
- Spawns NPCs as independent agents with their own personality, memory, and goals
- Enforces rules via the cruncher engine - a standalone, zero-dependency rules calculator
What it does NOT do:
- Pick numbers. Every stat, bonus, and roll comes from the engine
- Control your character. You decide what your PC does
- Hallucinate rules. All mechanics come from system pack definitions (JSON files)
What It Looks Like
You play through a terminal TUI built with React and Ink. It starts the engine, spawns the GM, and streams the session as text.
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.
Two Packages, One Engine
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.
Game Systems Are Data, Not Code
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.
Try It Tonight
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.
What's Coming Next
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.
Top comments (0)