Track 03 · Agents & toolsLesson 09 of 12
Retries, fallbacks and failing gracefully
Design for the model being wrong, slow or down, and keep the work moving.
- The FDE path · Stage 4 of 6
- 40 min read
- 60 min hands-on
- Pro
What you'll be able to do
01- Classify agent failures (model, tool, loop, context, credential) and choose a handling strategy for each class.
- Implement retries with capped exponential backoff and full jitter that retry only retryable errors, honour
Retry-After, respect a deadline and draw from a retry budget. - Design idempotent writes and deadlines that propagate across steps, so retries never duplicate side effects or blow the SLA.
- Build a circuit breaker and a fallback chain, and degrade in a way that tells the user what happened.
- Prove resilience with fault injection, including the build's criterion: with the model endpoint disabled, new cases reach the nurse queue flagged manual intake within 5 minutes.
Before you start
- The agent loop, written by hand: stop conditions, budgets and the three classes of tool error (model-fixable, transient, fatal).
- Designing tools a model can use well: actionable error returns and idempotent write tools.
- Typed output: schemas, validation and tool calls: validating and repairing invalid model output.
- Tools with scoped, auditable access: credentials fetched at the tool, and token refresh.
- Workflows that survive restarts comes next in the README's order. It places the retry policies designed here on Temporal activities so they survive crashes.
The short version
The model can be wrong, malformed, refusing, slow, rate-limited or down, and every tool behind it can fail too. Handle each class deliberately. Retry only what a retry can fix (timeouts, connection errors, rate limits, overload) with capped exponential backoff and full jitter, never earlier than Retry-After, never past the deadline, never beyond a retry budget, and in exactly one layer. Make writes idempotent, because a timed-out write has an unknown outcome. Put a circuit breaker in front of each dependency so a dead endpoint costs milliseconds per request, not minutes. Fall back down a chain (smaller model, deterministic path, human) where each step is less autonomous than the last, and tell the user which path produced the result. Prove it with fault injection before the customer's outage does.
Key takeaways:
- Classify on the error body, not only the status: a 429 can be "slow down" or "you are out of credit".
- Full jitter spreads retries;
Retry-Aftersets a floor; the deadline and the retry budget set a ceiling. - One retry layer. SDK retries inside your retries inside workflow retries multiply load on a failing service.
- A fallback must lower autonomy, not just keep the lights on: a weaker path produces a flagged result for a human.
- Degradation is a feature with acceptance tests, not an absence of errors.
Practise this in the lab
Pro lesson
The rest of this lesson is in Pro.
The mental model, worked example, field note, failure table, exercise and self-check, with the voice tutor.
Pro opens this stage
Stage 4 · Agents that act safely- 7 lessons, with the voice tutor
- Lab · Find the intake agent's failed writes, graded here
Also in Pro
- Every stage and specialisation, in full
- Every lab and every role project
- Halden weeks 2–10, on your record
- Every drill, live in the playground
- All solutions, plus the server judge
- Lab Assistant and every Teach with AI