3
6 Comments

How I forced LLMs into a deterministic state-machine (without API wrappers)

If you’ve ever tried to build a game or a structured interactive experience using standard LLMs, you already know the core problem: Generative models are sycophants.

They are hardwired to prioritize user satisfaction over mechanical integrity. They will fudge math, refuse to let a user fail, and endlessly hallucinate inventory items to keep the conversation moving. I wanted to build a lethal, rules-heavy dark fantasy RPG engine, and the default conversational drift made it impossible.

Instead of building a heavy API wrapper to manage the state externally, I engineered Grinmar—a prompt-based architecture that forces the model to act as a rigid, impartial state-machine.

Here is the exact logic I used to kill the sycophancy:

1. The 3-Tier Action Gate

LLMs drift when you let them generate narrative and calculate outcomes simultaneously. I forced a hard sequence break. Before the model is allowed to generate a single word of prose, it must output a bracketed [SYSTEM CALC] execution block at the top of the generation. It calculates the target threshold against the player's stats and locks in the outcome (Pass/Fail/Fatal) before the narrative tokens start streaming.

2. The S.I.I.N.S. Attrition Engine

Abstract hit points encourage LLMs to be forgiving. I stripped them out and built a strict 5-tier degradation track for Vitality and Stamina. The model cross-references standard attributes (Strength, Intuition, Intellect, Nimbleness, Social) against this track. If a player hits Tier-05 (Terminal Collapse), the logic gate forces immediate execution. Plot armor is disabled.

3. The Zero-Hallucination HUD

To stop context drift and inventory hallucination, the engine enforces a strict 5-slot persistent HUD at the end of every prompt. Consumed resources are immediately and permanently overwritten with an [Empty] marker. If it isn't in the ledger, the model is strictly forbidden from letting the player use it.

By forcing the math to lead the narrative, you can turn a conversational AI into a lethal Game Master.

I’ve compiled the core logic gates, the Monolith ruleset, and the survival dossier into a deployable package.

You can check out the live architecture deployment here:

https://graywolfone21.itch.io/grinmar

If anyone is working on taming LLM context drift or building similar procedural logic gates, I’d love to hear how you are handling state management.

posted toAvatar for product Grinmar
Grinmar
  1. 2
    How well does this hold up as state and context grow?
    1. 1
      It is definitely still a proof of concept and a work in progress, but it holds up surprisingly well. The trick is that the state doesn't actually 'grow' indefinitely. Because the engine enforces a strict 5-slot HUD that overwrites consumed resources with an [Empty] marker, state bloat is hard-capped. As for the conversational context expanding over time, forcing the [SYSTEM CALC] execution block at the very top of the generation keeps the model anchored to the math before it can get lost in the prose. I’ve been running my current build inside Grok for multi-day play sessions, and the logic hasn't broken yet. It proves the concept works, even if I'm still refining the edges
      1. 2
        The hard cap on state makes the multi-day result more meaningful. The remaining question for me is whether the [SYSTEM CALC] anchor still holds once the conversational context gets substantially more complex, rather than just longer.
        1. 1
          That is the exact right stress point to isolate. Length alone is easy to manage because linear text can be truncated or summarized by the state block. The friction actually hits when context density scales—when you have compounding variable states, intersecting character motivations, and multi-layered conditional logic running concurrently. The [SYSTEM CALC] anchor survives this because it forces a mathematical evaluation of the state ledger before the model is allowed to generate narrative prose. By evaluating hard rules and numeric thresholds first, it prevents narrative drift from polluting the state variables, even when the active lore complexifies. It treats complexity the same way it treats length: as a strict mathematical boundary rather than an open-ended narrative choice
          1. 2
            The complexity boundary is the interesting part. Have you found a point where the concurrent state/logic starts causing failures, or has it held up across those cases so far?
            1. 1
              As far as the parameters go I have not found a point at which it breaks the logic. I do keep expecting it to, but Grinmar is complex and lengthy at the same time, while performing multiple calculations. I do absolutely intend to update everyone if I find its breaking point.