New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
Three tool calls into a long agent run, half your context budget is already gone and nothing in it is helping anymore.
What you'll have at the end
A wrapper that clears a tool's old output before the next call, with peak token count logged before and after
You need
A working tool-using agent loop that already calls at least one tool whose result can run large, like a file read, a log fetch, or a search, plus a way to count how many tokens a message adds before it's sent.
Not covered
Deciding how much of the system prompt, retrieved documents, or the rest of the token budget to hold back before any clearing kicks in, and summarizing old turns into a shorter version instead of dropping them outright; this covers only clearing a tool's own stale result, not the wider budget or lossy compaction of everything else.
Leans on
Log every tool call so you can find what broke a run
If you need the record of what a cleared tool call actually returned once the run is long over, that recipe's log survives even after this wrapper clears the message list; the live run alone won't keep it that long.
Give a long-running agent a memory file it rereads every run
If a finding needs to survive into a brand-new run, that recipe's memory file is the persistence layer a cleared placeholder can't provide; this one only carries a finding forward inside the same run.
Checked 18 Aug 2026
Part of the AI Agents cookbook