How to Control LLM in a Role-Playing Game: Beyond The Verge Architecture
Beyond The Verge tamed LLM problems in RPGs: model drift, amnesia, and rule violations. The solution is radical: an authoritarian FastAPI backend with PostgreSQL manages inventory, map, and state, while the LLM only describes events. Game mechanics are deterministic and the game scales. The approach removes LLM control over game mechanics. The model only receives a snapshot of game state in text form and generates descriptions. Player actions are parsed, validated, and processed by backend logic before the LLM describes the consequences.
AI-processed from Habr AI; edited by Hamidun News
Beyond The Verge — a fully Russian-language text RPG based on LLM — faced a classic problem: models forget context, violate game rules, and add items out of thin air. After 30 turns, the game turns into incoherent chat. Developers chose not to try to 'tame' the model, but to remove its control over mechanics.
Why LLM Isn't Suitable for Mechanics
LLM is generative by nature, while RPG requires determinism. The model only remembers window context, cannot distinguish its imagination from game state, and can spontaneously change the plot or violate logic. If allowed to manage inventory, it will easily lose a sword, forget constraints, or add an item the player didn't take.
Architecture: LLM as Narrator Only
Beyond The Verge divided responsibilities. All game mechanics are deterministic logic on the backend:
- Inventory — a row in PostgreSQL with item IDs, weight, and properties
- Map — a graph of vertices (locations) and edges (transitions between them)
- Character state — a vector in pgvector for fast context search
- Combat system — damage, defense, and crit formulas — all calculated
- Quests — finite state machines with fixed states
The LLM receives a snapshot of the game state in text form and generates only description: "You entered a dark forest. You hear bird sounds. In inventory: dagger, mana potion (30%). Ahead is a goblin, weak."
The player's action is parsed, validated by backend logic (can the character do this?), the result is calculated, then the LLM describes the consequences.
FastAPI + PostgreSQL + pgvector
The stack is simple but effective: FastAPI processes the player's turn, PostgreSQL stores state (inventory, NPCs, quests), pgvector finds relevant context for the LLM (character memories, location atmosphere), and Flutter Web serves as the interface.
When the player moves, the backend updates the position in the map graph, finds the best descriptions in pgvector, and collects visible objects. The LLM receives compact context and generates text in under 1 second. There is no struggle with model memory, no amnesia.
Scalability through Versioning
With 1000 simultaneous game sessions, state can conflict: two moves at the same time — who wins? Solution: optimistic locking with state versioning. Each state has a version number; if a conflict is detected during a move, the client resynchronizes and the move is replayed. Race conditions are excluded, and the system scales linearly.
What This Means
LLM is a text generation tool, not a control mechanism. For reliable systems, logic, state, and mechanics should live in code, not in the model. LLM translates events into vivid description. This is a pattern for all AI systems with deterministic state: browser agents, complex simulations, games. Separating the controllable from the generative is the path to reliability and scalability.
- Oct 28, 2026SLICE-Mem: LLM agent memory without generation cuts token use by 92–99%
- Oct 26, 2026Getty Images prepares to file for bankruptcy: shares plunge 68% as owners put in $533 million
- Oct 23, 2026Stanford and Together AI Teach LLMs to Write Text Starting From an Outline: Generation Up to 31x Faster
- Oct 22, 2026StopLoss Cuts Off Doomed Coding-Agent Runs and Saves Up to 48% of Costs
Key Questions Answered
Why LLM Isn't Suitable for Mechanics?
LLM is generative by nature, while RPG requires determinism. The model only remembers window context, cannot distinguish its imagination from game state, and can spontaneously change the plot or violate logic. If allowed to manage inventory, it will easily lose a sword, forget constraints, or add an item the player didn't take.
What are the key details on Architecture: LLM as Narrator Only?
Beyond The Verge divided responsibilities. All game mechanics are deterministic logic on the backend: Inventory — a row in PostgreSQL with item IDs, weight, and properties Map — a graph of vertices (locations) and edges (transitions between them) Character state — a vector in pgvector for fast context search Combat system — damage, defense, and crit formulas — all calculated Quests — finite state machines with fixed states The LLM receives a snapshot of the game state in text form and generates only description: "You entered a dark forest. You hear bird sounds. In inventory
What are the key details on FastAPI + PostgreSQL + pgvector?
The stack is simple but effective: FastAPI processes the player's turn, PostgreSQL stores state (inventory, NPCs, quests), pgvector finds relevant context for the LLM (character memories, location atmosphere), and Flutter Web serves as the interface. When the player moves, the backend updates the position in the map graph, finds the best descriptions in pgvector, and collects visible objects. The LLM receives compact context and generates text in under 1 second. There is no struggle with model memory, no amnesia.
Test Frontier LLMs & Autonomous Agents in One Workspace
Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.
The AI world, distilled — once a week
Seven stories that actually mattered, hand-picked. No noise, no reposts, no press releases.
Done! Check your inbox for a confirmation.