Resilience and cost: retries, fallbacks, rate limits, caching
Notebook· 12.02· 2–3 h· Lesson 101 of 129
The notebook opens in your lab, in a new tab. If your server is stopped, it starts first (a few seconds).
By the end you can
- Classify provider errors as transient, permanent or bugs, and retry only the transient ones.
- Add retries with backoff (
ModelRetryMiddleware) and a fallback model (ModelFallbackMiddleware), and measure the success rate they buy, with intervals. - Throttle calls on the client side with
InMemoryRateLimiterso the service stays under the provider's quota. - Stop runaway tool loops with
ModelCallLimitMiddleware. - Cache where it is safe (exact model calls), and explain why caching agent answers is risky.
- Cut token cost with provider prompt caching (stable prefix first) and batch jobs, and report cost per model.
Before you start
Lesson 12.01 (SLOs and budgets), Module 03 (middleware) and Lesson 01.03 (mastery.evals.stats).
Python in this lesson
Python guideNew herepass
