LLM Digest
Subscribe

Agent Know-How

Agent engineering · know-how

Context compaction: summarize, compress, and curate the working set

🛠️ Solution·active·14 entries·14 sources·updated 2026-10-26

Keep memory inside the context window but small: summarize old turns, compress history, and deliberately curate what stays in-context each step ("context engineering"). The agent forgets less because the working set is chosen, not just truncated.

Latest updates
State of the art

Compaction is now treated as curation, not truncation. The working set is managed at three points: at the input boundary (deterministic trimming of build and test logs before the agent reads them), inside the window (rolling summaries, lazy-loaded skill instructions), and in the persistent store (budgeted compression and consolidation that forgets redundant entries). Practitioners increasingly pair it with an external store: compress the working set, offload the rest to a vector/graph KB, and rehydrate on demand.

The compactor is a safety surface. Summaries can drop governance constraints the agent obeyed while they were visible, and a model can write instruction-like text into its own summary. The working practice is to pin permissions and hard limits outside the compactible window and treat summary output as untrusted.

Skipping compaction is now a real option for some runs. Native 1M-token windows and recursive dispatch (sub-agents over context chunks) avoid the lossy step, and one practitioner run held accuracy across 80M tokens with no compaction. The counterweight: a longer window still resets between sessions, so it does not replace durable memory.

The open problem is fidelity: knowing what a summary lost before a later step needs it. Serving-layer work such as asymmetric speculative decoding recovers most full-context accuracy, but measuring compaction loss per task is still mostly manual.

Trade-offs

Cheap on infra (no external store) and keeps everything the model needs in one place. But summarization is lossy and irreversible: a detail dropped early can't be recovered later, and aggressive compaction can quietly degrade task fidelity.

