Long-Context Engineering for Long-Form Chinese Web Novel Writing
This article presents an engineering approach to long-form Chinese web novel generation with large language models, where single-chapter quality is easy to achieve but consistency, style, and repeatability break down across hundreds of thousands of words. It describes a four-layer architecture—context, memory, workflow, and acceptance—built on a long context window with prefix caching, structured character cards and map/timeline files, modular writing skills, and computable style metrics. It also explains why translated English syntax patterns create a "floating" feel in Chinese prose and how prompt, decoding, and acceptance layers address it, plus cost estimation logic and a list of common pitfalls.
1. The Problem: Why Long-Form Chinese Writing Is Hard
Many developers share the same experience after wiring an LLM into a writing pipeline: a single chapter looks fine, but as soon as the project stretches to hundreds of thousands of words, problems erupt. They fall into three categories.
Long-range consistency collapse. A character who is a taciturn swordsman in the first ten chapters turns into a chatterbox by chapter fifty. A city’s location, distance, and climate contradict each other in later chapters. Setups are planted and never paid off. The root cause is not that the model is “dumb”—the context window cannot hold the whole book, so the model only sees fragments, and stitching locally optimal fragments together inevitably produces global contradictions.
A “floating” prose style. Every sentence reads smoothly, yet immersion is poor and readers are easily pulled out of the story. Typical symptoms: heavy use of contrastive constructions like “not X but Y,” frequent em dashes for supplementary explanation, paragraphs that end on abstract judgments, and dialogue loaded with big words and metaphors. These structures are common rhetoric in English; translated directly into Chinese at high density, they feel unnatural to Chinese readers.
Non-reusable workflow. Prompts are scattered across chat logs. Every new session requires re-explaining the setting, style, and taboos, and quality depends entirely on luck.
The approach here treats writing as a software engineering problem: use a long context window to solve memory, skill modules to solve process, a personal corpus to solve style, and statistical metrics to solve acceptance.
2. Overall Architecture: Four Layers
┌─────────────────────────────────────────┐│ Acceptance: style metrics / consistency ││ checks / cost dashboard │├─────────────────────────────────────────┤│ Process: skill modules (bible, outline, ││ chapter, revision) │├─────────────────────────────────────────┤│ Memory: character cards + map/timeline ││ + story bible │├─────────────────────────────────────────┤│ Context: long window + prefix caching ││ + retrieval fallback │└─────────────────────────────────────────┘
The four layers are decoupled through the file system. The context layer makes everything fit; the memory layer makes facts accurate; the process layer makes execution stable; the acceptance layer makes revisions correct. Optimizing any single layer alone cannot solve the long-form problem—which is why so many people tune prompts and see little improvement.
3. Context Layer: Fitting the Whole Book In
3.1 Why Long Context Is the Dividing Line
The traditional approach is “summarize plus retrieve”: compress a summary every few chapters, then retrieve relevant fragments when needed. This works for customer-support Q&A and document Q&A, but in fiction it loses information continuously—what the summary discards is often some inconspicuous detail that turns out to be the setup to be paid off three hundred pages later.
The value of long context is that it downgrades memory from an algorithmic problem to a capacity problem: the full story bible, written text, and pending outline are all present at once, so the model does not have to guess. The practical approach is to load the full set—story bible, character cards, map, and written chapters—and fill the window, rather than stuffing in summaries only.
3.2 Prefix Caching and Cost Structure
The biggest concern about long context is cost, but real billing structures often run counter to intuition. Mainstream inference services generally offer prefix caching: when the shared prefix of a request (system prompt, skill definitions, setting files, prior text) stays byte-for-byte identical, those tokens are billed at a price far below the normal input rate, and only new content is charged in full.
This means the key cost variable is not “total tokens” but “the share of incremental tokens that miss the cache.” For a reusable writing session, a hit ratio above 95% is not hard to reach, provided two rules are followed:
- Append to the prefix monotonically. Settings and text are only added at the end, never revised retroactively; otherwise the cache is invalidated from the point of change onward.
- Do not restart the session. Frequently creating new sessions means repeatedly paying full price to reload the entire book.
Illustrative cost estimation logic:
def estimate_cost(total_tokens, hit_ratio,price_input, price_cache_read, price_output):cached = total_tokens * hit_ratiofresh = total_tokens - cachedreturn cached * price_cache_read + fresh * price_input \+ price_output * output_tokens
Raising hit_ratio from 0.85 to 0.98 cuts input-side spending by an order of magnitude. This is also why “the same book costs one person hundreds and another a few dollars”—the difference usually lies not in the model but in how sessions are organized.
3.3 Retrieval as a Fallback, Not the Main Mechanism
Even with a window large enough, keeping a lightweight retrieval layer is still advisable: first, to prevent a single request from exceeding the limit; second, to make it easy to trace “which chapter a setting first appeared in.” Here retrieval is an indexer, not memory itself.
4. Memory Layer: Character Cards and Map Management
Writing settings as structured files rather than prose descriptions is the key to keeping a long work controllable.
Suggested character card fields:
id: char_017name: Chinese namealiases: [nickname, alias]role: protagonist/supporting/antagonistspeech_style: short sentences, few adjectives, no unsolicited explanationstaboo: never say "not X but Y"knowledge_scope: knows A, does not know B # prevents characters from knowing too muchrelations:- {target: char_003, type: master-disciple, tension: rising}arc: {start: revenge, mid: doubt, end: letting go}
knowledge_scope is the most frequently overlooked field, yet it is the key to eliminating “characters who suddenly know everything.” The taboo field pushes style constraints down to character granularity, which is more precise than a global prompt.
For the map, maintain nodes and edges:
node: {id: loc_004, name: city name, climate: dry, faction: owner}edge: {from: loc_004, to: loc_009, distance: three days on horseback, route: mountain path}timeline:- {day: 12, event: city falls, witnesses: [char_002, char_017]}
With distances and travel times recorded explicitly, the model will not let a character cross a continent in a day. The timeline doubles as the setup registry: each setup records the chapter where it was planted and the chapter where it is planned to pay off, and unpaid items are mandatorily checked in every revision round.
5. Process Layer: Breaking Writing Into Skills
Do not rely on one universal prompt for everything. Break the work into independently iterable skill modules, each doing one thing, with files as input and output.
skills/analyze_style/ # analyze structure and pacing of existing worksbuild_bible/ # generate story bible, character cards, mapoutline/ # volume-chapter-scene three-level outlinedraft_chapter/ # single-chapter draft, must read character cards and mapcontinuity/ # consistency inspection, outputs an issue listde_english/ # rewrite to remove English-style Chinese expressionfinal_pass/ # pacing, setup payoff, ending closure
The pipeline advances in a loop: build_bible → outline → draft_chapter → continuity → de_english. Each chapter is inspected immediately after it is produced, so issues do not sit overnight. The payoff of modularization is replaceability: when one stage underperforms, rewrite only that module instead of overturning the whole system.
A core constraint for a drafting skill can be written as:
Hard constraints:1. Use only the speech styles defined in the character cards; forbid any characterfrom stating information beyond their knowledge_scope;2. Before moving any character, query the map edge table; travel time must not be compressed;3. Ban contrastive/progressive templates such as "not X but Y" and "not only ... but also ...";4. Do not use em dashes for supplementary explanation; use periods to break sentences;5. Do not end paragraphs with abstract summary sentences; end with action or dialogue.
6. Style Alignment: Replacing “Feel” With a Personal Corpus
The intuitive judgment of “AI flavor” cannot be written into a prompt, but it can be solved with a corpus. Collect personal past articles, Q&A, and earlier works as plain text, then do two things.
Build a style profile. Have the model summarize sentence-length distribution, person usage, verbal habits, punctuation habits, and paragraph length, and output a reusable style specification file that resides permanently as part of the prefix.
Score style. Extract a blacklist of sentence patterns that “pull readers out of the story” and turn them into computable metrics:
def style_metrics(text):return {"not_but": text.count("not") and text.count("but"),"dash_ratio": text.count("—") / max(len(text), 1),"abstract_ending": ratio_of_paragraphs_ending_with_judgement(text),"avg_sentence_len": avg_sentence_length(text),}
The point of these metrics is to turn “something feels off” into a regression gate: run the same metrics before and after a rewrite, and if the numbers do not drop, send it back for rewriting. This is far more efficient than repeatedly tuning prompts by feel.
7. A Technical Look at “English Syntax Transfer”
The phenomenon noted in the original text deserves a closer look. In the Chinese training data of large models, translated texts and English academic/technical writing make up a non-trivial share, so generation tends to reuse English syntactic skeletons:
- The contrastive template “not A but B” is an emphasis device in English; appearing frequently in Chinese, it feels deliberate.
- Em-dash insertions correspond to supplementary clauses in English, whereas Chinese relies more on short sentences and commas.
- Abstract nominalized endings (“this is a manifestation of …”) correspond to English nominalization; Chinese readers prefer concrete action.
- The “inverted pyramid” of stating the conclusion first and details after weakens suspense in Chinese narrative.
There are three engineering layers of countermeasures: disable template patterns at the prompt layer; suppress template tendencies at the decoding layer beyond repetition penalties (for example, regex replacement and rewriting in post-processing); and regress with metrics at the acceptance layer. Only stacking all three is enough to free the text from the floating feel. Note that the above inference about corpus distribution is an empirical observation; a rigorous conclusion still requires larger-scale corpus statistics.
8. Acceptance and Cost Dashboard
For a full production run, record four dimensions: number of consistency defects (characters knowing too much, geographic conflicts, timeline conflicts, missed setups), style metrics, cache hit ratio, and cost per unit of text. Only when all four enter the regression can you tell whether a change is a real optimization or robbing Peter to pay Paul.
Publicly reported practice suggests that long context plus a high cache hit ratio can push the cash cost of long-form writing down to roughly the price of a drink, while the quality bottleneck concentrates in consistency and prose style—exactly where engineering effort is most worth investing.
9. Common Pitfalls
- Modifying the prefix midway invalidates the entire cache and spikes cost;
- A character card missing
knowledge_scopeproduces omniscient characters; - A map that records place names but not distances distorts travel;
- No setup registry leads to a rushed ending;
- Generating a whole volume in one shot, with no per-chapter inspection;
- Watching total tokens only, not the share of cache misses;
- Constraining style with a global prompt instead of pushing it down to character granularity.
10. Conclusion
The core tension in long-form Chinese writing is the gap between local generation ability and global consistency requirements. The workable engineering answer: carry the book’s memory with a long context window, constrain facts with structured character cards and a map, fix the process with skill modules, align prose style with a personal corpus and computable metrics, and control cost with cache discipline. If the pipeline is hosted on general-purpose capabilities such as model inference, object storage, and log monitoring offered by platforms like Baidu AI Cloud, only the integration layer needs to be swapped—the methodology itself is fully transferable.
