Skip to content

Let HookToolset retry a failed tool call instead of failing the task - #71853

Open
ColtenOuO wants to merge 1 commit into
apache:mainfrom
ColtenOuO:common-ai-hook-toolset-model-retry
Open

Let HookToolset retry a failed tool call instead of failing the task#71853
ColtenOuO wants to merge 1 commit into
apache:mainfrom
ColtenOuO:common-ai-hook-toolset-model-retry

Conversation

@ColtenOuO

Copy link
Copy Markdown
Contributor

Summary

Follow up: #71445

HookToolset.call_tool had 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 as
pydantic_ai.exceptions.ModelRetry, so the model can read the error and retry within the run instead of failing the task outright.

This brings HookToolset in line with the other toolsets, bounded by the tool's existing max_retries.

Change

  • HookToolset.call_tool (toolsets/hook.py) now wraps the hook method call in try/except Exception, re-raising as pydantic_ai.exceptions.ModelRetry with the tool name and original error message.
  • Added a short note to the class docstring describing this retry behavior, matching the wording already used by SQLToolset / SandboxToolset.
  • Added test_wraps_failure_in_model_retry (tests/.../test_hook.py), using a new _FakeHook.failing_method fixture that always raises.

Was generative AI tooling used to co-author this PR?

No

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants