Context Budgets for AI Agents: When a Harness Should Summarize
Learn when an agent harness should compress conversation history, what must never be summarized away, and how to log every compression for audit.

An agent harness should compress conversation history when the next model call would otherwise carry material that no longer affects the decision, and only when the facts that must survive can be kept intact. The core rule is simple: summarize narration and exploration, never summarize away instructions, permissions, identifiers, commitments or unresolved errors. Every compression should leave a log entry that states what was removed, what replaced it, and where the original can be recovered.
Key takeaways
- Compress on conditions the harness can check, such as context size, a closed phase of work or oversized tool output, not on a vague sense that the conversation is long.
- Keep a pinned block of protected state outside every summary and re-inject it on every model call.
- Verify each summary against the source span before it replaces the original, and reject any identifier or number that does not appear in the source.
- Log every compression with the trigger, the span, the size before and after, the protected-item check result and the reference to the stored original.
- Treat compression rules as versioned configuration that changes through review, not as an internal tweak.
Why context fills up before the work is finished
An agent works in loops. Each model call carries the instructions, the tool definitions, the current task state and the record of what has already happened. Tool outputs are often the largest part of that record: a search result, a long document extract, a page of database rows. Within a few dozen steps, a window that felt roomy at the start can be crowded with material that no longer bears on the next action.
Context pressure has two costs. The first is direct: more input means more cost and slower responses on every step. The second is quieter. When the window holds stale results, the important constraint stated early in the run can sit far from the point where it matters, under a long tool dump. Compression is the harness's way to manage both costs, but it is also the place where facts quietly disappear. That is why compression needs explicit rules rather than a single size threshold. Anthropic's engineering guidance on context engineering treats the context window as a finite resource to be curated on every call, which is the right mental model here.
For how to decide what each call should carry in the first place, see Context Window Budgets for AI Agents: What to Load in Each Call.
When should the harness compress history?
Compression should start from conditions the harness can measure and record. A size threshold is a useful trigger, but only if it is set below the hard limit so there is room for the next tool result, and only if it is combined with other signals. Useful triggers include:
- The context reaches the working budget you set for this workflow, with headroom left for the next tool result.
- A phase of work has closed, for example a document has been read and its findings have been written into the task state.
- The recent steps are mostly retries or exploration that did not change the plan.
- A single tool result is far larger than the next decision needs, so the full result should be stored outside the window and referenced by ID.
- The run is about to pause for approval or resume from a checkpoint, so the state should be compact and explicit before the pause.
Do not compress in the middle of an unresolved tool call, and do not compress while a human approval is pending. A summary written during an open decision tends to describe the question but not the answer, and the agent may later treat the summary as if the approval had happened. Compress complete turns only, so that every tool call and its result either both stay in the window or both move into the summary.
What must never be summarized away
Some content is not history. It is state, and a summary turns a rule into a memory of a rule, which the model may apply loosely or forget. Keep the following items in a pinned block that is injected on every call and never passed through the summarizer:
- The system instructions, the role boundaries and the stop conditions.
- Permissions and approval rules, including which actions require a person to confirm before they run.
- Identifiers the agent will reuse, such as account references, ticket numbers, file paths, order IDs and idempotency keys.
- Commitments made to a person, such as a promised follow-up date or a policy quoted to a customer.
- Open errors and unresolved questions, recorded with the exact error text rather than a paraphrase.
- The success criterion for the task, written in the form an evaluator will check.
- Any value a later step must compare against, such as a limit or a deadline held in the source system.
A practical test: if losing a sentence would change a later action or the answer to an audit question, that sentence cannot live only inside a summary. It belongs in the pinned block, where it is stored verbatim.
How to compress: a step-by-step plan
Follow the same sequence every time the harness compresses. The order matters, because each step checks the one before it.
- Step 1: Confirm the pinned block is present, unchanged since the last verified state and held in its own section of the context.
- Step 2: Select the span to compress from complete turns only, never splitting a tool call from its result.
- Step 3: Write the summary using a fixed template with four parts: goals reached, decisions made and the reason for each, facts established with their source, and open items.
- Step 4: Check the summary against the source span. Every identifier, number and quoted value in the summary must appear in the original span or in a stored tool result. Reject the summary if any value cannot be traced.
- Step 5: Replace the span with the summary and store the original in the run record under a reference ID, so it can be retrieved for review.
- Step 6: Write the compression log entry described in the next section.
- Step 7: Run one short verification call that asks the agent to restate the current task state, then compare the restatement with the pinned block. A mismatch stops the run and escalates to a person.
Step 4 catches most failures. A summary is generated text, and the typical error is not an obvious mistake but a plausible number or identifier that was rounded, shortened or guessed. A mechanical check against the source is cheaper than discovering the error when a downstream system rejects the action.
What each compression log should record
Every compression needs a record that a person can read later. Without it, a wrong answer on a Monday cannot be traced back to a summary written many steps earlier. The NIST AI Risk Management Framework is a useful reference for thinking about this kind of traceability as part of managing AI risk, and the OpenTelemetry semantic conventions for generative AI provide shared names for recording model activity. At minimum, each entry should contain:
- The run ID, the task ID, and the versions of the harness, the prompt and the tool schemas in effect.
- The trigger that fired, with the measured context size and the limit it was compared against.
- The span that was compressed, identified by step range, and the reference ID of the stored original.
- The size of the context before and after compression.
- The result of each protected-item check, recorded as pass or fail with the item name.
- The outcome of the verification call.
- The approver, if your policy requires a person to sign off on compression for this workflow.
Stored originals may contain personal or confidential data, so they should follow the same retention and access rules as the rest of the run record. Keep only the fields you need for review and reproduction. For a broader view of which fields make a failed run reproducible, see Replay Logs for AI Agents: Log Fields to Reproduce a Bad Run.
Illustrative scenario: a procurement assistant on its fifth request
The following scenario is illustrative and does not describe a real deployment. A procurement assistant reviews vendor onboarding requests. By its fifth request of the day, its history holds three vendor catalogs, two failed lookups and a note from an approver stating that one vendor needs a second review before any purchase order is raised.
A naive summary would read that vendor issues were discussed and one vendor needs review. That sentence is true but no longer actionable. A compression that follows the rules keeps the vendor identifier, the approver's exact condition and the lookup error text in the pinned block. The summary covers the catalogs and the lookups in general terms. The log records the span compressed, the size reduction, the protected-item checks and a passing verification call. If the verification call had restated the vendor as cleared, the run would have stopped and escalated before any purchase order was touched.
In Be Human managed operations, the protected items are defined with the business owner during the first engagement, so the pinned block reflects real approval rules rather than guesses. Compression thresholds, the summary template and the log schema are versioned together with prompts and tools, so a change to compression behavior ships as a reviewed release. Monitoring reviews compression logs for failed protected-item checks, permission reviews confirm the pinned block still matches current approval policy, and incident response covers the case where a summary is found to have dropped a fact.
If you are not yet sure which of your agent workflows would benefit from tighter context rules first, take the free Be Human AI diagnostic to find the first task worth handing to an agent.
Frequently asked questions
Should a harness summarize at a fixed token count? A fixed threshold is a trigger, not a complete rule. Set it below the hard limit so the next tool result has room, and combine it with phase-based and content-based signals. Then log which trigger fired so you can later judge whether the threshold is set well.
Can a model write the summary without human review? For most spans, yes, provided the harness checks every identifier, number and protected item against the source and runs a verification call afterward. Human review is worth adding for workflows with approval steps, regulated data or a new deployment, where you want to see the summaries before trusting the process.
How long should the uncompressed history be kept? Keep it for as long as your audit and retention policy requires for that workflow, under the same access controls as other run records. Storing originals separately keeps the active window small while preserving the ability to review what was removed. Apply the same standard to personal data inside those originals.
Does compression replace retrieval? No. A compressed summary keeps a long run coherent, while retrieval fetches specific documents when a step needs them. For long tasks, pair both with saved checkpoints, as described in Checkpoints for Long-Running AI Agents: Resume From Verified State, so a resumed run starts from verified state rather than from the summary alone.
Your next step
See where an AI agent fits in your company first.
Take the free Be Human AI diagnostic. A few questions about your work show which task to hand to an agent first, what it needs to know and where a person approves.
Be Human editorial guidance. Examples are illustrative unless explicitly attributed. Sources provide background; implementation choices depend on your workflow.


