-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
ADK Issue: Tool Lookup Errors Not Handled by on_tool_error_callback
Problem
When an agent attempts to call a tool that doesn't exist (e.g., browser_fill instead of browser_fill_form), ADK raises a ValueError during tool lookup before the tool execution phase. While ADK does catch this error and attempts to call on_tool_error_callbacks, the error handling flow has a critical flaw:
- Tool lookup fails in
_get_tool()(line 718) → raisesValueError - Error is caught in
_execute_single_function_call_async()(line 325) - Callbacks are invoked via
_run_on_tool_error_callbacks()(line 327) - If no callback returns a response → error is re-raised (line 338)
This means agents that are designed to handle "bad tool calls" (like validators that auto-correct tool names) cannot intervene because:
- The error occurs before tool execution
- If
on_tool_error_callbackis not configured, the error propagates immediately - The agent never gets a chance to handle the error gracefully
Expected Behavior
When on_tool_error_callback is configured, it should be able to:
- Catch tool lookup errors (tool name doesn't exist)
- Return a fallback response or corrected tool call
- Allow the agent to continue execution
Current Behavior
Even with on_tool_error_callback configured, if the callback returns None (or isn't configured), the error is re-raised and execution stops catastrophically.
Code Location
File: .venv/Lib/site-packages/google/adk/flows/llm_flows/functions.py
Lines 323-338:
try:
tool = _get_tool(function_call, tools_dict)
except ValueError as tool_error:
tool = BaseTool(name=function_call.name, description='Tool not found')
error_response = await _run_on_tool_error_callbacks(
tool=tool,
tool_args=function_args,
tool_context=tool_context,
error=tool_error,
)
if error_response is not None:
return __build_response_event(
tool, error_response, tool_context, invocation_context
)
else:
raise tool_error # ← Error re-raised if callback doesn't handle itLines 714-729 (_get_tool function):
def _get_tool(
function_call: types.FunctionCall, tools_dict: dict[str, BaseTool]
):
"""Returns the tool corresponding to the function call."""
if function_call.name not in tools_dict:
available = list(tools_dict.keys())
error_msg = (
f"Tool '{function_call.name}' not found.\nAvailable tools:"
f" {', '.join(available)}\n\nPossible causes:\n 1. LLM hallucinated"
' the function name - review agent instruction clarity\n 2. Tool not'
' registered - verify agent.tools list\n 3. Name mismatch - check for'
' typos\n\nSuggested fixes:\n - Review agent instruction to ensure'
' tool usage is clear\n - Verify tool is included in agent.tools'
' list\n - Check for typos in function name'
)
raise ValueError(error_msg) # ← Error raised hereUse Case
We have a validator agent (playwright_validator) that is specifically designed to:
- Execute tool calls from other agents
- Handle incorrect tool names gracefully
- Auto-correct tool calls (e.g.,
browser_fill→browser_fill_form)
YAML Configuration (seed/agents/44-playwright-validator-llm.yaml):
- Lists
browser_fill_formas a valid tool (line 23) - Instruction explicitly states available tools
- Designed to handle errors and correct them
Problem: When a generator agent produces a script with browser_fill instead of browser_fill_form, the validator agent cannot handle it because ADK fails catastrophically before the validator's error handling can intervene.
Proposed Solution
- Option A: Make
on_tool_error_callbackrequired to return a response for tool lookup errors, or provide a default fallback - Option B: Add a separate callback for tool lookup errors (
on_tool_lookup_error_callback) - Option C: Allow
on_tool_error_callbackto return a corrected tool name/function call that ADK can retry
Version
- ADK Version: 1.21.0
- Python Version: 3.12+
- Date: 2025-12-23
Reproduction
- Create an agent with
on_tool_error_callbackconfigured - Have the agent attempt to call a non-existent tool (e.g.,
browser_fillwhen onlybrowser_fill_formexists) - Observe that the error is raised even though
on_tool_error_callbackexists - The callback is called, but if it returns
None, the error propagates
Related
- ADK Documentation: https://google.github.io/adk-docs/plugins/
- Issue: Tool lookup errors should be gracefully handled by callbacks
- Feature Request: Allow callbacks to correct tool names and retry