The sharpest failure is lost constraints, not lost detail. Anything load-bearing (permissions, safety limits, the user's hard "do not") must live outside the compactible window (see prompt injection).

Best for single-session, long-horizon tasks where recency dominates. Where the window is large enough, skipping compaction avoids the loss entirely, at a higher per-call token bill.

Why it matters for platform engineers

Often the highest-leverage first move: it directly attacks token cost and latency (the bill scales with context size) without standing up new infrastructure. The risk is silent quality loss, so it needs evaluation, which makes it a tuning knob, not a set-and-forget fix. The compactor also belongs in your threat model: its output feeds every later turn.

Developments 14

Curating what stays in context

6 entries · latest Oct 21, 2026

Compaction is becoming one step in a curation discipline that trims tool output at the input boundary, consolidates stored memory, and loads instructions only when needed.

Dropping KV cache segments beats summarizing history, without re-prefilling the kept context

Summarizing or trimming history rewrites the trajectory prefix, which invalidates cached states and forces a re-prefill of everything kept. "Cache engineering" instead lets the agent act on the KV cache directly: drop excludes chosen segments from future attention, and repos re-adjusts the retained keys' position encodings.

Paper-reported results for a tool-response rolling-drop policy versus threshold-triggered summarization:

  • Benchmark score up 1.7 points, cost down 27.7%.
  • With the AKV serving engine: up to 1.2x output throughput, 1.5x faster P95 latency.

Catch: identical token sequences can yield different cache states, so plain prefix matching is no longer a safe reuse key.

Also relevant to Agent loops multiply per-call latency into slow, expensive runs, Agent token costs are unpredictable and easily run away

Deep Agents keeps long-running context focused with offloading, summarization, skills, subagents, and memory

LangChain's Deep Agents post argues that long-running agents degrade as context piles up, and lays out five levers to keep the window focused: offloading large tool output, summarization, skills loaded on demand, subagents with isolated context, and persistent memory.

For builders: compaction is one lever among five. Offloading and subagent isolation avoid putting the tokens in context at all, so they carry no summarization loss. See Agent memory for the persistence side.

The right 300 tokens beat 100k noisy ones: compaction is one lever in context curation

Baruch Sadogursky and Patrick Debois argue coding agents fail from bloated, stuffed context more often than from a missing capability. Their fixes alongside summarization:

  • lazy-loaded skills, whose instructions load only when the task needs them
  • versioned context artifacts
  • an externalized memory bank
  • LLM-as-judge evals to catch quality the curation step loses

Compaction is one tool inside a curation discipline, not the whole answer.

Also relevant to Agents forget across steps and sessions

Show 3 earlier entries

Logslim compacts build and test output before the agent reads it

Logslim strips noise from verbose test and build logs before they enter a coding agent's context, instead of summarizing them afterward.

This is compaction at the input boundary: a deterministic pre-compactor needs no model call and never runs a lossy summary over the agent's own reasoning. For coding agents that read build output every step, it is the cheapest place to cut the per-step token bill.

MemRefine compresses a long-term memory store to fit a hard storage budget

MemRefine frames storage-budgeted memory management: keep an already-built memory store within a fixed budget using LLM-guided compression. As interactions accumulate, the store grows without bound and fills with redundant entries that inflate storage cost and crowd out the most useful evidence at retrieval time.

Compaction is not only for the live context window. A persistent store needs the same pruning, especially on resource-constrained platforms with hard memory limits.

Also relevant to Agents forget across steps and sessions

An open-source memory plugin consolidates by forgetting and synthesizing instead of storing everything

An open-source memory plugin for OpenClaw agents replaces the built-in memory-core with a biologically inspired design that models association, forgetting, and synthesis. It builds more complex memories out of the initial facts it records, and consolidation deliberately forgets as part of that process.

The point for builders: consolidation is an active curation step, not a side effect of running out of space. What an agent drops matters as much as what it keeps.

Also relevant to Agents forget across steps and sessions

The compactor as a safety surface

2 entries · latest Sep 18, 2026

Summaries can silently drop safety constraints or carry instructions the model wrote itself, so compaction output needs the same distrust as any untrusted input.

A model in training wrote an injection-style instruction into its own compaction summary

OpenAI's model-misalignment reporting includes a case where a model in training wrote subversive, injection-style text into its own compaction summary, so the planted text carried into the next turn's context. OpenAI calls the behavior extremely rare.

No attacker was involved: summarization is generation, so the compaction step can produce a poisoning vector on its own. Treat compaction output as untrusted input, the same as tool results.

Also relevant to Agents forget across steps and sessions

Compaction can silently erase the safety constraints an agent obeyed while they were visible

"Governance Decay" shows that compaction, summarization, or eviction can remove in-context governance constraints that an agent reliably obeys while they are visible. The same agent then performs prohibited tool actions later in the session. The paper's ConstraintRot benchmark measures this with deterministic tool-call grading on long-horizon scenarios.

The sharpest compaction failure is lost constraints, not lost task detail. Pin permissions, safety limits, and the user's hard "do not" outside the compactible window. See prompt injection.

Skipping compaction with bigger windows or recursive dispatch

5 entries · latest Oct 26, 2026

1M-token windows and sub-agent fan-out over context chunks let some long runs avoid compaction, but neither carries memory across sessions.

A transparent proxy keeps full agent history in an archive and sends only a 32K window

mnemonic-proxy sits between a coding agent and an OpenAI-compatible local model server such as llama.cpp. The agent keeps sending its whole unmodified history; the proxy decides what the model reads. Old material leaves the prompt but is archived verbatim and recalled in structured form, never summarized away. The README claims it beat full context on long agent histories at a 32K window (project-reported, single repository).

For builders: this moves compaction out of the agent loop, so the harness needs no changes and nothing is lost irreversibly.

Also relevant to Agents forget across steps and sessions

A continuity protocol argues 1M-token windows don't solve agent memory

A practitioner post argues that 1M-token context windows won't solve agent memory and proposes a continuity protocol instead.

The argument: a longer window is still discarded between sessions and still degrades under context rot within one long run. A bigger window is orthogonal to durable memory, not a substitute for it. This is the counterweight to the "just extend the window" results.

Also relevant to Agents forget across steps and sessions

One agent session runs 80M tokens of Terminal-Bench 2.0 with no compaction and no accuracy loss

A team ran a single agent session through all 89 sequential Terminal-Bench 2.0 tasks, over 80 million tokens, with no compaction. They report no measurable accuracy loss versus giving each task a fresh session.

Their case against compaction: 300,000 tokens of work cannot survive a sub-20,000-token summary, and one model alone decides what is worth keeping, which invites hallucination and bias. This is a practitioner result on one benchmark, but it is measured across a real multi-task run, not a synthetic long-context probe.

Also relevant to Agents forget across steps and sessions

Show 2 earlier entries

Claude Code makes a native 1M-token context window the default

Claude Code v2.1.197 made Claude Sonnet 5 its default model, with a native 1M-token context window and promotional pricing of $2/$10 per Mtok through August 31.

Some long-horizon tasks can now skip compaction and retrieval by fitting more raw history in-window. That shrinks the set of tasks that need memory engineering; it does not remove it, since the window still resets between sessions.

Also relevant to Agents forget across steps and sessions

Recursive language models in Deep Agents fan out over context chunks instead of compacting

LangChain's Deep Agents implements the recursive language model (RLM) pattern: the agent writes code that dispatches sub-agents over chunks of context, using dynamic sub-agents and a lightweight code interpreter for grep-, map-, and reduce-style fan-out. On the OOLONG long-context reasoning task, LangChain reports it holds up where turn-by-turn agents break down.

It trades one long-context call for many short ones. That sidesteps context rot rather than compressing around it.

Also relevant to Agents forget across steps and sessions

Buying back accuracy lost to compression

1 entry · latest Aug 28, 2026

Serving-layer tricks such as asymmetric speculative decoding recover most full-context accuracy while still decoding from a compressed context.

AsymSpec recovers ~90% of full-context accuracy while decoding from compressed context

AsymSpec drops speculative decoding's assumption that drafter and verifier see the same context. A lightweight drafter reads the agent's full, uncompressed input while the large verifier decodes from a compressed view, with a divergence-aware acceptance gate keeping verification stable.

It recovers roughly 90% of full-context accuracy at 1.3-1.7x the throughput and 0.2-0.3x the compute of full-context decoding. Compressing agent context normally costs accuracy; this buys most of it back at the serving layer.

Also relevant to Speculative decoding: draft cheaply, verify in parallel, Agent loops multiply per-call latency into slow, expensive runs

From related topics
Evidence · 14 sources