How the InkOS book generator keeps context on track across hundreds of chapters
Anyone who has tried to write long fiction using language models knows the moment when everything starts falling apart. By the third or fourth chapter, the hero unexpectedly "resurrects" a companion who died, confuses locations, and the narrative style slides into dull generalizations like "he learned an important lesson and moved on."
The problem here isn't just the context window size. Even if you stuff fifty thousand previous words into the neural network, the model will still start getting details wrong or producing clichés.
Recently I came across an open project called InkOS (which has already gathered over 8.5 thousand stars on GitHub). It's a full-featured TypeScript framework for narrative management, web novel generation, interactive games, and scenarios. The authors tried to consolidate control over memory, style, and plot.
What's the idea and why ordinary prompts aren't enough
InkOS manages text creation through a chain of specialized agents. Instead of asking a single neural network to "write a chapter considering the plot," the system divides the process into clear roles.
One agent (Planner) shapes the current chapter's direction, another (Writer) produces the draft, a third (Observer) extracts facts about the world and characters from the text, and a fourth (Auditor) checks the finished version for contradictions.
The text passes through a control funnel:
If the auditor notices a character suddenly drawing a sword that was lost two chapters earlier, the chapter gets sent back for automatic revision by an editor agent.
Three-level memory and protection against hallucinations
The most interesting technical aspect of InkOS concerns how the project stores the state of the fictional world. If you rely on the LLM agent itself to rewrite the entire state in a Markdown file, the structure will quickly degrade.
The authors applied a hybrid approach:
- Strictly structured database. Inventory state, plot devices, character relationship statuses are stored in JSON format and validated with Zod schemas. The agent outputs not the entire JSON anew, but only a differential delta packet (JSON delta), which the project code applies to the state immutably.
- Local SQLite database. In Node.js 22+ versions, the system automatically connects SQLite for vector and keyword retrieval of past events, compressed annotations, and facts.
- Projections in Markdown. Files like
current_state.mdorpending_hooks.mdare automatically generated from validated JSON. They serve as a visual reference for the human author and for passing into generator context.
Thanks to this separation, the model cannot accidentally delete a plot branch or corrupt the state.json file format.
Fighting neural network gloss and automatic audit
Everyone has noticed the characteristic style of language models. Excessive use of filler words, uniform sentence length, a love for deep moral conclusions at the end of each paragraph.
InkOS includes a built-in text checking module with 37 parameters. It monitors sentence rhythm, word repetition frequency, and hunts for banal clichés.
Additionally, the engine includes a style analytics command:
inkos style analyze sample_author.txt
inkos style import sample_author.json --book my-novel
The utility extracts a numerical fingerprint from reference text (sentence length distribution, frequency dictionary, dialogue density) and generates a guideline. When generating new chapters, it produces not abstract text, but material strictly fitted to this fingerprint.
Interactive worlds and text RPGs
In version 1.5, developers added InkOS Play mode. This is a tool for launching text worlds with free actions or turn-based branching.

In Play mode, a so-called world contract is set. For example, detective investigation rules or a survival simulator. A system agent tracks time, inventory, items, and evidence, generating choice interfaces or processing user input in natural language.
Under the hood, mechanisms for dynamic illustration generation for scenes and items are used, as well as support for standard skill packages SKILL.md.
How it works internally
The project is entirely written in TypeScript. The web interface (Studio) runs on Vite, React, and Hono. The interactive console is implemented via TUI, and a traditional CLI is available for automation enthusiasts.
The agent framework is built on top of the pi-mono library (@mariozechner/pi-agent-core).
One convenient solution is flexible model routing. Writing fiction can be assigned to, say, Claude 3.5 Sonnet or Kimi K2.7, while audit tasks, JSON delta assembly, and validation can be delegated to faster and cheaper models via OpenRouter, Gemini, or local Ollama.
Routing configuration is set via pairs:
inkos config set-model writer kimi-k2.5 --provider custom --base-url https://api.moonshot.cn/v1
inkos config set-model auditor gemini-2.5-flash --provider google
How to run locally
The package is available on npm:
npm i -g @actalk/inkos
Creating your first book and launching a local studio requires just three commands:
inkos init my-story
cd my-story
inkos studio
A web panel opens in the browser on port 4567. There you can enter API keys for the required providers, set the concept of the work, and launch the process of planning the first chapters.
Direct commands are available for console work:
inkos book create --title "Забытый код" --genre sci-fi
inkos plan chapter Забытый код --context "Герой обнаруживает странный архив в серверной"
inkos write next Забытый код
Who will benefit from this project
InkOS isn't just another wrapper around ChatGPT. It's a structured development environment for those working with narrative systematically.
The project will be useful for:
- Narrative designers and game writers for developing quests and branching dialogues.
- Web novel authors who need an assistant that maintains chronology and facts.
- Developers creating text-based AI bots with memory and internal world rules.
Of course, the source code and prompts are oriented toward Chinese and English, but flexible prompt-pack configuration inside the prompt/ folder allows adapting generation to any language. AGPL-3.0 licensing allows deploying the system locally on your own server without being tied to proprietary clouds.
Related projects