feat(prebuilt): add support for handle_tool_errors with single exception type (#6021)

This PR extends the `ToolNode` `handle_tool_errors` property to also
accept a single exception type: `type[Exception]`.

Example:
```python
tool_node_with_error_handling = ToolNode(
    [tool1, tool2, tool3], handle_tool_errors=ValueError
).invoke(...)
"""A tool node that will only retry a failed tool call if a ValueError is raised"""
```
This commit is contained in:
Caspar Broekhuizen
2025-08-26 18:49:55 -04:00
committed by GitHub
parent b36b7e2730
commit 4eaab0284a
2 changed files with 29 additions and 9 deletions
+2
View File
@@ -274,10 +274,12 @@ async def test_tool_node_error_handling() -> None:
# test catching all exceptions, via:
# - handle_tool_errors = True
# - passing a single exception
# - passing a tuple of all exceptions
# - passing a callable with all exceptions in the signature
for handle_tool_errors in (
True,
Exception,
(ValueError, ToolException, ToolInvocationError),
handle_all,
):