Tenacity
Python retry library that wraps functions with configurable retry logic including exponential backoff, jitter, stop conditions, and custom wait strategies via decorators or context managers.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
No network layer; secure by default. No external calls, no credential handling.
⚡ Reliability
Best When
You need robust, configurable retry logic for LLM API calls, external HTTP requests, or transient I/O failures with minimal boilerplate.
Avoid When
You are retrying operations with side effects that are not idempotent and you have not implemented deduplication at the callee.
Use Cases
- • Wrapping LLM API calls (OpenAI, Anthropic) with exponential backoff and jitter to handle rate limit 429 errors gracefully
- • Retrying flaky external HTTP requests in agent tool calls without writing boilerplate retry loops
- • Implementing circuit-breaker-like patterns by combining retry limits with exception filtering for database connections
- • Adding retry resilience to agent subtask execution where transient failures should not abort the entire workflow
- • Retrying file I/O operations that may fail transiently due to filesystem locks or network mounts
Not For
- • Non-idempotent operations that must not be duplicated — retrying POST requests that create resources will cause duplicates
- • Permanent errors that will never succeed on retry — retrying auth failures or 404s wastes time without a meaningful exception filter
- • Async-heavy workflows where asyncio-native retry libraries like aioretry offer better integration without thread-blocking
Interface
Authentication
Local Python library, no auth required
Pricing
Apache 2.0 license
Agent Metadata
Known Gotchas
- ⚠ Default retry is infinite with no stop condition — always set stop=stop_after_attempt(N) or stop=stop_after_delay(seconds) to prevent runaway retries
- ⚠ retry=retry_if_exception_type must be specific or all exceptions including KeyboardInterrupt and SystemExit will be caught and retried
- ⚠ wait_exponential without jitter causes thundering herd when multiple agents retry simultaneously — always add wait_random_min/max
- ⚠ The @retry decorator reruns the entire function including any non-idempotent side effects that occurred before the failure point
- ⚠ reraise=True is not the default — without it, the final exception is wrapped in RetryError and original traceback context is harder to extract
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for Tenacity.
Scores are editorial opinions as of 2026-03-06.