The short version
- Classify first: transient, permanent, ambiguous, or a success that is wrong or empty.
- The harness retries transport. The model fixes arguments. A write is replayed with a key.
- Back off with jitter, a budget and Retry-After. An illustrative cap is 3 attempts.
- An MCP error the model can read sets isError. A JSON-RPC error is a protocol failure.
- Stop a repeated call, and stop sooner after a permanent error. Then compare task success.
What is a tool error on an agent?
A tool error is a failed, empty or uncertain result the loop must classify before the next call.
A failed tool call is not a reason to call it again. It is a class of result, and each class has one owner. Timeouts, 429s and 5xx responses can be retried by the harness, inside a budget. Other results are a validation error, an auth error, or a write that may already have landed. Do not send these again unless a stored key can return the first result.
This is for agent engineers, and for anyone who owns an agent already in production. The contact example asks update_contacts for 9 contacts and gets 3 written and 6 skipped. Counts below are illustrative, not a measurement and not a customer result.
Short answer. Retry a timeout, a 429 or a 5xx in the harness, with jitter and a budget. Hand a bad argument to the model. Replay a write with a key the harness derived. Stop on a repeated call or a permanent error. An MCP error the model can use sets isError: true. A JSON-RPC error is a different object.
Four classes cover what a loop sees. Mix them and the policy either gives up on a blip or applies a write twice.
| Class | What it looks like | Next action |
|---|---|---|
| Transient | Timeout before the request is sent, connection reset, 429, 500, 502, 503 | Harness retries the same call, inside the budget |
| Permanent | 401, 403, 404, a schema failure, an unknown tool | Do not retry. Change arguments only if the text names a field. Otherwise stop |
| Ambiguous | Timeout or a dropped connection after the request may have left | Replay the idempotency key. Do not start a second write |
| Semantic | isError: false or HTTP 200, with an empty list or 3 of 9 written | The model reads the body. This is not a transport retry |
update_contacts can return success, write 3, and skip 6. Calling it again does not finish the 6. That body wants a new argument or a message, not a timer. A silent failure is this row under a calm sentence. Read the body before the status code.
Where should a tool retry live?
Put transport retries in the harness, hide only idempotent reads inside the tool, and let the model fix arguments.
The harness, the tool and the model can each retry. Only one should. If all three do, one timeout becomes three calls, and a write becomes three writes.
Classify, then retry, repair, or stop
The harness owns transport. The tool may retry a read it can prove is safe to repeat. The model repairs arguments and reads a partial body. A write is retried only as a keyed replay.
| Owner | Retries | Cost | Fails when |
|---|---|---|---|
| Harness | Timeouts, 429s and 5xx, same arguments | Latency, and one extra call per attempt | The call was a write and no key was stored |
| Tool | Its own idempotent read, hidden from the model | Latency the trace will hide if you swallow it | The same helper also wraps a write |
| Model | Whatever the error text invites | Tokens, and a loop if the text says try again | It retries a 401, or a write, with new arguments that still fail |
A harness retry re-sends the tool call, not the prompt. A model retry re-sends the prompt and the error, then invents a new argument. Put the sleep in the harness and call the model once, with the final result.
update_contacts is not a read. A timeout after the request left may already have written 3 rows. Do not retry a write you cannot see. A tool may retry a read that returns the same rows, with its own cap. If that helper also wraps the write, take it off. A hidden write retry looks like a slow success and a duplicate.
How does backoff with jitter work?
Sleep a random slice of a growing cap, honour Retry-After, and stop when the retry budget is spent.
Equal spacing wakes every session together after a shared timeout. Jitter spreads that. Full jitter, from the AWS Architecture Blog post on exponential backoff and jitter, sleeps a random value from 0 up to a cap. The cap is the minimum of a ceiling and base × 2^attempt.
Settings here are illustrative, not a measured budget. Base 0.2 seconds, ceiling 8, attempts 0, 1 and 2. Caps are 0.2, 0.4 and 0.8 seconds, because 0.2 × 2^attempt stays under 8. They sum to 1.4. Each sleep is at most that cap, so three sleeps sum to at most 1.4 seconds. A uniform draw averages half the cap, so the mean wait is 0.7 seconds. Arithmetic, not a measurement. Call time is extra. This page did not measure it.
Retry-After replaces the draw. RFC 9110 allows seconds or an HTTP date. A past date means do not sleep. A delay past the cap, or past the sleep left, is cut to the smaller one. On these numbers a 5 second header becomes 0.8 seconds on the last attempt, because that cap is 0.8.
A retry budget is three fences, not one counter.
- Attempts. 3 tries, illustrative. The first is the attempt. The next two are retries. A fourth try does not leave the harness.
- Sleep. 2 seconds, illustrative, above the 1.4 second cap sum so the jitter fits. At 0 seconds left, stop, even if an attempt remains.
- The step budget. Each retry is a step. The caps in how to stop an agent from looping still apply. A retry is not a free lap.
The model cannot sleep. “Wait and try again” becomes another call at once. Put the clock in the harness. Log the class, the attempt, the sleep, and whether Retry-After won. A swallowed retry looks like a slow success.
How do idempotency keys work for agent tools?
Derive a stable key from the task and the step, store the result, and return it on replay.
Stripe’s idempotent requests store the first response and return it on retry. They suggest a random client id. Do not copy that. A model mints a new id every attempt, and a new key is a new write. The harness derives the key. The model never sees a field it can change.
Hash the task id, the step, the tool and the arguments. Sort object keys so argument order does not matter. If the task id is not stable yet, use the conversation id. A different list is a different task id, so a different key. The same call in the same step keeps the same key.
Store the key, the result and a deadline. A replay before the deadline returns the stored result and skips the write. Store failures too: a stored 500 comes back as that 500, so a second write does not start and then succeed. Stripe’s v1 API saves status and body the same way.
The sample TTL is illustrative: 3,600 seconds. until is 1,000 + 3,600 = 4,600. At 4,600 the write runs again. That is expiry, not a second retry. A new task id is a new key. Reusing the task id after the TTL does run the write again.
The sample runs the function, then stores. Overlapping calls would both write. Mark the key in progress first, and make the second caller wait.
On replay, return the stored body and a flag the log can see. If it says 3 written and 6 skipped, that is what the model gets. The key stopped the double write. It did not finish the 6. A second ask is a loop. The key protects the CRM. The guard protects the session.
This page ran the function. The print is 1 False True 3 6: one write, then a replay, written 3, skipped 6. The key on these inputs is idem_8188675d5460695d. A printed 2 means the write ran twice.
An idempotency store on an illustrative task that this page ran.
import hashlib, json
def idem_key(task, step, tool, args):
raw = json.dumps([task, step, tool, args], sort_keys=True, separators=(",", ":"))
return "idem_" + hashlib.sha256(raw.encode()).hexdigest()[:16]
class IdemStore:
def __init__(self, ttl, now):
self.ttl, self.now, self.rows = ttl, now, {}
def call(self, key, fn):
row = self.rows.get(key)
if row and self.now < row["until"]:
return {**row["value"], "replayed": True}
value = fn()
self.rows[key] = {"value": value, "until": self.now + self.ttl}
return {**value, "replayed": False}
writes = {"n": 0}
def write():
writes["n"] += 1
return {"written": 3, "skipped": 6}
store = IdemStore(3600, 1000)
key = idem_key("task-9", "update", "update_contacts", {"ids": ["c1", "c2"]})
a, b = store.call(key, write), store.call(key, write)
print(writes["n"], a["replayed"], b["replayed"], b["written"], b["skipped"])
c1 and c2 are placeholders. written: 3 is the running example’s partial, so the replay is obvious. The clock is an argument. A production store uses its own clock, a lock, and a TTL you wrote down.
What should an MCP tool error tell the model?
Return a tool result with isError set, and say whether to retry, change the arguments, or stop.
The tools page of the MCP specification, revision 2025-11-25, read on 1 Dec 2026, splits failures in two. A tool execution error is a tools/call result with isError: true and the reason in content: API failures, bad input, business-logic errors. A protocol error is a JSON-RPC error: an unknown tool, a request that fails the CallToolRequest schema, or a server error. The page’s example uses code -32602 and “Unknown tool: invalid_tool_name”. No result means no isError.
Clients should give isError: true to the model. They may forward a protocol error, which the page says is less likely to be repaired. Dropping the tool result hides the message the model can use. The text names one next action. Naming retry, change and stop in one paragraph is how a 401 gets retried.
| Next action | When | What the harness does |
|---|---|---|
| Retry | Timeout, 429 or 5xx, and the text says retry once | Sleep, then the same arguments, until the budget ends |
| Change | A named field is wrong, and the text gives the allowed value | Do not sleep. Pass the text to the model. Do not replay the same arguments |
| Stop | Auth, not found, or the text says do not retry | Do not call again. Tell the person what already landed |
An illustrative validation result, not a recorded server, names the tool, the field, the value to use, and the ban on a same-argument retry.
Illustrative tool result, isError true
{
"jsonrpc": "2.0",
"id": 4,
"result": {
"content": [{
"type": "text",
"text": "update_contacts: match_by email is not allowed. Use name_and_company. Do not retry these arguments."
}],
"isError": true
}
}
A protocol error means the client called a name that is not on the list. Retrying will not create the tool. Show it to the model only when a different name might be right. Otherwise stop.
Illustrative JSON-RPC error, not a tool result
{
"jsonrpc": "2.0",
"id": 3,
"error": { "code": -32602, "message": "Unknown tool: update_contact" }
}
Do not put a stack trace, a token, or “something went wrong” in content. Name the field and the verb. “Not authorised for this account. Stop. Tell the person.” is complete. “Please try again” on a 401 burns the step budget.
A description that says to retry every error is a design bug. How to test MCP tool design scores the pick, the arguments and the extra calls. Re-run it before a description change, and include a 401, a bad field and a partial success. The call log is MCP observability. isError: false with 3 rows written is still the semantic class.
How do you stop an agent that keeps calling a failing tool?
Hash the tool and the arguments, and open a circuit when that signature, or a permanent error, repeats.
A retry policy without a stop is a loop. Four signatures need different counters. Comparing a call only with the previous one misses two of them.
- Same tool, same arguments. Hash the call with its arguments, sorting object keys but keeping list order. An illustrative limit is 3: the first call is the attempt, the second can be a retry, the third is the loop.
- Two tools, alternating.
find_contacts, thenupdate_contacts, thenfind_contacts. The identical-call hash stays quiet. The no-progress check in the loop playbook catches it, because the written set does not change. - A retry after a permanent error. The harness does not retry a 401 or a schema failure. If the model asks again, stop on the second call, not the third. An illustrative limit of 2 is stricter than the timeout limit because the text already said the call cannot succeed.
- New arguments, same tool, still failing. The model changes
match_byand the new value is rejected too. After an illustrative 4 failures of that tool name in the session, stop calling it and tell the model the tool is closed for this task.
Those limits are illustrative. They are not a measured budget, and not a threshold from the contact example’s attempts. A poll that should repeat needs its own tool, or a hash that includes a progress field. A guard that cannot tell a status read from a stuck write stops a task that was moving.
Which part of the agent is failing splits two causes of the same second call: no guard, or a description that says to retry. Change the description first if the text invites the repeat. If it remains, add the guard. Shipping both at once leaves the finish rate unable to say which one worked.
Say “3 contacts updated, 6 skipped, and the same call will not change that.” Do not return the exception. The trace sees the hash. The person shows a correction, a repeated intent, or no further turn. This page only decides which errors may spend a retry before the repeat guard and the step budget.
When should you not retry a tool call?
Skip the retry on a permanent error, on an unknown write, and on a result the model should change.
- Three owners at once. Tool, harness and model. One timeout becomes three calls. Keep one owner.
- A permanent error, retried “to be safe”. A 401 does not become a 200 because you waited. Stop, and tell the person.
- A write you cannot see, and no key. The timeout may already have landed. Add the key, or do not retry.
- Backoff in the prompt. The model cannot sleep, so the sentence becomes an immediate second call.
- A key the model invents. A new random id on each attempt defeats the store. Derive the key in the harness.
- A hidden retry. If the trace skips the attempt, a blip, a loop and a second write all look the same.
- An unpriced retry. No token or cost figures were measured for this guide. A model retry re-sends the prompt. A harness retry does not. Know which one you are paying for.
A stronger model does not retire the guard. A description that says “retry on any error” still has one legal reading, and a careful model will take it. The fences stay in the harness.
How to tell it worked
Repeated failures of that tool drop, the write runs once, and task success on that task moves.
Search for repeated failures of update_contacts. A tool event can match even when the person left no complaint. Open the annotated replay: topic, task, intent and signals stay on that turn. Dissatisfaction, a repeated intent, or abandonment after the error is the loop the person felt.
Change one thing. Add the key, or add the stop, not both. After the key, a second call with the same task, step, tool and arguments is a replay. The write counter stays at 1, as the sample prints. After the stop, the third identical call does not run, and the person hears 3 updated and 6 skipped.
The workspace holds that search, the labels and the replay. Read the turns behind the failure there. The feature list names tool events, task progress, user corrections, repeated intents and sentiment on the person’s turns. Abracadabra does not run the retries, and it does not host the tools.
This page did not measure a production before and after. The sample shows one write, then a replay. In conversations the person stops correcting that call, and the task finishes. A green budget with the same abandonment missed the step that stopped them.
What should you do first?
Classify one failing tool, put the retry in one place, and compare task success after that single change.
- Pick one tool that fails in real sessions. Label each failure transient, permanent, ambiguous or semantic.
- Give transport retries to the harness. Give argument repairs to the model. Let the tool retry only a read.
- Cap attempts and sleep, add full jitter, and honour Retry-After inside the cap. Count each retry as a step.
- Derive the idempotency key in the harness. Return the stored result on replay, including a stored error.
- Make the error text say retry, change, or stop. Stop the loop on a repeated call, sooner if the error was permanent.
- Compare task success on that task with the previous period, after one of those changes, not after all of them.
Common questions about agent tool retries
These are the questions people ask when a tool error turns into another call.
How do you retry a failed agent tool call?
Sort the failure into its class first. Transient failures go back through the harness with backoff and a cap. A bad argument goes to the model, and a write repeats only when its idempotency key is already on record. The table in the first section names the owner of each class.
Should the model decide when to retry a tool?
Only when the error text says to change the arguments or to stop. Transport retries belong in the harness. A model that retries every error spends tokens and can apply a write twice.
What is an idempotency key for an agent tool?
A key the harness derives from the task, the step, the tool and the arguments. The server stores the first result and returns it when the same key arrives again, so the write does not run twice.
What is an MCP isError tool result?
A normal tools/call result with isError set to true and the reason in the content. It is not a JSON-RPC error. The model can read it and change course. An unknown tool is a JSON-RPC error instead, and the model is less likely to repair that.
Why does an agent keep calling a failing tool?
The error text says to try again, the harness retries with no budget, or nothing counts a repeated call. A repeat guard stops the identical call. A permanent error should stop sooner than a timeout.