85 agentic tools audited for security incidents · Talk to the lab →
MotionticBook a call
Glossary

What is compaction in AI agents?

Compaction is a context-management technique in which an AI agent's older conversation turns and tool results are replaced with a model-written summary, so a long task can continue inside the context window.

Checked

An agent's context grows with every tool call and every result it reads. Reliability drops as input grows, a pattern Chroma's Context Rot study found across 18 models, so without intervention a long run either hits the window limit or degrades before it gets there.

Compaction is the most common intervention. At a set point, the older part of the conversation is summarised, the summary replaces it, and the agent carries on from a shorter context.

How the labs ship it

  • Anthropic

    The Claude API offers server-side compaction in beta, either on demand or when input reaches a token threshold. Recent turns can be kept word for word, and a custom summarisation prompt can replace the default.

  • OpenAI

    The Responses API runs server-side compaction in-stream when context crosses a threshold, and a standalone compact endpoint gives explicit control. OpenAI advises treating compaction as a default for long runs rather than an emergency fallback.

  • Google

    Google's context-engineering guidance for ADK recommends compacting asynchronously and keeping a stable prompt prefix so caching still works.

Compaction and its alternatives

  • Context editing

    Clearing stale tool results by rule instead of summarising. Cheaper and more predictable, but it only removes, it does not condense.

  • Context reset

    Starting a fresh context with a structured handoff file. Anthropic found resets worked better than compaction for long application builds, because they give a clean slate.

  • Notes outside the window

    Progress and plan files the agent writes and re-reads, so the critical facts never depend on a summary.

What can go wrong

A summary can drop the one detail a later step needs, such as a file path, an ID or a constraint the user stated early. Compaction also rewrites the start of the context, so the prompt cache stops matching until a new prefix is established.

How Motiontic's engineers apply it

Motiontic's engineers keep durable state, such as the plan, decisions and IDs, in files or a session log outside the context window, so compaction only has to carry the narrative. Long-run evals check that the agent still meets its constraints after each compaction point.

Compaction, context editing and context reset compared

Compaction, context editing and context reset compared
CompactionContext editingContext reset
What happensOld turns become a summaryStale tool results are removedA new context starts from a handoff file
KeepsA condensed narrativeEverything except cleared itemsOnly what the handoff file records
RiskLost detail in the summaryRemoving something still neededHandoff file missing context
FitsLong conversations and agent runsTool-heavy runs with bulky outputsMulti-session builds

Common questions

What is context compaction?

Context compaction replaces the older part of an agent's conversation with a summary written by the model, so the agent can keep working without hitting the context window limit.

Is compaction the same as context editing?

No. Context editing removes items, such as old tool results, by rule. Compaction condenses the history into a summary. Many harnesses use both.

Does compaction affect prompt caching?

Yes. Compaction changes the start of the context, so later calls no longer match the cached prefix until a new one is built. Google's guidance recommends keeping a stable prefix where possible.

When is a context reset better than compaction?

For long, multi-session builds. Anthropic found that starting a fresh context with a structured handoff file kept agents more coherent than compacting the same window repeatedly.

Running agents that have to hold up?

Describe the agent, the systems it touches and what it must never get wrong. The first call is with a lab engineer, who will say plainly whether it is ready for production, and whether Motiontic is the right team.