Skip to content

Commit 9eeab48

Browse files
fix: extract alias target from normalize_tool_call error for consistent tool names
When normalize_tool_call raises a 'Cannot infer' error (e.g., for file_editor with empty arguments), the error message contains the alias target name (e.g., 'file_editor'), not the original tool name (e.g., 'str_replace'). Previously, the validation error path would show the wrong tool name because it used the requested_tool_name. Now we extract the alias target from the error message and use it consistently in error messages, fixing the mismatch on the validation error / retry path. Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 8d35dee commit 9eeab48

File tree

1 file changed

+12
-1
lines changed
  • openhands-sdk/openhands/sdk/agent

1 file changed

+12
-1
lines changed

openhands-sdk/openhands/sdk/agent/agent.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import json
4+
import re
45
from collections.abc import Callable
56
from dataclasses import dataclass, field
67
from typing import TYPE_CHECKING
@@ -913,13 +914,23 @@ def _get_action_event(
913914
# Build concise error message with parameter names only (not values).
914915
# Try to extract keys for the error message, but gracefully handle
915916
# truly unparseable JSON by showing "unparseable JSON" instead.
917+
918+
# When normalize_tool_call raises about file_editor "Cannot infer",
919+
# the error message contains the alias target (e.g. "file_editor"),
920+
# not the original tool name. Extract it so error messages match.
921+
err_str = str(e)
922+
display_tool_name = requested_tool_name
923+
if "Cannot infer" in err_str:
924+
match = re.search(r"for tool '([^']+)'", err_str)
925+
if match:
926+
display_tool_name = match.group(1)
927+
916928
keys = list(arguments.keys()) if isinstance(arguments, dict) else None
917929
params = (
918930
f"Parameters provided: {keys}"
919931
if keys is not None
920932
else "Arguments: unparseable JSON"
921933
)
922-
display_tool_name = tool.name if tool is not None else requested_tool_name
923934
err = f"Error validating tool '{display_tool_name}': {e}. {params}"
924935
self._emit_tool_error(
925936
error=err,

0 commit comments

Comments
 (0)