What Is Context Compaction in AI Agents?
Context compaction is how an AI agent summarizes its own work when its context window fills up. What makes a good summary, and how our engineers test it.
Context compaction is what an AI agent does when its context window, the limited amount of text a model can hold in view at once, fills up during a long task. The agent writes a summary of its work so far, drops the older details and carries on from that summary, like notes left for the next shift.
Coding agents now work on tasks that run for hours, and the length of tasks they can finish keeps growing. Research on Measuring AI Ability to Complete Long Software Tasks found that this length has doubled roughly every seven months since 2019. Longer runs mean more compaction points, so each summary matters more.
With a good summary, the agent continues smoothly. With a summary that misses a key decision or gets a fact wrong, the agent repeats work, breaks something it already fixed, or heads off in the wrong direction. Our engineers built evaluation data that tests exactly this skill. The short answer from that work: a good compaction summary records only what the agent actually saw, keeps the decisions made early on, and ends with concrete next steps.
- When a coding agent runs out of context, it has to summarize its own work and carry on from that summary.
- At each compaction point our engineers wrote an ideal summary and a scoring guide across six areas.
- A good summary uses only what the agent actually saw and keeps beliefs separate from proven facts.
- Every later point builds on the first, so early decisions are the first thing we verify in any summary chain.
How do you test an agent's compaction summaries?
You force the agent to compact, then grade its summary against one an expert wrote from the same record. Each task was one long coding run, played under small context windows so the agent had to compact several times. At each compaction point our engineers wrote two things. The first was an ideal summary, the one the agent should have written, which the next part of the run continues from. The second was a scoring guide, a list of checks used to grade the agent's own summary. For more on writing checks that grade fairly, see How to Write a Fair Grading Rubric for AI Answers.
The chain ends with a final run that has to pass the task's tests. So a weak summary early on can sink the whole chain.
What does a good summary do?
- It uses only what the agent actually saw. Our engineers check every claim against the run record, the full log of the agent's actions and tool outputs. If a tool output was cut off, the summary cannot include the part that was cut. If something is still visible in the kept part of the context, it does not need repeating.
- It separates beliefs from facts. If the agent judged something without proving it, our engineers mark it as a belief in the summary.
- Its next steps are concrete. And our engineers check them against the record so they do not repeat work already done.
- It is written fresh. Our engineers build each ideal summary from the run record itself, so most of it is new writing rather than text reused from an earlier summary.
The scoring guides our engineers wrote covered six areas: the files and artifacts, the goal, the reasons behind decisions, the order of events, how well it compresses, and structure. They also added a few negative checks to each guide, each one a believable false claim tied to a specific line of the run that contradicts it.
Four lessons from building summary chains
Summarize what the record shows. An agent's internal reasoning is not part of the visible record, so a summary that leans on it makes claims nobody can check against the run. Anything that cannot be checked reads as invented. Our rule is to build every summary from visible evidence only: tool outputs, file contents and the agent's own messages.
Full paths, always. One summary used a shortened file path. Reading the next part of the run, our engineers saw the agent try to list it and fail. A path that is obvious to the writer is not obvious to an agent starting fresh, so full paths became a rule.
Early decisions carry the whole chain. A design choice settled near the start of a run has to appear in the first summary and in every summary after it. If it goes missing early, every later point inherits the gap, and the fix means reworking every point that came after. That is why our reviewers check the first summary hardest, and why early decisions are the first thing we verify.
One fix can cause the next problem. A small edit made to satisfy one check can quietly break another. So our engineers follow a strict rule: after any change, even one word, they run every check again.
Can a good summary make the agent better?
Yes. In one run, the engineer writing the ideal summary spotted a real bug in the record that the agent itself had missed, and wrote it in. In the next part, the agent read the summary and fixed that bug first. That is what a good summary does. It does not just remember. It points the way.
As agents take on longer work, memory becomes one of the biggest limits. Teaching them to write honest, useful summaries of their own progress is a direct way to make them more reliable, and it is careful, detailed human work. Another way agents take on bigger jobs is splitting work across helpers, which we looked at in When Should a Coding Agent Use Subagents?.
Frequently asked questions
What is context compaction in AI agents? When an agent runs out of context space, it summarizes its work so far and continues from that summary.
What makes a good compaction summary? Our engineers check that it uses only what the agent actually saw, separates beliefs from proven facts, records key decisions and gives concrete next steps.
Why do compaction summaries fail? In the chains our engineers built and checked, the common causes were a missing early decision, claims about things the agent never saw, and vague references like short file paths.
What is a context window? The amount of text a model can work with at one time. Everything the agent has read, written and run so far has to fit inside it, which is why long tasks eventually need compaction.
Building Evaluation Data for Long-Running Agents?
We write ideal summaries and scoring guides that test whether an agent can pick up where it left off, with every claim checked against the run record. Our AI Agent Development and Model Evaluation and Rubrics teams help AI labs and model teams get this data built to a bar their researchers trust, and delivered when the next training or evaluation round needs it.
Get in TouchKeep reading
All articles- AI & MLNov 11, 2026
How to Give Human Feedback on AI Agent Work
How to give human feedback on AI responses that a model can learn from: evidence for every judgment, consistent flags and a clear reason for each preference.
- AI & MLSep 15, 2026
How to Build DevOps Tasks That Test AI Agents
DevOps tasks for testing AI agents: a broken, production-like system the agent must repair without losing data. How our engineers built 19 of them, and why.
- AI & MLSep 3, 2026
Terminal-Bench 2.0 vs 3.0: What Changed in Task Design
Terminal-Bench 2.0 vs 3.0: the newer version is harder and covers far more kinds of work. What that shift changed in how our engineers design terminal tasks.