Manage tool output the same way you'd manage a limited budget: summarize each result down to what the next step actually needs, prune completed steps once their outcome is captured in state, and scope each step's context to only the data relevant to its own sub-task. Skip all three, and results accumulate silently until the agent forgets what it was asked to do.

Quick answer: Feed agents summaries, not raw dumps. Prune a step's output once its conclusion is captured in running state — don't keep the transcript "just in case." Scope each step to see only what it needs, not the full trace. Treat context as a spendable budget, not an append-only log.

Why Tool Outputs Overwhelm an Agent's Context Window

Every tool call an agent makes returns its full output straight back into the conversation, and nothing removes it automatically. A ten-step agent that calls a search API, a database, and a file reader will, by step eight, be carrying the combined weight of every prior result — most of it irrelevant to the current decision.

This is different from a normal chat context problem. A human conversation grows one message at a time, roughly matched in size to what a person types. An agentic loop grows in bursts — a single tool call can return a 20,000-token JSON blob, a full webpage, or a database dump, and the agent has no built-in instinct to compress it before moving on.

Two mechanisms compound the problem:

  1. Verbatim accumulation. Most agent frameworks append the raw tool response to the message history by default, because it's the simplest thing to implement — not because it's the right long-term default.
  2. Context rot. Chroma's 2025 research on long-context behavior found that model performance on retrieval and reasoning tasks degrades measurably as input length grows, even well inside a model's stated context limit — the model doesn't just run out of room, it gets worse at using what's there.

The result is a slow drift rather than a hard failure. Nothing crashes. The agent just gets steadily less precise about which of the fifteen tool outputs sitting in its window actually matters to the task it started with. Our complete guide to context engineering covers this drift in more general terms — tool output management is the sharpest, most agent-specific version of it.

It's a distinct discipline from prompt design

Teams that are strong at prompt engineering often assume the same skill covers this problem, and it doesn't. A well-written prompt tells the model what to do; it says nothing about what data it's looking at five steps into a loop. As we lay out in context engineering vs. prompt engineering, prompting is authored once, up front — context management is a continuous, per-step decision about what stays, what goes, and what gets compressed. Tool output handling lives entirely on the context side of that line.

Summarizing Tool Output Before It Re-Enters the Context

Summarize a tool's result immediately, before it's appended to history, rather than storing the raw payload and hoping a later step filters it. The summary should capture the answer the step needed, not a condensed version of everything the tool returned.

The distinction matters. A bad summary shrinks a 5,000-token API response to 800 tokens of prose that still recites every field. A good summary reduces it to the two or three facts the next step will actually condition on — everything else is discarded, not compressed.

A few practical rules for where this holds up:

  • Summarize at the tool boundary, not at the end of the run. Waiting until the full trace is long to compress it means the summarizer itself is working with a bloated, already-degraded context.
  • Keep a structured residue, not just prose. A short JSON fragment ({"status": "found", "record_id": 4821}) survives re-reading by a later step far better than a paragraph the model has to re-parse.
  • Preserve provenance. Note which tool and which call produced a fact, so a later step (or a human reviewing the trace) can trace a decision back to its source instead of trusting an unattributed claim.
  • Don't summarize away numbers you'll need to recompute. If a later step needs to do arithmetic on a value, keep that value exact — summarization is for narrowing relevance, not for lossy rounding of anything load-bearing.

Anthropic's own published guidance on building agents makes a related point: context should be treated as a finite resource with diminishing marginal returns, where the job of the engineer is to find the smallest set of high-signal tokens that maximizes the likelihood of the desired outcome — not the largest set that fits. Summarization is the mechanical lever for that; it's how "smallest set" gets enforced call after call instead of staying an aspiration.

Where this connects to retrieval: if your agent needs to search back over dozens of past tool outputs rather than just the last few, that's a job for semantic retrieval over an embedded store, not for stuffing history into the prompt. Our guide to choosing an embedding model covers how to pick one for this kind of retrieval-augmented memory layer.

Pruning Old Steps Without Erasing the Plan

Prune a completed step's raw output once its conclusion has been folded into the agent's running state — the plan, the accumulated facts, the next action — because the raw transcript of how the agent got there stops earning its keep the moment the what is captured.

This is a harder call than summarization because pruning is destructive: once you drop a step, you can't reconstruct it if a later step turns out to need something you threw away. The practical answer isn't "keep everything" or "keep nothing" — it's a tiered policy.

What to doApplies toWhy
Keep verbatimThe original task/goal, current plan, and the last 1-2 tool outputsThe agent needs to re-ground itself in what it's doing at every step
Keep summarizedCompleted steps whose conclusion is now folded into stateThe fact matters; the exact wording of how it was retrieved doesn't
Prune entirelyFailed attempts already superseded by a working retry, verbose logs, raw HTML/JSON already extracted fromNothing downstream conditions on it anymore
Externalize, don't pruneLarge artifacts (files, datasets, full documents) the agent might need to re-queryStore a reference/pointer in context; fetch on demand instead of carrying the whole thing

