New Tool Radar

AI Agents & Automation

How to Truncate Large Tool Outputs Before They Enter Agent Context

Truncate large tool outputs before they enter agent context, so one result cannot crowd out the rest.

Schematic with three steps: Set a size cap for each tool; Keep the start and the relevant part,; Test with a result that exceeds the.

A tool can return a huge result: a full page, a long log, a thousand-row table. Pasted whole into the agent’s context, it crowds out the instructions, the history, and the other tools’ results, and the run gets worse while costing more. Truncation is the fix: cap each tool result at a size the run can afford, keep the start and the most relevant part, and say clearly that the result was cut. CrewAI’s context handling does this automatically in one mode, deferring oversized native tool results to temporary files the agent reads in sections, and that is the shape to copy: never paste a giant result whole, and never silently drop the part that was cut.

What you need

  • A tool that can return a large result, with its typical size noted
  • A size cap per tool result, chosen from what the run can afford
  • A marker that says the result was truncated, so the agent knows it is partial

Step 1: Set a size cap for each tool result

Choose the maximum size a tool result may contribute to context, based on the context window and the number of tools. A cap that fits one tool may not fit ten.

Step 2: Keep the start and the relevant part, and mark the cut

When a result exceeds the cap, keep its beginning and the most relevant section, cut the rest, and add a marker saying the result was truncated and how much was cut. A silent cut looks like a complete answer.

Step 3: Test with a result that exceeds the cap

Run a task against a tool that returns a huge result and confirm the context stays inside the window, the marker appears, and the agent works from the kept part without claiming the missing part.

Worked example: synthetic output truncation check

The table below is a synthetic example. It shows the expected result of truncation; no agent was run.

Tool result Size In context?
Search results, 2 pages Small Whole result
Log file, 500 lines Large First 50 lines, marked
Table, 1,000 rows Large Summary rows, marked
Context stays in window Yes Pass

Expected result (UNTESTED). small results enter whole, large results are cut with a marker, and the context stays inside the window. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Truncation can cut the exact line the answer needed, so keep the most relevant part, not just the first part.
  • A marker says the result is partial; the agent must be told not to claim the missing part.
  • The cap must fit the whole run, not one result: ten capped results can still overflow.
  • Some results cannot be cut safely, such as a full record; fetch those by parts instead.

Sources

See all