R340 · Agent architecture › Memory and context

Who decides when to compact: model-managed context in an agent harness

Read the original

context-engineeringagent-harnessmemorykv-cacheinferencebenchmarkstoken-efficiency

Every long-running agent harness eventually has to throw away part of its own history. The conventional answer is a threshold: when the context window is 80% full, summarize the older events and keep the last few turns verbatim. A recent study (arXiv:2611.34147, submitted 25 November 2026) asks what happens if the model makes that decision instead, through an API it can call whenever it likes, and measures the result across four frontier models and two task families. The short version: the mechanism works, the benefit is a property of the model rather than of the design, and the cheapest part of the whole paper is a serving-layer trick nobody was looking for.

Architecture: two places the compaction decision can live

Harness-driven (the baseline). At 80% of the context budget, the harness summarizes the earlier history, preserving the initial instructions and the 10 most recent events. The model has no say and no visibility.

Model-driven (the thing under test). The model is given four things: a context API that lets it choose which events to replace with a summary, a live context-usage indicator, an instruction to consider compacting only once usage passes 85%, and a context-pressure warning appended to the request as the window fills. Compacted events are archived under a tag, and the model can go back and retrieve them later.

The distinction that matters for anyone building a harness is not "summarize vs. don't" — both arms summarize. It is who holds the trigger, and at what granularity. The harness compacts a prefix on a timer; the model compacts a selected set of events whenever it judges them spent. The archive-and-retrieve path is what makes the second one safe enough to try: a wrong compaction is recoverable at the cost of a retrieval.

What the measurements show

Two benchmarks: a document-research task (90 questions over a large pre-parsed corpus of U.S. federal receipts and expenditures, where reading documents fills the window fast) and an ML-engineering task (22 Kaggle competitions, where the agent must track experiments, implementation choices and execution feedback). Context budgets were swept from 8K to 512K tokens, each a hard limit on request size; on overflow a fallback drops the oldest events and retries, and three failures score the run wrong.

The headline is real and large: the strongest model nearly tripled its score at a 32K budget on the document task, 21% to 56%, with no extra training. That is the number worth knowing, and it is also the number most likely to be quoted without what follows.

The benefit does not generalise across models. All four received the same API and the same instructions. Three called it in 42-53% of tasks; the fourth called it in 4% of tasks — it simply declined to use the affordance. One of the three showed markedly less improvement than the leader. A harness feature whose value ranges from "nearly 3x" to "never invoked" is not a feature with a single expected value.

Compacting harder costs retrievals. When the leading model compacts, the request shrinks by a median factor of 3.7; the others manage 2.1, 1.8 and 1.5. But it goes back for archived content after 19% of its compaction calls, against 7% and 3% for two of the others. Aggressive compaction buys window space and sells it back in retrieval turns.

Timing is prompt-sensitive to an uncomfortable degree. With the 85% instruction, most models wait near that line. Remove the instruction and one model's median first compaction drops from about 84% of the budget to 29%; another from 83% to 40%; the model that almost never compacted starts compacting at a median of 16%. The paper calls this context anxiety, after prior work on models misjudging their remaining budget. A single sentence of prompt is the difference between a model that compacts at four-fifths full and one that compacts at a sixth full.

Token savings are smaller and patchier than the accuracy headline. At a 32K budget one model processed 41% fewer cumulative input tokens (36M against 62M) while scoring slightly higher, 43% against 41%. At 64K the same model saved about 11% while scoring 57% against 52%. The leading model on accuracy showed no comparable token saving at all.

The serving-layer finding, which is the most portable result

Editing a context breaks prefix caching in a specific and avoidable way. A KV cache stays valid up to the point of an edit and is invalidated for everything after it — including text that did not change. So replacing a middle slice of history with a summary forces the engine to recompute the whole surviving suffix, and a shorter context is not automatically a cheaper one.

Reusing the KV cache of that unchanged suffix cut prefilled input tokens per request by up to 15%, with no measurable impact on task reward. The saving is largest on the document task precisely because the suffix is big there: roughly 10K tokens, about 60% of the prompt on average, is retrieved document text that survives an edit.

This is the part to take seriously even if model-managed context is not on your roadmap, because it applies to any harness that edits history, including the 80%-threshold baseline. Caveat the authors state plainly: the prototype was one open 27B model in one serving engine, it approximates full recomputation, and it measures prefill compute, not end-to-end latency or cost.

Tradeoffs

Failure modes to design against

Review checklist

For a team considering giving an agent control of its own context:

What the study does not establish

The paper's own limitations are unusually direct. Both benchmarks are small. Context pressure is simulated by shrinking the budget rather than by genuinely long-horizon work, and the overflow fallback can itself move scores. Four models were tested and their training is unknown, so the explanation offered for the leader's stronger results is labelled a conjecture rather than a finding. The KV-reuse result rests on a single open model in a single engine. Note also that co-designing trained context management with the serving stack is the discussion's proposal, not a demonstrated method: everything measured here comes from prompting models that were not trained for the task.

Connections

See R340 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.