Skip to content
LiveNext 22:20:18

Definition

What is Context compaction?

Context compaction is Context compaction is when an AI agent replaces a long conversation or work history with a shorter summary so it can keep working without running out of room in its context window.

What it is

Every AI model has a context window, a hard limit on how much text it can consider at once. A long-running agent, such as a coding assistant working for hours, eventually fills that window with its own earlier messages, tool results and file contents. Context compaction is the fix: when the history gets too long, the system condenses it into a summary and continues from the summary instead of the full record.

It works like a person taking notes on a long meeting and then throwing away the transcript. You keep the decisions and the open questions, and you lose the exact wording.

How it works

  1. The agent runs until its history approaches the window limit.
  2. The model, or the software around it (the agent harness), writes a summary of what has happened: the goal, what is done, what is pending, key facts and file names.
  3. The old history is dropped and the summary becomes the start of a fresh context.
  4. The agent carries on, reading the summary as its memory of the earlier work.

Different products call this compaction, summarization or context trimming. Some let you trigger it by hand, and others do it automatically.

Why it matters

Compaction is what lets an agent work on tasks far longer than one context window. It also has costs.

  • Lost detail. A summary can drop a fact that turns out to matter later, or state something slightly wrong.
  • Compounding errors. Each compaction summarizes a summary, so mistakes and omissions can persist.
  • Stuck beliefs. If the summary records an incorrect assumption, the agent may keep acting on it, because it no longer sees the evidence that would correct it.
  • Cost and speed. Writing a summary uses tokens, though a shorter context makes later steps cheaper.

Because the summary is the agent's working memory, whoever or whatever can edit it can steer the agent. Safety researchers have used this deliberately, editing a model's running notes to see whether its behavior changes.

How to work with it

Put durable instructions and key facts in a place the summary will not rewrite, such as a project file the agent rereads, or the system prompt. Good context engineering treats compaction as a step to design for. Check that the summary keeps your constraints. Where the work is critical, save important state to files or to AI memory rather than relying on the summary alone.

Key points

  • It trades detail for room, so an agent can keep going past its window.
  • The summary becomes the agent's memory, and mistakes in it can persist.
  • Keep rules and key facts somewhere that survives compaction.

Questions people ask

What is context compaction in AI?

It is replacing a long conversation or work history with a shorter summary so an agent can keep working within its context window.

Does context compaction make an AI forget things?

It can. Details left out of the summary are no longer visible to the model, so important facts should be stored somewhere that survives compaction.

Context compaction in the news