feat: Propagate exceptions to AfterToolCallEvent for decorated tools (#1565)#1566
feat: Propagate exceptions to AfterToolCallEvent for decorated tools (#1565)#1566pgrayy merged 17 commits intostrands-agents:mainfrom
Conversation
zastrowm
left a comment
There was a problem hiding this comment.
Good implementation! Left some comments/requested-changes of the tests
|
Looks like there are also some linting failures; |
Yeah thats my bad, I optimistically tried to resolve conflicts in the UI. Should be good now |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
About the unit test assertion changes suggested -- ...though when it's the exact same object being returned we can use |
9b3609b to
87977ef
Compare
Co-authored-by: Arron Bailiss <arron@amazon.com>
…arams (strands-agents#1584) Co-authored-by: Dean Schmigelski <dbschmigelski+github@gmail.com>
|
Any further attention needed from my end here? |
Apologies, nothing else needed. Went ahead and merged. |
Description
Motivation
Hook providers need the ability to distinguish between expected errors (like validation failures that the model should adjust for and retry) and unexpected errors (like assertion failures or configuration errors that should fail the task immediately). Currently,
AfterToolCallEvent.exceptionis alwaysNonefor@tool-decorated functions because the decorator catches all exceptions and converts them to error results before the executor can see them. This forces all tool errors to be returned to the model, even when propagating the exception would be more appropriate.Resolves: #1565
Public API Changes
ToolResultEventnow accepts an optionalexceptionparameter, andAfterToolCallEvent.exceptionis populated for decorated tools:The error result is still returned to the model by default; hooks must explicitly re-raise if they want to propagate.
Use Cases
AssertionError,ConfigurationError, etc. instead of letting the model retry futilelyValueErrorto return to the model while propagating other exceptionsRelated Issues
#1565
Documentation PR
strands-agents/docs#482
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.