Chapter 24: Failure and Recovery
Lecture
Chapter principle
Key takeaways
- Classify failure before selecting a recovery policy.
- Bound retries; use backoff for transient and capacity failures.
- Fallbacks help only when their failure modes are independent.
- Side-effecting retries need stable operation identity.
- Checkpoints preserve control state, and may need revalidation on resume.
- Keep recovery observable: reliability is a system property, not model accuracy.
Experiments
Every experiment in the book is small, runnable and printed with its real output. In the Lab you can replay a recorded real run of each one, with no programming, and watch what the model and the agent do.
Experiment 43: Retry, back off, fall back
When a call fails, when should the agent try again?
A retry policy wraps a real model call that asks for the capital of Peru. A provider cannot be made to time out on demand, so timeouts are injected before the real call. A timeout counts as temporary: the policy waits a little longer each time and tries again, up to 3 attempts. A request for a model that does not exist is permanent: the provider refuses it, and the policy stops at once. Four cases are tried: two timeouts then success, a permanent error, an outage with a fallback to a smaller real model, and an outage without one. This is a recorded run; the waits are partly random.
Experiment 44: Retrying a payment safely
If a payment’s reply is lost, is it safe to send it again?
A real agent has a payment tool. The user asks it to charge a customer 100 dollars. The payment server charges the card, but the reply is lost on the way back, so the agent sees only a timeout. The user then says "Please try again." The conversation runs twice: once plainly, and once with an idempotency key attached by the tool, a label that says "this is the same payment as before", so the server can recognize the repeat. This is a recorded run of a real model; a new run may differ.
Experiment 45: Checkpoint and resume
After a crash, can a long task pick up where it left off?
A five-step task (retrieve, analyze, draft, verify, submit) where every step is a real model call. After each step it saves a checkpoint: a small file recording how far it got and which version of the source data it used. It crashes during the fourth step and is started again. Then the same thing happens, but this time the price in the source changes from 80 to 90 while the task is down. The crash is simulated. This is a recorded run of a real model; its wording will differ in a new run.
All the code for this chapter: github.com/agentic-engineering-book/code
Download the bookBrowse all chapters