Retries with Exponential Backoff
Use tenacity to retry transient failures with exponentially-increasing delays and jitter.
Why Retries?
External calls (LLMs, search APIs, vector DBs) fail transiently. A simple retry recovers from most flakes without bothering the user.
What NOT to Do
Do not retry instantly in a tight loop — you will hammer the service and the rate-limiter will lock you out:
# BAD
for _ in range(10):
try:
return call_api()
except Exception:
passAll lessons in this course
- Idempotent Tools and Side Effects
- Retries with Exponential Backoff
- Timeouts and Circuit Breakers
- Validating Tool Outputs (Pydantic)