Phase 2: Tool Design & Function Calling · 55 min · Python · asyncio · Tenacity
Error Handling in Tool Execution
An agent that crashes is useless. An agent that handles errors gracefully is production-ready.
Hiring signal: Production agents fail — APIs go down, rate limits are hit, data is missing. Engineers who have built resilient tool executors and can explain their error taxonomy and retry strategy are demonstrably experienced with production systems. This is a common system design interview topic: 'How would you handle API failures in your agent?'
What you will learn
- Implement retry logic with exponential backoff for transient failures
- Return structured error information to the model so it can reason about failures
- Design fallback strategies: cached data, degraded responses, graceful escalation
The Problem
An agent calls your get_flight_prices tool. The airline API is down. Without error handling, the agent crashes and the user sees a 500 error. With good error handling, the agent catches the failure, explains it to the model, and the model responds: "I couldn't retrieve live prices right now — here's what I know from cached data." The agent loop continues. The user experience is preserved.
The difference isn't in the model — it's entirely in how your tool executor handles failures.
Error Taxonomy for Tools
Not all errors are created equal. The correct response depends on the error type. Build your tool executor around this taxonomy:
| Error Type | Example | Correct Response |
|---|
| Transient | 429 rate limit, 503 temporary outage, network timeout | Retry with exponential backoff |
| Client error | 400 bad input, 401 unauthorized, 404 not found | Return structured error, let model handle — do NOT retry |
| Partial success | Got 3 of 5 records before timeout | Return what you have with a partial_response note |
| Unrecoverable | Implementation bug, data corruption, 500 internal error | Surface to human, do not retry |
The most important distinction: transient errors should be retried; client errors should not. Retrying a 404 wastes time. Retrying a 429 without backoff makes your rate limit problem worse.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Retry Patterns, Returning Errors to the Model, Build It, What to Practice — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy