AI-generated fiction has a consistency problem. Ask any LLM to write chapter 1 of a novel and it'll do a decent job. Ask it to write chapter 30 and it has no idea what happened in the first 29.
I built InkOS to solve this. It's an open-source CLI AI agent that writes, audits, and revises novels autonomously — using a pipeline of 10 specialized AI agents with persistent state tracking across the entire book.
This post walks through the architecture and the specific engineering problems it solves.
The Problem
Most AI writing tools work like this: you give the model a prompt, it generates text, you copy it, repeat. There's no memory between chapters. After 20+ chapters, you run into:
- Continuity breaks — characters remember things they never witnessed, weapons reappear after being lost, relationships reset
- Context bloat — injecting all previous state into each prompt hits token limits, causes 400 errors, costs $200/chapter in API calls
- Hook accumulation — the model plants plot hooks but never resolves them. After 30 chapters you have 40+ dangling threads
- AI voice — every paragraph uses the same words ("delve", "tapestry", "testament", "intricate"), sentence structure is monotonous, and there's excessive summarization
The Architecture: 10 Agents in Sequence
Instead of one model doing everything, InkOS splits the work across 10 specialized agents:
Radar → Planner → Composer → Architect → Writer → Observer → Reflector → Normalizer → Auditor → Reviser
Each agent has exactly one job:
| Agent | What it does |
|---|---|
| Radar | Scans platform trends and reader preferences (pluggable, skippable) |
| Planner | Reads author intent + current focus + memory retrieval, produces chapter intent with must-keep/must-avoid lists |
| Composer | Selects relevant context from truth files by relevance, compiles rule stack |
| Architect | Plans chapter structure: outline, scene beats, pacing targets |
| Writer | Produces prose from composed context (length-governed, dialogue-driven) |
| Observer | Over-extracts 9 categories of facts from the chapter text |
| Reflector | Outputs Zod-validated JSON deltas for state updates |
| Normalizer | Single-pass compress/expand to hit the target word count band |
| Auditor | Validates draft against 7 truth files across 33 dimensions |
| Reviser | Auto-fixes critical issues, flags others for human review |
If the audit fails, the pipeline loops back: revise → re-audit until all critical issues are resolved.
State Management: 7 Truth Files
Every book maintains 7 canonical truth files as the single source of truth:
-
current_state.md— character locations, relationships, knowledge, emotional arcs -
particle_ledger.md— resource accounting: items, money, stats with quantities -
pending_hooks.md— open plot threads, foreshadowing, unresolved conflicts -
chapter_summaries.md— per-chapter summaries with state changes -
subplot_board.md— A/B/C subplot line status tracking -
emotional_arcs.md— per-character emotion tracking and growth -
character_matrix.md— interaction matrix, encounter records, information boundaries
The Auditor checks every draft against these files. If a character "remembers" something they never witnessed, or pulls a weapon they lost two chapters ago — the auditor catches it.
Since v0.6, truth files are stored as Zod-validated JSON (story/state/*.json). The Reflector outputs JSON deltas — not full markdown rewrites. Corrupted data is rejected, not propagated.
Solving Context Bloat: SQLite Temporal Memory
On Node 22+, InkOS uses a SQLite temporal memory database (story/memory.db). Instead of injecting all 7 truth files into every prompt (which blows up after 20 chapters), the Composer agent does relevance-based retrieval — pulling only the facts, hooks, and summaries that matter for the current chapter.
This was the single biggest improvement in v0.6. Before: context bloat caused 400 errors and made each chapter cost $200+ in API calls. After: selective retrieval keeps context lean regardless of book length.
Hook Governance
One of the hardest problems in long-form AI fiction: the model loves planting hooks but never pays them off. After 30 chapters you'd have 40+ open threads, none resolving.
The Planner agent now generates a hookAgenda — scheduling which hooks to advance and which to resolve in each chapter. analyzeHookHealth audits hook debt, evaluateHookAdmission blocks duplicate hooks, and new mention semantics prevents fake advancement (where the model references a hook without actually progressing it).
De-AI-ification
Every genre profile includes a fatigue word list. For LitRPG: "delve", "tapestry", "testament", "intricate", "pivotal". The Auditor flags these automatically.
But detection alone isn't enough — InkOS bakes de-AI-ification into the Writer agent's prompts at the source: banned sentence patterns, style fingerprint injection, dialogue-driven scene guidance. revise --mode anti-detect runs dedicated anti-detection rewriting on existing chapters.
You can also clone any author's style: inkos style analyze reference.txt extracts a statistical fingerprint (sentence length distribution, word frequency, rhythm profiles), and inkos style import injects it into all future chapters.
Genre Support
10 English-native genre profiles, each with dedicated pacing rules, audit dimensions, and fatigue word lists:
LitRPG, Progression Fantasy, Isekai, Cultivation, System Apocalypse, Dungeon Core, Romantasy, Sci-Fi, Tower Climber, Cozy Fantasy — plus 5 Chinese web novel genres.
Getting Started
npm i -g @actalk/inkos
inkos book create --title "The Last Delver" --genre litrpg
inkos write next
One command writes a full chapter: draft → audit → auto-revise. Run inkos up for daemon mode that writes chapters on a schedule.
Works with Claude, GPT-4, or any OpenAI-compatible API including local models. Multi-model routing lets you put Claude on the Writer and GPT-4o on the Auditor.
InkOS is also published as an OpenClaw skill — install with clawhub install inkos and any compatible agent can invoke it.
GitHub: github.com/Narcooo/inkos (2.4k stars, MIT license)
npm: npm i -g @actalk/inkos
Would love feedback from anyone working on multi-agent systems, long-context state management, or creative AI. What continuity problems have you run into with long-form AI generation?
Top comments (0)