How AI Agents Handle Errors and Edge Cases
Your agent doesn't fail because the model is dumb. It fails because nobody decided in advance what happens when things go wrong — and in production, things go wrong constantly. A tool times out, the model invents a function argument, an instruction means two things at once, and your agent, built for the happy path, improvises its way into a wrong refund.
The uncomfortable truth in this one: a chatbot's bad answer ends the turn. An agent's bad step triggers more actions. A wrong lookup becomes a wrong payment. Error handling isn't a feature you bolt on — it's the difference between a demo and a system that survives its thousandth run.
Classify first, retry second
The first job is classification, not recovery. LangChain's fault-tolerance docs split it three ways: transient failures get retried, model-recoverable errors get fed back to the model, and anything needing a person pauses the agent. One generic retry loop can't do that job — and a study of 900+ agent traces found the failures compound exactly because the loop around the model is where things break: premature action without grounding, over-helpfulness under uncertainty, context pollution.
A 429 is not always a "wait and retry"
Here's the detail vendors won't put in their marketing: Anthropic's own docs show a 429 rate-limit means back off and retry — but a 429 with a spend-limit code means the monthly cap is hit and the run should stop and tell a human. Same status code, opposite responses. A 500 gets retried with backoff; a 504 on a side-effecting call must be reconciled first, or you charge the customer twice. If your agent reads status codes instead of the provider's error contract, it's guessing.
Retries that actually help — and the ones that burn money
Bounded retries, exponential backoff, and one rule most teams ignore: change something on retry, or don't retry at all. A model that produced invalid JSON will happily produce it again. The arithmetic is brutal — retrying a deterministic failure four times quadruples cost and latency for a success probability near zero. And the failures you should never retry at all: a 400 means the request itself is broken, a policy refusal is a decision, not a glitch.
The escalation line is a design choice, not a failure
Escalation isn't admitting defeat — it's the designed endpoint. Low-risk work retries and reports afterwards; payments, deletions, messages to customers need a person first. The numbers back the caution: in a September 2026 follow-up, 80% of organisations that let agents skip human review for low-risk changes reported an agent that passed internal evaluations and then failed in front of a customer, versus 36% of those that required review. Correlation, not proof — but a correlation worth designing around.
Go deeper
Read the full guide on Agentic Affairs: How AI Agents Handle Errors and Edge Cases
Originally published on Agentic Affairs (https://agentic-affairs.com)
原文:https://www.a8q9.cn/en/article/how-ai-agents-handle-errors-and-edge-cases-28acca.html