Append-Only Context for LLMs: A Practical Guide to Never Rewriting the Prompt Prefix
This article explains why many mainstream conversational model APIs now treat submitted conversation history as immutable, and why editing the prefix—rewriting the system prompt, truncating tool logs, summarizing earlier turns, switching output modes, or changing the tool list mid-session—invalidates all cached reasoning state after the edit point. It breaks down the mechanism behind the rising cost of prefix changes, shows why five common context-management habits fail under an append-only model, and presents alternative patterns: append configuration updates at the end, freeze stable instructions first, trim tool output before the first submission, and express permission changes as new records. A migration checklist and a note on prefix-cache placement are included.
1. Background: Multi-Turn Conversations Move from Editable to Append-Only
Over the past two years, agent applications built around large models have settled into a set of familiar context-management habits: system prompts assembled dynamically per scenario, overlong tool logs truncated after the fact, older turns compressed into summaries once they cross a threshold, structured output modes switched as stages change, and the available tool list adjusted by permission. All of these make sense under the assumption that context is a randomly readable and writable string.
A recent migration in a mainstream class of conversational model APIs sends a clear signal: once multi-turn conversation history is submitted, it can no longer be modified retroactively. Any change to the prefix—rewriting the developer instructions at the top, shortening a tool return, replacing older turns with a summary, or switching models, end users, or organization ownership midway—discards all inference intermediate state after the point of change. For developers, this is not a small optimization to cache hit rates; it is a paradigm shift in context architecture.
2. How the Mechanism Works: Why Editing the Prefix Gets Expensive
2.1 Inference intermediate state is a function of the prefix
The inference intermediate state left by the model in each turn is a cached computation result over “all input up to that point.” Change the prefix, and that result no longer corresponds mathematically to the new input; it must be discarded in full and re-derived from the point of change.
2.2 The cost structure is amplified
Recomputation means higher input-side token consumption and longer time to first token. In long tool chains and multi-round review scenarios, repeated inference multiplies both the bill and response time.
2.3 Quality drift comes from discontinuous reasoning
When history is replaced by a summary or tool output is trimmed, the model loses more than text: it loses the problem decomposition and intermediate conclusions already established, which shows up as inconsistent judgments across turns and dropped constraints.
2.4 A safety property, not a billing option
This kind of invalidation is typically documented explicitly as part of safety guarantees rather than a mere pricing choice. Saving tokens by editing the prefix is therefore not sustainable at the policy level either.
3. Why Five Common Practices Fail Together
- Rewriting the opening system prompt each turn based on retrieval results: prefix rewriting.
- Truncating overlong tool logs after the fact: prefix rewriting.
- Replacing early conversation with a summary: prefix rewriting.
- Switching the structured output mode by stage: prefix rewriting.
- Dynamically adding or removing tools by permission: prefix rewriting.
A typical code-review agent hits four of these at once. Trimming logic that looked carefully designed triggers a full restart of inference on every invocation under an append-only model.
4. Alternatives Under the Append-Only Paradigm
The core principle in one sentence: context is appended one-way along the timeline, and configuration changes are also written as new records at the end.
- Adjust reasoning effort: do not change request-level parameters; append a configuration-change record at the end.
- Switch output mode: declare the new mode with an appended configuration-change entry instead of editing the old declaration.
- Dynamic tool permissions: express them as “append available tools” and “restrict the callable scope for this turn,” keeping history unchanged.
- Update developer instructions: append a new developer message at the end, forming a versioned stack of instructions.
- Handle overlong tool output: trim it before the first submission to the model, and do not modify it afterward.
Illustration (pseudocode, structure only):
input = [{role: developer, content: fixed spec v1},{role: user, content: task},{role: tool, content: trimmed log},{type: configuration_update, reasoning_effort: high, output_schema: v2},{role: developer, content: appended constraint v2}]
5. An Easily Overlooked Caching Detail
When fixed instructions are placed in a top-level instruction field rather than at the first position of the input sequence, they often fail to hit the prefix cache, and that portion is billed as uncached input. Moving stable specifications to the first developer message in the input is a low-cost, high-return change.
6. Migration Checklist
- Inventory every code path that “rewrites history” and flag it as high risk.
- Move stable content to the front and freeze it; place volatile content at the end and append it.
- Perform one-time trimming and structuring of tool output before it is stored.
- Replace in-place modification of parameters and modes with configuration-change entries.
- Build observability: use logging services and monitoring alerts to track recomputation counts, input tokens, and latency percentiles.
- Enforce an “immutable history plus appended events” data flow at the container platform and message queue layers.
7. Conclusion
Moving from editable context to append-only context means designing a session as an event log that only grows. Following three principles—an immutable prefix, changes appended at the end, and stable content placed first—yields a better balance among cost, latency, and output stability, and aligns more closely with security and compliance requirements. Organizations deploying on Baidu AI Cloud can store session events in object storage, chain the append flow with a message queue, and run the agent runtime on a container platform to form a complete engineering loop.
