feat: add retry utility with exponential backoff#901
Open
surajsahani wants to merge 1 commit intomozilla-ai:mainfrom
Open
feat: add retry utility with exponential backoff#901surajsahani wants to merge 1 commit intomozilla-ai:mainfrom
surajsahani wants to merge 1 commit intomozilla-ai:mainfrom
Conversation
- Add retry_with_backoff decorator for handling transient failures - Support both sync and async functions automatically - Configurable exponential backoff with max delay cap - Selective exception handling for specific error types - Add RetryError exception for exhausted retry attempts - Include comprehensive test suite with 15 test cases - Add proper logging and type safety (mypy strict)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a robust retry mechanism with exponential backoff to help developers handle transient failures when working with LLM APIs and other external services in the any-agent library.
What Changed
src/any_agent/utils/retry.py: New retry utility module withretry_with_backoffdecorator andRetryErrorexceptionsrc/any_agent/utils/__init__.py: Export new utilitiestests/unit/utils/test_retry.py: Comprehensive test suite with 15 test casesFeatures
Why This Matters
When building AI agents that interact with LLM APIs, transient failures are common (rate limiting, network timeouts, temporary service unavailability). This utility provides a production-ready solution that improves reliability and reduces boilerplate error handling code.
Usage Example