# Record
**Author:** @cameron.stream (`did:plc:gfrmhdmjvxn2sjedzboeudef`)

## `knowledge-context-compaction`
**Collection:** `site.standard.document`
**AT URI:** `at://did:plc:gfrmhdmjvxn2sjedzboeudef/site.standard.document/knowledge-context-compaction`

**Title:** Context Compaction
**Published:** Mon, 20 Jul 2026 23:58:00 GMT
**Updated:** Mon, 20 Jul 2026 23:15:00 GMT
**Description:** Replacing part of a long agent history with a smaller working representation while preserving durable evidence outside the prompt.
**Publication:** `at://did:plc:gfrmhdmjvxn2sjedzboeudef/site.standard.publication/3mr4py6clps2f`
**Path:** /context-compaction
**Tags:** knowledge, concept, ai, agents, memory, summarization, context-engineering

**Content:**
```json
{
  "text": "Context compaction is the replacement of part of an agent's interaction history with a smaller representation that can fit inside a finite model context. The compacted state usually combines a summary of older events with a recent uncompressed tail.\n\nCompaction is one mechanism inside [agent memory](https://cameron.stream/knowledge/agent-memory). It is not equivalent to durable memory: the summary serves current inference, while external records preserve the exact messages, artifacts, tool results, and revisions that the summary may omit.\n\n## Why compaction exists\n\nLong-running agents accumulate user messages, model responses, tool calls, retrieved documents, and execution results. Retaining the full sequence increases inference cost and eventually exceeds the model's context limit. It can also add distraction when stale intermediate states remain visible after the task has moved on.\n\nRecursive summarization is one response. A summarizer combines older memory with new interaction segments to produce an updated compact representation. The 2023 recursive-summarization paper found that this approach could improve consistency in long dialogue and complement both larger context windows and retrieval. That result concerns particular dialogue evaluations; it does not show that any summary preserves every form of agent state.\n\n## Compaction as a state transition\n\nA useful compaction record identifies:\n\n- the source message range or trajectory segment;\n- the summarizer model, prompt, and configuration;\n- the generated summary;\n- the recent tail preserved verbatim;\n- the original history location;\n- the time and reason for compaction;\n- any validation or known loss.\n\nThe model sees the compacted view, but the system should retain [strong references](https://cameron.stream/knowledge/strong-context-references) to the source history. This separates a convenient working representation from the evidence it represents.\n\n## What summaries commonly lose\n\nCompaction failures are often structurally predictable:\n\n- an open promise becomes a completed event;\n- an attempted action becomes a delivered action;\n- a tentative claim loses its uncertainty;\n- a correction loses the incorrect belief it superseded;\n- a current route or identity loses the message that authorized it;\n- a tool result loses the version or environment that produced it;\n- a vivid but irrelevant detail survives while a quiet invariant disappears.\n\nThese are not ordinary wording defects. They change the operational state inherited by the next turn.\n\n## Preservation contract\n\nA continuity-oriented summary should preserve at least:\n\n1. unresolved user requests and promised follow-ups;\n2. current task state and exact next action;\n3. verified receipts and known failed attempts;\n4. active permissions, routes, identities, and destinations;\n5. blockers and uncertainty;\n6. artifact paths, versions, and checksums;\n7. recent corrections that change interpretation;\n8. the boundary between public, private, and reviewed material.\n\nOther details can move into external memory or remain in the raw history. The summary should point to them rather than impersonating a complete archive.\n\n## Observing compaction\n\nThe OpenTelemetry Generative AI semantic conventions include a development-stage `gen_ai.conversation.compacted` attribute for indicating when the effective conversation supplied to a model is a compacted view. The same conventions warn that prompts and messages can contain sensitive information and should be opt-in telemetry.\n\n[Agent trajectory observability](https://cameron.stream/knowledge/agent-trajectory-observability) can connect a compaction event to later retrieval and behavior. Useful evaluations include whether open obligations survived, whether claims remained calibrated, and whether known source references still resolve after the transition.\n\n## Compaction and retrieval\n\nCompaction should reduce the default working set, not erase the agent's ability to recover detail. When a later request depends on an omitted event, [routing-based memory](https://cameron.stream/knowledge/routing-based-agent-memory) can load the canonical external source or raw history.\n\nThe design tension is therefore not “summary or retrieval.” A durable agent usually needs both: summaries for continuity under a token budget and retrievable evidence for fidelity.\n\n## Sources\n\n- [Recursively Summarizing Enables Long-Term Dialogue Memory in Large Language Models](https://arxiv.org/abs/2308.15022)\n- [OpenTelemetry Generative AI semantic conventions](https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/gen-ai-spans.md)\n- [What does good AI memory feel like?](https://cameron.stream/co-3)",
  "$type": "site.standard.content.markdown",
  "version": "1.0"
}
```

---
*Fetched from https://enoki.us-east.host.bsky.network via `com.atproto.repo.getRecord`*