generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 608
feat: allow hooks to retry model invocations on exceptions #1405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zastrowm
merged 10 commits into
strands-agents:main
from
zastrowm:let_hooks_retry_model_calls
Jan 2, 2026
Merged
feat: allow hooks to retry model invocations on exceptions #1405
zastrowm
merged 10 commits into
strands-agents:main
from
zastrowm:let_hooks_retry_model_calls
Jan 2, 2026
Conversation
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
Add retry_model field to AfterModelCallEvent that enables hook providers to retry model invocations when exceptions occur. This provides flexibility for users to implement custom retry logic for any exception type. - Add retry_model: bool field to AfterModelCallEvent (default False) - Implement _can_write() to allow hooks to modify retry_model - Update _handle_model_execution() to check retry_model and retry when set - Hook retries integrate with existing ModelThrottledException retry logic - Hook retries respect MAX_ATTEMPTS limit - Add comprehensive test coverage for retry scenarios Resolves #9
Hooks should be able to retry without framework-enforced limits. Removed the attempt count check that artificially limited hook retries. Hooks now control their own retry logic within the loop iterations.
Reasoning: This will unlock use cases where folks want to re-trigger the model due to other reasons (like steering).
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Unshure
previously approved these changes
Dec 31, 2025
dbschmigelski
previously approved these changes
Dec 31, 2025
Unshure
approved these changes
Dec 31, 2025
dbschmigelski
approved these changes
Dec 31, 2025
zastrowm
added a commit
to zastrowm/docs
that referenced
this pull request
Jan 2, 2026
Now that strands-agents/sdk-python/pull/1405 is implemented, go ahead and add docs about how to use it. Expand the section to detail all writable properties.
This was referenced Jan 2, 2026
zastrowm
added a commit
to strands-agents/docs
that referenced
this pull request
Jan 2, 2026
Now that strands-agents/sdk-python/pull/1405 is implemented, go ahead and add docs about how to use it. Expand the section to detail all writable properties. --------- Co-authored-by: Mackenzie Zastrow <zastrowm@users.noreply.github.com>
7 tasks
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
Users need the ability to retry model calls on arbitrary exceptions beyond just
ModelThrottledException, and also retry based on response validation. This feature adds a low-level mechanism that enables that and more by letting hooks implement custom retry logic for both exceptions and successful responses.Public API Changes
New Field:
AfterModelCallEvent.retryHook providers can now set
retry=Trueto retry model invocations on both exceptions and successful calls:The
retryfield is writable within hook callbacks and defaults toFalse. It can be set for both successful calls (to validate response content) and failed calls (to retry exceptions).Use Cases
Implementation Notes
Hook Retry Integration
For now, hook-initiated retries work alongside the existing
ModelThrottledExceptionretry mechanism. If we implement #527 or #283, we should see if we can migrate the existing retry logic to be a hook instead of the current hard coding.No Framework-Enforced Limits
The framework doesn't enforce retry count limits or delays for hook-initiated retries - hooks manage their own state and logic. This provides maximum flexibility while keeping the framework simple.
Related Issues
#370, #1386
Documentation PR
After approval of this PR, will generate the documentation PR
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.