New Tool Radar

AI Agents & Automation

How to Prune Old Tool Results From Agent Context

Prune old tool results from agent context so the current step has room to work.

Schematic with three steps: Mark which results the next step still; Prune the finished results and keep the; Run the next step and confirm it.

Tool results pile up in context: every search, every lookup, every fetch stays in the history, and the current step ends up working in whatever space is left. Pruning removes the results the run no longer needs, keeping the ones the current step still depends on. The OpenAI Agents SDK lets you control how history merges into each run, for example by keeping only the last few history items, which is the same idea in a simpler form: old items leave, the current step keeps its room. Decide what to prune before the run: results whose step is finished and whose values are already used can go; results the next step still needs must stay.

What you need

  • A run where tool results accumulate across several steps
  • A rule for what may be pruned: results whose step is finished and whose values are already used
  • A way to keep the pruned results in the run log, so they are not lost entirely

Step 1: Mark which results the next step still needs

Before pruning, list the tool results the next step depends on: the order id, the prices, the names. Everything else is a pruning candidate, not a certainty.

Step 2: Prune the finished results and keep the log copy

Remove the pruned results from the context the model sees, and keep a copy in the run log so the run can still be audited. A result removed from both places is a result that never happened.

Step 3: Run the next step and confirm it has what it needs

After pruning, run the next step and confirm it uses the kept results correctly and does not ask for a pruned one. If it does, the pruning rule cut too deep.

Worked example: synthetic context pruning check

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

Tool result Still needed? In context?
Supplier search, step 1 No – used Pruned
Price list, step 2 Yes Kept
Order lookup, step 3 Yes Kept
Next step has what it needs Yes Pass

Expected result (UNTESTED). the used search result is pruned, the two results the next step needs are kept, and the step runs correctly. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Pruning removes context the model can no longer see, so a wrongly pruned result is a lost fact.
  • The run log must keep the pruned results, or the audit trail has holes.
  • A result the next step needs but that was pruned will be re-fetched or guessed.
  • Pruning saves context, not cost: the tokens were already spent when the result arrived.

Sources

See all