Blog / Tool results and errors
Why agents call the same tool twice (13 of 40 runs) and how to stop it
Your logs show the agent calling the same tool with the same arguments twice in one task. It looks like a bug in the agent. In our runs it was mostly a reaction to the result: too big to read in one go, so the app cut it, and the model went back for it. Here's the evidence and how to make the first call enough.
What we saw
Same 99-tool production MCP server, same 8 read-only jobs, 5 runs each:
Codex's 13 duplicates were spread over 5 of the 8 jobs. Most were the main list tool called again with the same arguments or from the first page, plus a groups list called twice. Every answer in those runs was still correct; the cost was extra calls and bigger requests. Runs with duplicates had larger requests on average, about 52k vs 44k tokens.
Why it happens: the result didn't fit
The list tool's results ran up to about 57,000 tokens. Codex in code mode calls tools from JavaScript and prints what it wants to read, and it cuts printed output to about 10,000 tokens, keeping the start and end. So the model often saw a slice, then went back.
The clearest case was “what's new since yesterday?”. Codex called the activity feed with a limit of 200, printed it, and the print was cut (“original token count: 67,251”). It then called the feed again with the same arguments and filtered the events in code. That happened in 5 of 5 runs (57–100%). In a separate follow-up of 3 live runs with model traffic recorded, every whole list page was cut, and in 2 of 3 runs the recovery meant calling the server again.
Claude Code handles the same oversized result differently: it refuses results over 25,000 tokens and saves them to a file, and the model reads the file. That costs extra reads instead of repeated server calls. See MCP output limits by agent.
See where agents repeat calls on your server.
We run your users' jobs through Claude Code, Codex and the other apps they use, flag every repeated call, and trace it to the result that caused it.
Small results: no repeats
We counted repeats in our mock experiments, where every result was small: a made-up task tracker whose biggest default result was about 12,000 tokens. Across 90 runs in Claude Code, Codex and a small free model, 0 of 90 repeated a call with the same arguments (0–4%). Another 40 runs comparing MCP and a CLI: 0 of 40.
Agents did call the same tool more than once with different arguments, which is normal paging or filtering. That dropped as the tools improved: Claude Code 8 of 10 runs with the original server, 4 of 10 after the fixes; Codex 2 of 10 to 0 of 10; the small model 4 of 10 to 1 of 10.
This isn't a controlled test of size alone: the live server and the mock differ in more than result size. But it fits the live evidence: repeats followed results the app had to cut.
Go deeper: Reduce MCP tool response size, How Codex finds MCP tools, How much MCP output is waste.
How to stop it
- Make the default result small, ideally under about 5,000 tokens so it fits every app's cap. See how to reduce MCP tool response size.
- Put the answer summary first: counts and what's next. Codex keeps the start of a cut print.
- Add filters for common questions (by name, date, status), so the agent asks for the slice instead of fetching everything and filtering.
- Leave noise out by default: in that feed, 56 of 106 events were the agent's own calls.
- Return a cursor, so “more” is a new page, not the same call again.
- Count repeats in your tests: same tool and arguments twice in one run, per app.
All the rules for results: tool results and errors for AI agents.
How we measured
- Live: a 99-tool production MCP server, read-only through an allowlist proxy, 16 Oct 2026. Codex CLI 0.161.0 and Claude Code 2.1.301, 8 jobs × 5 runs each. A duplicate is the same tool with the same or first-page arguments twice in one run.
- Follow-up: 3 Codex runs with model traffic recorded, 16 Oct 2026; the “what's new” job, 5 runs.
- Mock: 130 runs on a made-up task tracker (Claude Code 2.1.304, Codex 0.161.0, OpenCode 1.18.34 with a small free model), 21 Oct 2026. A duplicate is the same tool with identical arguments twice in one run.
- Limits: one live server; ranges are 95% Wilson intervals; Codex's cut sizes are its own estimates.
FAQ
Why does my agent call the same MCP tool twice?
In our runs the main cause was result size. When a result is bigger than the app will show, the app cuts it, and the model calls again to get the part it needs, often with a filter in code. Codex did this in 13 of 40 live runs on a server whose list results reached about 57,000 tokens.
Is it the agent's fault or the server's?
Both play a part, but the server is what you control. The same Codex version made no exact repeats in 90 runs on a mock whose results were small.
Does a duplicate call double the cost?
Not always. In Codex code mode many repeats happen inside one code block, so the data enters the context once; they cost server time more than tokens. But in our runs, requests in runs with duplicates were larger on average (52k vs 44k tokens).
How do I stop duplicate tool calls?
Make the first result enough: a small default, a summary line with counts and what's next, filters for the questions users ask, and a cursor for more. Keep results under the smallest output cap of the apps your users run.
See where agents repeat calls on your server.
We run your users' jobs through Claude Code, Codex and the other apps they use, flag every repeated call, and trace it to the result that caused it.