<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jean Schmitz</title>
    <description>The latest articles on DEV Community by Jean Schmitz (@jschm42).</description>
    <link>https://dev.to/jschm42</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3927947%2F15d4ce5f-dcbf-4f05-b656-4cb71e39c97b.jpeg</url>
      <title>DEV Community: Jean Schmitz</title>
      <link>https://dev.to/jschm42</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jschm42"/>
    <language>en</language>
    <item>
      <title>How I built a self-hosted AI Gamemaster that actually enforces RPG rules (FastAPI &amp; Vue)</title>
      <dc:creator>Jean Schmitz</dc:creator>
      <pubDate>Tue, 12 May 2026 20:53:47 +0000</pubDate>
      <link>https://dev.to/jschm42/how-i-built-a-self-hosted-ai-gamemaster-that-actually-enforces-rpg-rules-fastapi-vue-45nm</link>
      <guid>https://dev.to/jschm42/how-i-built-a-self-hosted-ai-gamemaster-that-actually-enforces-rpg-rules-fastapi-vue-45nm</guid>
      <description>&lt;p&gt;Have you ever wondered if an LLM could actually make a capable Gamemaster? If you have ever tried to play or build a text adventure with a standard AI model, you know the architectural frustration. The AI acts like a hyperactive improv partner. If you type 'I jump over the moon and slay the dragon with a spoon', the model simply hallucinates: 'Yes, you do that.' There is no state management, no constraints, and zero real game mechanics. But what if you combined a deterministic, rule-based RPG engine with an omniscient generative AI Gamemaster?&lt;/p&gt;

&lt;p&gt;I wanted a genuine RPG experience with a strict Gamemaster, so I built &lt;strong&gt;TaleWeaver&lt;/strong&gt;. It is an open-source, self-hosted RPG engine that generates dynamic worlds on the fly. &lt;/p&gt;

&lt;p&gt;Here is how I solved the "LLM Amnesia" and enforced strict game mechanics using a &lt;strong&gt;2-Pass Architecture&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem: Mixing Mechanics and Narrative
&lt;/h2&gt;

&lt;p&gt;LLMs are fantastic at writing atmospheric prose, but they are terrible at tracking state, hitpoints, and inventory items. If you force a single prompt to manage complex math and write a cinematic story simultaneously, the model will hallucinate.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution: The 2-Pass Engine
&lt;/h2&gt;

&lt;p&gt;I split the workload into two distinct processes to keep the game state intact:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Pass 1: The Rule Engine
&lt;/h3&gt;

&lt;p&gt;When a user submits an action, a fast, highly logical model evaluates the input against the current game state. It performs hidden D20 stat rolls, checks the inventory, and calculates damage. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Output&lt;/strong&gt;: A strict JSON &lt;code&gt;GameEvent&lt;/code&gt; that mutates the database (e.g., updating HP, moving an NPC to a new scene, or adding loot).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Pass 2: The Gamemaster
&lt;/h3&gt;

&lt;p&gt;Once the database state is safely updated, a creative narrative model takes the raw JSON outcome and translates it into an immersive, atmospheric response.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Tech Stack
&lt;/h2&gt;

&lt;p&gt;I built this engine to be completely self-hosted and robust:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Backend&lt;/strong&gt;: Python and FastAPI. The database is SQLite, fully tenant-ready with UUID-based primary keys.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Frontend&lt;/strong&gt;: Vue.js for a snappy, app-like experience.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Dynamic Cartography&lt;/strong&gt;: The engine automatically renders a live directed graph map of the discovered scenes using &lt;strong&gt;Rough.js&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;TTS Audio&lt;/strong&gt;: Integrated &lt;strong&gt;Gemini 3.1 Flash TTS&lt;/strong&gt; and &lt;strong&gt;ElevenLabs&lt;/strong&gt;. The engine parses director notes to build dramatic tension directly into the audio output.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bring Your Own Key (BYOK) &amp;amp; Local Execution
&lt;/h2&gt;

&lt;p&gt;The entire stack is containerized with Docker for a frictionless 1-click setup. It uses the &lt;strong&gt;LiteLLM&lt;/strong&gt; adapter under the hood. You simply plug in your API key for top-tier models, which are highly recommended to handle the complex JSON reasoning.&lt;/p&gt;

&lt;p&gt;I also added experimental support for local &lt;strong&gt;Ollama&lt;/strong&gt; execution. It is tough to get smaller local models to consistently output complex nested JSON, but it is a fun challenge to push the boundaries of offline play.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check out the code
&lt;/h2&gt;

&lt;p&gt;You can find the repository, the complete JSON manifest specifications, and the setup scripts here:&lt;br&gt;
&lt;a href="https://github.com/jschm42/taleweaver" rel="noopener noreferrer"&gt;https://github.com/jschm42/taleweaver&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>gamedev</category>
      <category>python</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
