Let HookToolset retry a failed tool call instead of failing the task - #71853
Open
ColtenOuO wants to merge 1 commit into
Open
Let HookToolset retry a failed tool call instead of failing the task#71853ColtenOuO wants to merge 1 commit into
ColtenOuO wants to merge 1 commit into
Conversation
A hook method call from an LLM tool invocation — bad arguments from the model, a transient network error — aborted the whole agent run instead of giving the model a chance to correct itself, unlike SQLToolset, DataFusionToolset, and SandboxToolset, which already retry through pydantic-ai's ModelRetry.
ColtenOuO
requested review from
Lee-W,
ashb,
gopidesupavan and
kaxil
as code owners
August 19, 2026 20:35
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.
Summary
Follow up: #71445
HookToolset.call_toolhad no error handling — any exception raised by the wrapped hook method (bad arguments from the LLM, a transient network error, etc.) propagated straight up and aborted the whole agent run. Every other hand-written toolset in this provider (SQLToolset,DataFusionToolset,SandboxToolset) already catches tool failures and re-raises them aspydantic_ai.exceptions.ModelRetry, so the model can read the error and retry within the run instead of failing the task outright.This brings
HookToolsetin line with the other toolsets, bounded by the tool's existingmax_retries.Change
HookToolset.call_tool(toolsets/hook.py) now wraps the hook method call intry/except Exception, re-raising aspydantic_ai.exceptions.ModelRetrywith the tool name and original error message.SQLToolset/SandboxToolset.test_wraps_failure_in_model_retry(tests/.../test_hook.py), using a new_FakeHook.failing_methodfixture that always raises.Was generative AI tooling used to co-author this PR?
No