Design for graceful failure
Diseña para el fallo elegante
When something breaks, return retry logic, an alternate path, and a clear message the agent or user can act on.
Why
Agents need recoverable errors, not dead ends. Speakeasy defines Recoverability as handling failures gracefully with retry logic, alternate paths, and user communication, and Anthropic's guidance on tools asks for error responses that communicate specific, actionable improvements rather than opaque error codes or tracebacks. MCP builds this into the protocol: tool execution errors come back flagged isError: true with feedback the model can use to self-correct and retry. An opaque 500 Internal Server Error ends the agent's workflow entirely. A structured error with retryable: true, retry_after_seconds, and an alternative path turns a failure into a recoverable state.
A source that returns nothing useful needs the same treatment as one that errors. Judged Useless, Queried Anyway (arxiv 2610.06191) ran seven agents against a retrieval source that kept failing. Where their judgments were recorded, the agents called the source's results useless 97 to 100 percent of the time, and most of them rarely stopped on that judgment. Stopping followed the evidence only when the harness made the agent answer after five consecutive useless results. The paper's remedy sits in the harness. The product-side reading is ours: return an explicit empty or degraded status instead of plausible filler, so the signal does not depend on the agent acting on its own judgment.
Do
Return a structured error plus a suggested next step, and an explicit empty or degraded status when a source has nothing useful to return.
Don't
Return an opaque 500.
Artifact
{
"error": {
"code": "rate_limited",
"message": "Too many requests.",
"retryable": true,
"retry_after_seconds": 30,
"alternative": "Use GET /v1/orders/export for bulk reads.",
"docs": "https://acme.com/docs/limits.md"
}
}
Citations
- [01]Speakeasy: Designing Agent Experience(opens in a new tab)
Recoverability: agents must handle failures gracefully with retry logic, alternate paths, and user communication
- [02]Anthropic: Writing Effective Tools for AI Agents(opens in a new tab)
Prompt-engineer error responses to clearly communicate specific and actionable improvements, rather than opaque error codes or tracebacks
- [03]MCP Specification 2025-11-25: Tools(opens in a new tab)
Tool execution errors are reported in tool results with isError: true and contain actionable feedback that language models can use to self-correct and retry with adjusted parameters
- [04]Zhang et al.: Judged Useless, Queried Anyway: Tool-Using Agents Rarely Turn Their Own Evidence Judgments into Stopping Decisions (arxiv 2610.06191, v1, 2026-10-05)(opens in a new tab)
Where we record their judgments, the seven agents we test call a failing source's results useless 97-100% of the time, yet most of them rarely stop on that judgment.
- [05]Zhang et al.: Judged Useless, Queried Anyway (arxiv 2610.06191, v1, 2026-10-05)(opens in a new tab)
Stopping follows the evidence only when the harness enforces an integration step that makes the agent answer after five consecutive results it judged useless.