The last row is the one teams miss most often. LangChain's write/select/compress/isolate framing for context engineering treats offloading to external storage as its own tactic, distinct from compression — a file, a scratchpad, or a database row the agent can look up again is not the same problem as a summary the agent can't un-shrink. Prune the copy sitting in context; keep the source of truth retrievable elsewhere.

A useful gut check before pruning a step: would a human reviewing the transcript need this to understand why the agent did what it did next? If yes, keep at least a summarized trace. If the honest answer is "no, it was a dead end," prune it completely rather than summarizing a failure nobody will act on.

Scoping What Each Step Is Allowed to See

Scope each step of a multi-step agent to the subset of context it actually needs for its own sub-task, rather than handing every step the entire accumulated history by default. Full visibility feels safer, but it's precisely how irrelevant tool output crowds out the instructions that matter for the step at hand.

This is the same discipline behind a well-designed context packet: a packet built for one purpose shouldn't carry every fact ever gathered, it should carry the facts that specific consumer needs to act correctly. Applied to an agent loop, each step is a consumer, and its context should be assembled for it, not inherited wholesale from the step before.

Three scoping patterns cover most agentic workflows:

  1. Sub-agent isolation. Spin up a narrow sub-agent for a bounded task (e.g., "extract every date mentioned in this document"), give it only the document and the instruction, and return just its distilled output to the parent — the sub-agent's internal tool calls never pollute the parent's context at all.
  2. Step-scoped state. Instead of one growing message list, maintain explicit state fields (current_goal, known_facts, open_questions) and construct each step's prompt from those fields directly, rather than replaying the whole history and trusting the model to find what's relevant.
  3. Role-based filtering. In a multi-agent setup, a "planner" role and an "executor" role don't need identical context — the planner needs the state of the world, the executor needs the current instruction and the tools available to it, not the planner's reasoning trace.

Think of it the way a customer journey map separates what a customer sees and needs at each stage — an awareness-stage message would be noise during checkout, and vice versa. An agent's steps deserve the same separation: what step three needs is not what step eight needs, even inside the same overall run.

Scoping also forces a useful question up front: what is this step's job, specifically? That's the same discipline behind jobs-to-be-done thinking applied to product decisions — define the job before you design around it. An agent step with a vaguely defined job tends to get handed vague, over-broad context "just in case," which is exactly the pattern that causes bloat.

A Worked Example: How an Agent Loses the Plot

An under-managed agent doesn't fail loudly — it drifts, quietly substituting a nearby, easier goal for the one it was actually given, once enough tool output has crowded out the original instruction. Below is a representative pattern, not a report of any specific production incident.

The task: "Find the three highest-priority customer complaints from last quarter's support tickets and draft a one-paragraph summary for the product team."

How it unravels, step by step:

  • Steps 1-2: The agent calls a ticket-search tool, gets back 40 tickets as raw JSON, and appends the full response to context. Already, most of the window is ticket metadata the agent doesn't need yet.
  • Steps 3-4: It calls a sentiment-scoring tool on a subset of tickets. That output, too, is appended verbatim — timestamps, ticket IDs, raw scores for tickets it already ruled out.
  • Step 5: Asked to identify the top three complaints, the model's attention is now split across several thousand tokens of ticket data, most of it irrelevant, with the original one-sentence task instruction buried near the top of a much longer window.
  • Step 6: Instead of synthesizing three priorities, the agent starts re-describing the tickets it most recently saw — a recency bias the "lost in the middle" research from Liu et al. documented directly: models are measurably better at using information at the very start or very end of a long context than information buried in the middle, and the original task sat right in that dead zone.
  • Step 7: The final output is a paragraph about the two tickets mentioned last, not the three highest-priority complaints across the full set — the agent answered a question adjacent to the one it was asked, because the real question got buried.

What would have prevented it:

FixWhere it applies in the trace above
Summarize each ticket batch to {id, one-line issue, severity} immediately after retrievalSteps 1-2, before the raw JSON ever entered lasting context
Prune the sentiment tool's raw scores once they're folded into a ranked listStep 4, instead of carrying every ticket's full scoring payload
Re-state the original goal at the top of context for the synthesis stepStep 5, so the instruction isn't competing with data for attention
Scope the synthesis step to only the top-ranked candidates, not all 40 ticketsSteps 6-7, cutting the field the model had to search before answering

None of these fixes require a smarter model — they require treating context as something the agent loop actively curates, step by step, rather than something that simply accumulates.

