Skip to content

Conversation

@dbschmigelski
Copy link
Member

Description

Adds a retry field to AfterToolCallEvent that allows hook callbacks to trigger tool re-execution. When
set to True, the tool executor discards the current result and invokes the tool again with the same
tool_use_id.

This provides the hook infrastructure needed for implementing custom retry strategies for tool
failures, timeouts, or transient errors.

Changes

  • Add AfterToolCallEvent.retry: bool = False field
  • Add retry loop in tool executor that checks after_event.retry after each tool call
  • Use getattr(after_event, "retry", False) to maintain compatibility with BidiAfterToolCallEvent

Streaming behavior

When retry=True:

  • ToolStreamEvents (intermediate) are emitted immediately and visible from ALL attempts
  • ToolResultEvent is only emitted for the final attempt

Callers consuming streamed events should be prepared to see intermediate events from discarded
attempts.

Related Issues

#1405

Documentation PR

Todo

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

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Add `retry` field to AfterToolCallEvent and BidiAfterToolCallEvent that
allows hook callbacks to trigger tool re-execution. When set to True,
the tool executor discards the current result and invokes the tool again.

This provides the hook infrastructure needed for implementing custom
retry strategies for tool failures, timeouts, or transient errors.
Add tests verifying:
- AfterToolCallEvent.retry field is writable
- Setting retry=True causes tool re-execution
- Retry works with error results from @tool decorator
- Retry works with exceptions from tool.stream
- Max retries can be controlled by hook callback
- Integration tests with real Agent using HookProvider
Keep the first PR focused on standard AfterToolCallEvent only.
BidiAfterToolCallEvent.retry can be added in a follow-up if needed.
- ToolStreamEvents ARE emitted from discarded attempts
- ToolResultEvent is NOT emitted for discarded attempts
@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

❌ Patch coverage is 85.96491% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/strands/tools/executors/_executor.py 85.45% 5 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant