The "context tax": why tool-heavy agent runs cost more than you'd expect

If you build longer AI-agent workflows here — the kind where an Agent node loops through several tools before it answers — this is the cost surprise that caught me out, and it’s worth understanding before your token bill does the explaining.

My mental model for cost used to be: cost ≈ tokens in my prompt + tokens in the answer. In a single-shot call that’s roughly true. In an agent loop it isn’t, and the gap is large. Each iteration, the model is handed the entire conversation again: your instructions, every tool call, and — the expensive part — every tool result. A tool that returns 4 KB of JSON doesn’t cost 4 KB once. It costs 4 KB on that step, then again on the next step, and again on every step until the run ends. A 15-step agent re-reads its early outputs ~15 times. I’ve started calling it the “context tax”: you pay rent on old output, not just the price of new output.

An easy way to see it on your own workflows: if your provider returns usage stats, log input_tokens per model call across one agent run. In a short task it stays flattish; in a tool-heavy loop it climbs roughly linearly and often dominates the total before the agent even finishes. That one graph changed how I wire these.

Two things that measurably moved the number for me, both doable in n8n:

  1. Don’t let fat tool outputs flow straight back into the agent. If an HTTP Request or a DB node returns 200 lines and the agent only needs three fields, put a Set/Function/Edit-Fields node in between to pluck those fields first. The agent keeps the signal and stops paying rent on the noise every subsequent step.
  2. Collapse independent steps. If two lookups don’t depend on each other, doing them as parallel branches (rather than making the agent take two sequential tool turns) means fewer iterations, and fewer iterations means fewer re-reads of everything before them.

None of this is exotic — it’s just that the cost model is counterintuitive until you watch per-call tokens climb. Curious how others here are handling big tool outputs inside Agent nodes: do you trim before they re-enter the loop, and did trimming ever cost you answer quality, or was it free?

2 curtidas