Part 1 of 6 · 1 min read
Overview
In this module you will
- Decide which API errors are worth retrying, and write a retry loop with backoff, jitter and a deadline.
- Protect actions with idempotency keys so a retry cannot do the same thing twice.
- Explain and use a circuit breaker and a fallback chain.
- Test all of it without sleeping, by injecting the clock.
An agent run is many calls in a row, so the chance that something fails during a run is much higher than for a single request. At a 1% failure rate per call, a run of 20 calls hits at least one failure about 18% of the time (1 - 0.99^20). Without a plan, those failures abort runs or, worse, repeat a side effect such as sending an email twice.
About the examples
The code uses a fake API that replays a script of outcomes (503, 429, a timeout, then success) and a fake clock, so the timing logic is tested exactly and instantly. Real providers differ in status codes and in how they signal a retry delay, so read your provider's error documentation. No real network call was made.