AI Coherence Engineering for Long-Form Fiction: External State, Multi-Agent Pipelines, and Consistency Audits
This article explains why large language models struggle with long-form fiction and presents a practical engineering approach to solving it. It covers a multi-agent pipeline that separates planning, writing, observation, auditing, revision, and reflection; an external state store with world, character, plot, and style layers; a foreshadowing registry and rolling summaries for long-term memory; a six-family, 33-dimension consistency audit with severity-based handling; and bounded generate-audit-revise loops with retry, convergence, rollback, and idempotency rules. It also addresses readability, content compliance, and a staged rollout path.
1. The Problem: Why Long-Form Fiction Is Hard for AI
About two months ago, a natural question came up: could a large language model independently write a full-length web novel of several hundred thousand characters? I tried every common approach available—continuing directly with a general-purpose chat model, using various AI writing assistants, and assembling my own long-prompt pipeline—and the results were remarkably consistent: the first ten chapters read fine, but problems became denser the further the story went.
The symptoms fall into four categories:
- Dangling foreshadowing: A clue planted in Chapter 3 is neither paid off nor even remembered by Chapter 20.
- Power drift: The protagonist’s power level fluctuates up and down as scenes require, with no monotonically increasing or at least explainable constraint.
- Item resurrection: A key object that was lost, destroyed, or given away in the previous chapter reappears out of nowhere in the next.
- Timeline knots: Parallel events, travel durations, and day-night cycles contradict one another.
The root cause is not mysterious. A large language model is essentially a function that predicts the next segment given a context. It has only a finite context window, no built-in long-term memory, and no persistent representation of world state. Human authors rely on a mental setting bible, an outline, and repeated re-reading; a model that depends only on the text inside its window will inevitably drop details by Chapter 30 or 40.
So the conclusion is clear: without externalized state and consistency checking, the ceiling for AI-written fiction is the short story. Once state is moved out of the model into an externally readable, writable, and verifiable storage structure, long-form writing becomes a controllable engineering problem rather than something mystical.
2. The Approach: From One-Shot Generation to a Division-of-Labor Pipeline
The traditional approach is to build one prompt as long as possible, stuffing in the worldbuilding, character cards, a recap of prior events, and the requirements for the current chapter, then asking the model to produce everything in a single pass. Its failure mode is structural: the token budget is limited, everything stuffed in competes for space, and the model cannot verify itself.
The core idea here is separation of concerns: split writing into several single-responsibility agents, each doing one thing, chained through a pipeline, with a closed loop of generate–audit–revise.
A typical role breakdown looks like this:
| Role | Responsibility | Input | Output |
|---|---|---|---|
| Planner | Decide the chapter’s goal, conflict, and information gain | Outline, state snapshot | Chapter task card |
| Writer | Generate the prose | Task card, necessary setting slices | Chapter draft |
| Observer | Extract new facts from the chapter | Chapter draft | Structured fact entries |
| Auditor | Run multi-dimensional consistency checks | Draft, state, facts | Issue list |
| Reviser | Fix issues in a targeted way | Draft, issue list | Revised draft |
| Reflector | Update long-term state and the pacing curve | Fact entries, audit conclusions | New state version |
In practice, you usually add more: a setting gatekeeper (ensuring world rules are never violated), a pacing controller (managing the distribution of payoffs and tension), a summarizer/compressor (condensing history into an injectable rolling summary), and a review/compliance checker (handling sensitive content and moderation risk). Ten roles are not mysterious—it is essentially an editorial assembly line expressed in code.
The key constraint: each agent’s prompt contains only the minimum context needed for its one job. This saves tokens and significantly reduces cross-interference.
3. Externalizing State: Turning “Long-Term Memory” into Readable, Writable Data
The foundation of the whole approach is an external state store. It should be split into at least four layers:
world_state # world rules, geography, factions, timelinecharacter_state # abilities, location, possessions, relationships, injuriesplot_state # foreshadowing registry, suspense items, payoff flagsstyle_state # style baseline, sentence preferences, banned expressions
The most valuable of these is the foreshadowing registry, which turns “the author’s mental to-do list” into a row in a database:
{"id": "fs_017","planted_at": 3,"description": "The incomplete jade pendant the protagonist picked up","expected_payoff": "Reveal the protagonist's origins around Chapter 30","status": "open","related_chars": ["c_001"]}
Each time, the auditor only needs to query entries where status = open and expected_payoff is approaching, then prompt the planner that “it’s time to pay this off.” Likewise, character possessions are maintained in an item_ownership table, and the item-resurrection problem disappears naturally.
To keep injected context as short as possible, historical chapters should be compressed into a rolling summary: after each chapter, the summarizer produces a factual summary of no more than a few hundred characters, keeping only information that affects subsequent causality and discarding rhetoric.
4. Audit Dimensions: How the 33 Checks Actually Work
“33 dimensions” sounds complex, but they can be grouped into six families, each with several executable rules:
- Setting consistency: world rules, power systems, geographic distances, currency and units.
- Character consistency: ability ceilings, personality baselines, forms of address, verbal tics, continuity of injuries and state.
- Plot causality: whether each chapter adds information, whether conflicts are resolved, whether foreshadowing is paid off per the registry.
- Time and space: monotonic timestamps, reasonable travel durations, coherent day-night and weather transitions.
- Style stability: sentence-length distribution, narrative person, and tense that do not drift.
- Review and compliance: whether violence and sensitive plotlines cross the line, whether the value orientation is sound.
Rules should be written in a decidable form so they can be executed automatically:
def audit_power_level(state, draft_facts, chapter_no):issues = []for c in draft_facts.characters:cur = state.characters[c.id].power_levelif c.power_level > cur + CHAPTER_GROWTH_CAP:issues.append({"type": "power_jump","char": c.id,"at_chapter": chapter_no,"detail": f"{cur} -> {c.power_level} exceeds the single-chapter growth cap"})return issues
Two engineering lessons are worth emphasizing. First, audits must be repeatable and explainable: every issue must carry locating information and the basis for its judgment, otherwise the reviser has nothing to act on. Second, tiered handling: fatal issues (setting violations, moderation risk) must block and trigger a rewrite; general issues (wording, pacing) are handed to the reviser for local fixes; advisory issues (optional improvements) are only logged and do not block. Undifferentiated “full rework” will send the pipeline into an infinite loop.
5. The Loop and Retries: When to Stop
Generate–audit–revise must have boundaries, or costs spiral out of control. Strategies that work in practice include:
- Maximum rounds: revise the same chapter at most two or three times; beyond that, downgrade it to “flagged for human confirmation” and move on.
- Convergence check: if this round has fewer issues than the last and contains no fatal items, consider it converged.
- Rollback points: keep historical versions of the draft and state for each chapter, so a failed revision can roll back without polluting the state store.
- Idempotent writes: facts extracted by the observer are written with the chapter number as the primary key, so repeated runs produce no duplicate entries.
From an implementation standpoint, none of this requires mysterious infrastructure. State files can live in object storage or a versioned bucket; chapter tasks can be decoupled with a message queue so each role consumes asynchronously; a container platform can host the stateless agent processes; and logging, monitoring, and alerting services track per-chapter latency, audit pass rate, and retry counts. On Baidu AI Cloud, these general-purpose capabilities can be combined as needed—the focus remains on the state design and the audit rules themselves.
6. “Will Anyone Read It, and Will It Pass Review?”
Two practical questions deserve direct answers.
Readability: The advantage of a multi-agent pipeline is consistency; the risk is an “industrialized feel”—if every chapter strictly follows the same pacing template, readers tire quickly. The solution is to hand pacing to a dedicated role that maintains a chapter-tension curve, forces a twist or information peak every few chapters, and keeps a randomization range in the style state.
Review and compliance: This is a prerequisite for whether a serialized long-form work can continue. It is advisable to make compliance checking an independent agent placed before the audit rather than after it, outputting structured risk labels; also maintain a configurable rule set for sensitive words and subject-matter policies, updated as platform requirements change. Note that passing internal consistency audits and passing platform content review are two different things: the former ensures the novel does not contradict itself, while the latter depends on subject matter, degree of expression, and platform rules—no approach can promise a 100% result.
7. Implementation Advice
If you want to build a similar system, proceed in this order and do not stack ten roles from the start:
- First, do only state externalization: structure the character cards and foreshadowing table, and observe how much consistency improves.
- Then add the observer and auditor roles to get “generate-and-verify” working end to end.
- Next, add the reviser and retry strategy to push the pass rate from usable to stable.
- Only then split out planning, pacing, compliance, and other roles for fine-grained tuning.
In one sentence: the bottleneck for AI long-form writing has never been whether the model can write, but whether you have built a readable, writable, verifiable, and rollback-capable world state for it. Make memory a data structure, make review a pipeline, and serialized long-form fiction finally becomes engineering-feasible.
