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.

What you'll be able to do

What you'll be able to do

01
  1. Classify agent failures (model, tool, loop, context, credential) and choose a handling strategy for each class.
  2. 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.
  3. Design idempotent writes and deadlines that propagate across steps, so retries never duplicate side effects or blow the SLA.
  4. Build a circuit breaker and a fallback chain, and degrade in a way that tells the user what happened.
  5. 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

Before you start

The short version

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-After sets 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