How to Set Token Budget Per Task for AI Agents Before Costs Spiral Capping each tool result at roughly 3,000 tokens, with a handle to fetch more, does more to control AI agent costs than any other single change, according to a Startup Fortune guide on setting per-task token budgets. The guide calculates that a 20,000-token tool result left in context for 11 more calls costs 220,000 input tokens, more than an entire 200,000-token task budget, and recommends splitting a 200,000-token task into 10% system and tool definitions, 10% planning, 20% retrieval, 35% tool output, 10% retries and 15% reserve. It cites Anthropic's engineers reporting that agents use about four times more tokens than normal chat and multi-agent setups about 15 times more, and the Manus agent team reporting an average input-to-output ratio of around 100 to 1. Most of what an agent bills you for is text it has already read once. Cap that text slice by slice and the runaway bills stop. - An agent resends its whole history on every call, so a tool result is billed once for each later step that carries it. - A 20,000-token tool result sitting in context for 11 more calls costs 220,000 input tokens, more than a whole 200,000-token task budget. - A workable split for a 200,000-token task is 10% system and tool definitions, 10% planning, 20% retrieval, 35% tool output, 10% retries and 15% reserve. - Capping each tool result at about 3,000 tokens, with a handle to fetch more, does more for cost than any other single change. - Warn at 70% of the budget, force a wrap-up at 90% and stop with partial results at 100%, and keep the dollar cap as a backstop. The cheapest agent run you'll ever see is the one in the demo. The expensive one is task 400 in production, where a search tool returned an entire web page and every step after it dragged that page along. If you want to know how to set token budget per task for AI agents, start from that fact: tokens are billed every time they're re-read, not once when they're written. Most teams cap the wrong thing. LangGraph has a recursion limit and the OpenAI Agents SDK has a max turns setting, and both count steps. A step can weigh 500 tokens or 80,000, so a ten-step cap tells you almost nothing about the bill. The other common guard is a dollar limit, which the provider enforces at the account level and which fires after the money is gone. The unit that matches how you're charged is tokens, set per task, then divided into slices you can cap one at a time. An agent loop is stateless on the provider's side. Each call sends the system prompt, the tool definitions and everything that happened so far. Step 12 pays for steps 1 through 11 all over again. Anthropic's engineers made the scale visible when they described their multi-agent research system: agents use about four times more tokens than a normal chat, and multi-agent setups about 15 times more. The team behind the Manus agent wrote in a widely read post on context engineering that the average input-to-output ratio in their agents is around 100 to 1. Output is what you write. Input is what you re-read. The second number is where your money goes. How to Reduce MCP Tool Definitions Token Usage Before Your Agent Starts https://startupfortune.com/how-to-reduce-mcp-tool-definitions-token-usage-before-your-agent-starts/ An Anthropic setup with five MCP servers used 58 tools and roughly 55,000 tokens before the conversation started, with GitHub alone at about 26,000 tokens for 35 tools. Anthropic has seen definitions reach 134,000 tokens and says Claude's tool selection degrades beyond 30 to 50 tools. A May 2025 RAG-MCP paper reported 43.13% accuracy with... - how to reduce MCP tool definition tokens https://startupfortune.com/how-to-reduce-mcp-tool-definitions-token-usage-before-your-agent-starts/ - audit MCP servers for token usage https://startupfortune.com/how-to-reduce-mcp-tool-definitions-token-usage-before-your-agent-starts/ Run the arithmetic on one bad moment. At step 3 of a 14-step run, your search tool returns a 20,000-token page. That result is now in the context for calls 4 through 14, which is 11 calls, so you pay for 220,000 input tokens to carry one result. The model probably needed two paragraphs from it. Prompt caching softens this but doesn't fix it. Anthropic prices cache reads at a tenth of the normal input rate, which is a real saving when the prefix stays stable. It does nothing for the context window itself, and it does nothing the moment you edit something early in the history. Treat caching as a discount on a budget, never as a replacement for one. A 200,000-token budget for one agent task Pick a ceiling for the whole task. I'll use 200,000 billed tokens, input and output together, and the split below is a starting point you should adjust after your first week of logs, not a law. One accounting rule makes the whole scheme work: a token is charged to the slice that created it, and it's charged again on every call it stays in. That's how you see tool output for what it costs. Here's the split. System prompt and tool definitions get 10%, or 20,000 tokens. Planning gets 10%. Retrieval gets 20%, which is 40,000. Tool output gets 35%, or 70,000. Retries get 10%, and the last 15%, 30,000 tokens, stays untouched as a reserve for the final answer and for the one surprise you didn't plan for. The system slice is the dullest and the easiest to shrink. Tool definitions are re-sent on every call, and an agent wired to 40 tools carries all 40 whether the task needs two or not. Load only the tools a task type uses, and keep that block byte-identical between calls so it caches. Planning is cheap if you let it be. Ask for one plan up front, cap the call with max tokens at a figure like 1,500, and re-plan only when a step fails. Agents that re-plan on every turn pay for the same reflection ten times and rarely get a better plan out of it. Retrieval is where people overspend quietly, because each individual call looks small. Five chunks of about 500 tokens is 2,500 tokens per query. Let the agent run 16 queries and you've spent the whole 40,000, before counting how long those chunks stay in the context. Cap the number of chunks, cap the chunk size, rerank so the five you keep are the best five of fifty, and cap the number of queries per task at something like eight. Why Does My AI Coding Agent Bill Keep Increasing Overnight https://startupfortune.com/why-does-my-ai-coding-agent-bill-keep-increasing-overnight/ Why does my AI coding agent bill keep increasing when nobody touched the keyboard overnight? Usually it's a runaway tool-call loop compounding token costs with every retry. This guide walks through the mechanism, a real incident involving Replit's agent, and the specific guardrails that stop it. - why AI coding agent bills spike overnight https://startupfortune.com/why-does-my-ai-coding-agent-bill-keep-increasing-overnight/ - preventing runaway tool call loops in agents https://startupfortune.com/why-does-my-ai-coding-agent-bill-keep-increasing-overnight/ Cap tool output first, because that's where the budget leaks Give tool results the biggest slice, then make them small. A hard ceiling of about 3,000 tokens per result, enforced in your tool wrapper and not left to the model's good manners, changes the math from the earlier example. A 3,000-token result carried through 11 calls costs 33,000 tokens, not 220,000. Truncation alone is lossy, so pair it with a handle. When a result is cut, return the first slice plus a short note saying how many tokens were dropped and how to ask for a specific range, a filter or the next page. Anthropic's engineering team, writing about how to build tools for agents, describes adding pagination, range selection, filtering and truncation with sensible defaults for this reason. The agent asks for more only when it needs more, and most of the time it doesn't. The big tools already do some of this. Claude Code caps tool and MCP output at 25,000 tokens by default and lets you lower the limit with an environment variable. That default protects a single call from blowing up. It's far too generous for a task budget, since a few results at that size would swamp the entire 70,000-token slice. Old results can also be cleared once they've done their job. Anthropic's context editing feature for the Claude API removes stale tool results when the context crosses a threshold you set, and the company reported an 84% cut in token use in a 100-turn web search evaluation. If your provider doesn't offer that, do it yourself: after the agent has used a result, replace it in the history with a one-line summary and keep the full text in storage. Tool output also tends to be the messiest data an agent sees. Raw HTML, full JSON with 60 fields when the model needs three, a stack trace with 200 frames. Strip it at the wrapper. Return the three fields. Retries and the reserve Retries cost more than they look like they should, because the failed attempt usually stays in context while the second attempt gets added on top of it. Two bad calls in a row, each with a big error payload, can eat 10,000 tokens without producing anything. Three rules fix most of it. Allow two retries per tool call and no more. When a call fails, keep one line in the history, such as the tool name, the arguments and the error message, and drop the failed output. And detect repeats: if the agent issues the same call with the same arguments twice, stop it, because a third try won't behave differently. Give the whole task a retry pool of about 20,000 tokens so one flaky API can't spend the retrieval budget. The reserve is the part teams skip, and then the agent runs dry mid-answer and returns half a sentence. Don't let any other slice borrow from it. The final answer, plus a short summary of what was done, comes out of that 30,000 and nothing else. Enforce it with a ledger and three thresholds A budget you only describe in a document won't hold. Keep a small ledger object in the loop that records, per slice, the tokens spent so far. After every model call, read the usage figures the provider returns and update it. Before sending a large payload, such as a retrieved bundle or a tool result you're about to append, count it first. Anthropic offers a token counting endpoint, and for other models a local tokenizer is close enough to catch a 20,000-token surprise. Then give the ledger three thresholds on the cumulative total. At 70%, inject a short instruction telling the agent to stop exploring and move toward an answer, and clear stale tool results. At 90%, switch to wrap-up mode: no new retrieval, no new tools, write the answer from what's already in hand. At 100%, stop the loop and return partial results with a plain statement of what wasn't finished. A hard stop that returns something is better than a soft limit that the agent talks itself past. Set max tokens on every call as well, not just on the planning step. Without it, a single rambling response can use a slice's whole allowance in one go. Keep your dollar cap and your iteration cap too. They're coarse, but they catch the failures your ledger can't, like a bug that starts a thousand tasks. The token budget is the fine control and the other two are the fence at the edge of the property. To start, don't build all of this at once. Pull one expensive run from your logs, sort its calls by input tokens and find the largest tool result. Put the 3,000-token cap on that tool tonight, then set the other slices from what the logs show next week. Also read: How to Recognize Revenue From Prepaid AI Credits Before Your Audit https://startupfortune.com/how-to-recognize-revenue-from-prepaid-ai-credits-before-your-audit/ • How to Reduce MCP Tool Definitions Token Usage Before Your Agent Starts https://startupfortune.com/how-to-reduce-mcp-tool-definitions-token-usage-before-your-agent-starts/ • The ACH Return Rate Threshold for Unauthorized Returns Is Just 0.5% https://startupfortune.com/the-ach-return-rate-threshold-for-unauthorized-returns-is-just-05/ This article is posted in AI News https://startupfortune.com/category/ai/ , check it out for more related stories. Join the discussion Open in the community → https://startupfortune.com/community/ Almost there. Sign in and your reply posts straight away.