Context Management for Multi-Turn Agents: From Dynamic Trimming to Append-Only History

    As reasoning-capable model services treat conversation history as a one-way stream, editing earlier messages can invalidate later reasoning items, raise token use and latency, and hurt output quality. This article explains why classic dynamic-trimming techniques break under that rule and how to move to an append-only context design.

    1. Background: The Old Playbook for Agent Context

    Over the past two years, builders of multi-turn applications have largely converged on a context stack centered on dynamic trimming. The usual pattern looks like this: system prompts are assembled per scenario and rewritten at the start of each turn from retrieval results; long tool logs are shortened after a few turns; once a conversation grows past a threshold, earlier turns are replaced by a summary; structured-output schemas switch as the task phase changes; and the available tool list grows or shrinks with permissions.

    That approach worked because earlier model APIs treated the final message sequence as the only input that mattered. As long as the sequence submitted to the model was coherent, how the history had been edited along the way did not. System prompts, prior turns, and tool outputs could be rewritten and compressed with one goal: fit the most relevant information into a limited context window.

    When services moved to models with deeper reasoning, that assumption changed. Reasoning is no longer an opaque text-generation step. It is a traceable chain of explicit reasoning items that record the steps the model takes before each decision. Those items are an important part of output quality.

    2. The Core Change: Prefix Edits Invalidate the Reasoning Chain

    Current developer migration guidance introduces a far-reaching rule: if history is modified during a multi-turn conversation—for example by rewriting an earlier developer message, truncating a tool result, replacing older turns with a summary, switching models mid-conversation, or changing the end user—the service discards every reasoning item after the point of change.

    That rule needs to be read carefully:

    • Reasoning items are not a cache. They are a reasoning path. When the service detects a prefix change, it cannot be sure the edited history still supports the later reasoning, so it clears every subsequent reasoning item and requires the model to reason again.
    • Reasoning again means more tokens and higher latency. The same guidance notes that incomplete reasoning recovery can significantly reduce output quality.
    • Just as important, discarding reasoning is described as part of the safety measures. The newer architecture treats context as a one-way flow in time. Any backward edit may undermine safety alignment or behavioral constraints, so the service prefers to spend performance rather than let reasoning be contaminated.

    As a result, five classic context optimizations now risk becoming ineffective or actively counterproductive. Developers need a new mental model.

    3. Compatibility of Five Common Optimizations

    3.1 Dynamically assembling the system prompt

    Old practice: rewrite the opening system prompt each turn from retrieval results and inject task instructions on the fly.

    Problem: under the new rule, any change to an earlier message is a prefix change and drops every reasoning item after it. Even a single dynamic field in the system prompt can wipe out the reasoning-cache benefit for the whole conversation.

    3.2 Truncating tool results

    Old practice: when a tool log is too long, go back and shorten that call’s result to free context space.

    Problem: truncation is also a prefix edit. It is easy to miss that tool results often sit on a critical reasoning path. After they are shortened, the model has to reinterpret what the output means for the current decision. The efficiency loss can easily exceed the space saved.

    3.3 Replacing older turns with a summary

    Old practice: once the conversation exceeds a length limit, compress earlier turns into a summary.

    Problem: this is the most common way to hit the rule. Replacing history with a summary deletes the original content, and the service clears every reasoning item after that point. In long conversations, each compression forces another full reasoning pass, so token use can rise instead of fall.

    3.4 Switching structured-output schemas by task phase

    Old practice: change the structured output schema according to the current task type.

    Problem: in the old architecture, a schema change affected only output parsing. In the new one, it is treated as a configuration change and can trigger the same prefix-modification check. Frequent schema switches put the model in a loop of reason, discard, and reason again.

    3.5 Adding or removing tools by permission

    Old practice: before each request, add or remove tools based on the signed-in user’s permissions.

    Problem: the tool list shapes how the model judges its capability boundary, so it is part of the prefix. Changing it breaks reasoning continuity. When a tool is removed, the model may no longer interpret intermediate conclusions that depended on that tool.

    4. The New Pattern: Never Rewrite, Only Append

    The documentation’s replacement is clear: context should only grow at the end, in time order. Configuration changes are written as new records at the end. Historical content is not modified.

    In practice:

    • To change reasoning-effort settings, do not alter them as a request-level parameter. Append a configuration-update entry at the end of the message sequence.
    • To change the output format or structured schema, do the same with an appended configuration update, and leave request-level parameters unchanged.
    • To change the tool-call scope, extend capability by attaching tools, or use an allowlist to limit the subset callable on the current turn.
    • To revise or add system instructions, append a new developer message instead of rewriting the original instructions at the start.
    • If a tool output must be shortened, shorten it before it is sent to the model the first time, and do not change it afterward.

    One easy-to-miss detail: top-level instruction fields are now placed at the end of the input sequence. If you want stable instructions to hit the context cache, move them into the first developer message in that sequence. Without that change, that portion is billed as uncached input.

    This append-only style turns a multi-turn conversation from an editable document into an append-only log. The provider needs every context state to be fully replayable, so historical rewrites are not allowed.

    5. What This Means for Agent Architecture

    The impact goes well beyond how a single API call is assembled. Agent architecture has to change with it.

    Plan context up front. It used to be acceptable to keep optimizing context while a run was in progress. Now the content has to be planned before the request is built. The initial system prompt should be written completely once, rather than extended later with fragmented instructions. That means more work in prompt design, separating instructions that stay fixed from those that change.

    Move state outside the transcript. When history cannot be edited backward, compression and filtering of older information have to live in the application. Keep a separate state store for key facts, intermediate conclusions, and task progress. Only when you call the model should you turn the relevant information into new messages and append them.

    Make tool calls self-contained. If tool outputs cannot be shortened later, the tools themselves must return less. Prefer a compact structured result and avoid large raw logs in the output. Where detail is still needed, expose a separate log-query interface so the model can fetch it with a follow-up call.

    Treat caching as the main cost lever. Under an append-only design, context caching can cut token use sharply. Keep stable instructions in a fixed position in the message sequence and append changing business data after them, so each request pays mainly for the increment.

    Use a different compression path for long conversations. Because in-place summaries are not viable, long-conversation compression means starting a new session, or using a compressed summary as the first message of that new session. Turn limits then depend on how complete the business needs the history to be versus what tokens cost. Session boundaries need an explicit management policy.

    6. A Practical Migration Path

    For multi-turn applications already in production, a three-step migration is a reasonable path.

    Step 1: Audit current context logic. Map every code path that can rewrite message history or configuration parameters, and mark each operation that can trigger a prefix change. Pay special attention to system-prompt assembly, post-processing of tool output, and history compression.

    Step 2: Rebuild around append-only assembly. Change request construction so every update is a new entry at the end of the messages. Update the cache strategy at the same time so the stable prompt portion can be cached.

    Step 3: Check reasoning continuity and output quality. After the migration, regression-test representative conversations. Watch reasoning consistency in long dialogues, latency, and token use. If an older technique still looks better in some cases, weigh the quality loss from a broken reasoning chain against the space it saves.

    Over the longer term, context management is shifting from “optimize space first” to “preserve reasoning integrity first.” The stronger a model’s reasoning, the more it depends on an intact history. Future agent designs will treat an append-only log as the default and push compression and editing out to an external memory system. That is not only a change in how APIs are called. It is a shift in how multi-turn systems are designed.