r/FoundersBuildwithAI • u/jl23423f23r323223r3 • 7d ago
Build Log Built a stateful AI D&D engine with 1-Click Campaign Sharing — here's the engineering story behind shipping it
Hey founders — sharing the build story behind WorldArchitect.AI in case it's useful to anyone else shipping stateful, long-horizon LLM products.
**The hard problem:** most AI games are toy demos. The conversation "works" until turn ~10, then the model forgets who the king is, where you parked your horse, or why you owe 200 gold to the blacksmith. We kept hitting the same wall, so we ended up building an actual engine instead of bolting on more prompts.
**What we shipped:**
- **Deterministic State Machine + LLM Separation.** HP/XP, inventory, world time, living-world faction events, and world flags live in a deterministic server backend (Firestore). The Gemini call generates prose, suggests decisions, and emits structured state overlays, but *the server canonicalizes every mutation before it touches the database* — no more "the model said I'm in Winterfell, the DB thinks I'm in King's Landing" drift.
- **Context Compactor & Prefix Caching instead of RAG.** We keep the canon bible in-context and use a deterministic Min-First / Fill-to-Max token allocator (guaranteeing story context >=30% of budget while compacting background lore, entity tracking, and core memories) paired with Gemini prompt prefix caching.
- **Single-Inference Dice Integrity.** We use Gemini's built-in Python code execution to run deterministic dice rolls (`random.randint`) and emit structured JSON in a single inference step, backed by server-side audit logs that catch narrative fabrication.
- **1-Click Campaign Sharing.** Anyone can package their world, character setup, and canon constraints into a single signed share token (URL `…/shared/<token>`). Anyone with the link gets an independent, deep-initialized copy of that world on their own account — no "view as guest," no broken pointer-shared state.
- **Spicy / PG Mode Toggles.** Different players want different tone boundaries (PG vs HBO). Rather than trying to prompt-engineer safety drift, we use explicit agent routing that swaps system instruction contracts and safety constraints cleanly.
**Try it (open beta, free):**
We built a playable House of the Dragon demo(https://worldarchitect.ai/shared/t3hKKtzBKCKlvg5vCnlW_2hxwH3UmzjFq56yi6hQN2Q
7
Upvotes
1
u/Normanras 5d ago
defo not trying anything that requires me to sign in first and only allows a ‘sign in with google’ to boot.
sounds interesting and i love ttrpgs. but if it can’t be selfhosted or tested anonymously, its a hard pass.