What is context compaction?

Definition

AI context compaction replaces or reorganizes part of a growing context with a smaller representation. The process may summarize older messages, retain selected constraints and move detailed outputs into referenced artifacts.

Compaction can reduce token cost and latency, but it may also remove important evidence or instructions. Systems should preserve original history, validate the compacted context and apply the intervention only within approved policy boundaries.

ELI5

Context compaction reduces a long AI conversation or work history into a smaller form while trying to preserve the instructions, decisions, evidence, and unfinished work needed to continue. Detailed outputs can be moved into referenced files instead of repeated in every prompt.

For example, an agent may replace many old tool messages with a concise summary and links to saved results. The original history should remain recoverable because a poor summary can omit an important constraint or turn uncertain evidence into a false fact.

Acronyms and aliases

context compression synonymagent context compaction variantAI context compaction variant

Frequently asked questions

How does context compaction reduce AI agent cost?

It decreases the amount of prior text sent with later model calls, reducing repeated input-token processing.

What is the risk of context compaction?

A poor compaction can omit constraints, evidence or decisions and cause the agent to continue with distorted context.

Videos explaining context compaction

  1. Why Agent Runtimes Need Events and Logs
    AI Engineer20:291 VIEW