Building Budget Discipline Into the Agent Loop

Treat context like a token budget with a working ceiling well below the model's advertised maximum, and enforce it the same way you'd enforce any other resource constraint — with a check at every step, not a hope that it works out. The advertised context window is a limit on what the model can accept, not a target for what it should be given.

Published context windows vary by provider and change often, but the gap between "technically supported" and "reliably usable" is the point:

Model family (illustrative — check current provider docs)Published context windowPractical implication for agent loops
Claude (Anthropic)Roughly 200K tokens standard, with longer-context options in some releasesComfortable for most multi-step loops if pruning keeps working context far below the ceiling
GPT-4-class (OpenAI)Ranges from roughly 128K up to around 1M tokens depending on the specific modelLarge windows tempt teams to skip pruning entirely — the "lost in the middle" effect doesn't care how much room is left
Gemini (Google)Up to roughly 1-2M tokens in some tiersHighest raw ceiling of the major families, but Chroma's context-rot findings suggest raw capacity and reliable attention aren't the same curve

The table's lesson isn't "pick the biggest window." A bigger ceiling buys room for mistakes, not permission to skip the discipline — provider guidance on agent design converges on the same advice: keep the working context small and current, regardless of how much headroom the model technically offers.

A few operating habits worth setting once, rather than re-deciding every project:

  1. Define a token budget per step type, not just a global ceiling — a "search" step and a "synthesize" step have very different legitimate needs.
  2. Log context size at each step during development so bloat is visible before it causes a wrong answer, not after.
  3. Re-inject the original goal at a fixed cadence (every N steps, or whenever context is rebuilt) so it can't silently drift out of the model's effective attention window.
  4. Treat every new tool integration as a context-cost decision, not just a capability decision — ask what the tool returns and how it will be summarized before wiring it in, not after it's already bloating traces in production.

Where a structured critique of the loop helps

Spotting this kind of drift by re-reading a raw agent trace is tedious and easy to get wrong — the same verbosity that causes the problem also makes it hard for a human to audit by eye. Prodinja's Agentic-workflow critique is designed to walk you through where a multi-step agent's context can bloat or drift across a run, alongside the same budget-discipline questions covered in the context-packet breakdown above. Treat it as a structured design-review pass over your agent's plan, not a live monitor watching a production agent run — it's a rehearsal step for the design, the same way you'd review a spec before shipping it.

Key Takeaways

  • Tool output accumulates by default — most agent frameworks append raw results to history automatically, which is a convenience default, not a correctness default.
  • Summarize at the tool boundary, capturing the specific fact a step needs rather than a shorter version of everything the tool returned.
  • Prune completed steps once their conclusion is folded into state, but externalize large artifacts to a reference instead of deleting the only copy.
  • Scope each step's context to its own sub-task — full visibility into the whole trace is usually a liability, not a safety net.
  • Context rot is real even inside the stated limit — both Chroma's context-rot research and the Liu et al. "lost in the middle" findings show attention degrading well before the token ceiling is hit.
  • A bigger context window doesn't remove the need for discipline — it just raises how much noise an undisciplined loop can accumulate before failing visibly.
  • Re-inject the original goal at a fixed cadence so it can't drift into the dead zone of a long context window.

Frequently Asked Questions

How much context should an AI agent keep between tool calls?

Keep only what the next step needs: the current goal, a summarized state of known facts, and the last one or two raw tool outputs. Everything older should already be folded into summarized state or pruned, not carried forward verbatim step after step.

What is context rot in AI agents?

Context rot is the documented drop in a model's ability to retrieve and reason over information as input length grows, even when the total is still within the model's stated context limit. Chroma's 2025 research and the earlier "lost in the middle" findings from Liu et al. both demonstrate it directly, which is why raw context-window size is a poor proxy for how much an agent can reliably use.

Does a bigger context window fix tool-output bloat?

No — a larger window raises the ceiling before a hard failure, but it doesn't fix the underlying attention degradation that happens as unmanaged content accumulates. Teams that rely on window size instead of summarization and pruning tend to hit quieter, harder-to-diagnose failures: wrong answers, not error messages.

Should I summarize tool output or just truncate it?

Summarize rather than truncate whenever the discarded portion might contain a fact a later step needs — truncation is blind to relevance and can just as easily cut the important half. Truncation is acceptable only for content you're confident is uniformly low-value, like verbose logs or boilerplate headers.

How do I know if my agent is losing track of its original goal?

Watch for the pattern in this article's worked example: the agent's final output addresses something adjacent to the original task rather than the task itself, usually skewed toward whatever content it processed most recently. Re-stating the goal at a fixed step cadence and keeping a visible token-budget log during development both surface this before it reaches production.