How does an AI Agent handle tool failures, timeouts, and retries?
Real APIs fail. Good agents fail gracefully.
Picture it first
You call your friend, but the line is busy. You wait a little and try again, then wait longer, then try again. After 3 tries you send a message instead. But if you were sending them money, you wouldn't press 'send' three times — you'd first check if the first one went through!
Now the same idea, in simple QA words
Real systems fail sometimes — they are slow, busy or return errors. A good agent: (1) waits a limited time, (2) tries again a few times, waiting a bit longer each time, (3) if it still fails, tells the truth to the user. Important rule: it's safe to retry reading data, but not to blindly retry actions like payments or bookings — they might happen twice.
How the story connects to the real thing
Real-world example
A refund agent calls process_refund and gets a timeout. A naive retry could refund the customer twice. The well-built agent uses an idempotency key, checks get_refund_status first, finds the refund already succeeded, and tells the customer it's done. For a read-only get_order call, it simply retries with backoff.
Step by step, in plain words
- Call the tool with a time limit.
- If it fails because it's busy/slow, wait and try again.
- Wait longer before each new try (max 3 tries).
- For payments/bookings: first check if the first try actually worked.
- If still failing, tell the user honestly.
- Log every failure.
How a tester tests it
- Fault injection: mock tools to time out, return 500/429, return empty or malformed data.
- Verify no duplicate side effects on retries (double booking, double payment).
- Verify the user-facing message is honest — the agent must not claim success after a failure.
- Check total wait time stays within the product's latency budget.
Try it yourself
1) For a 'book a meeting room' agent, list which tools are safe to retry and which aren't. 2) Write the exact message the agent should give the user if booking fails three times.
Interview angle
“What's the most dangerous failure mode when an agent's tool times out?”
Two: a duplicate side effect from blindly retrying a non-idempotent action, and a false success claim where the agent says 'done' even though the tool failed. I test both with fault injection and verify the external system's final state, not just the chat message.