Skip to content

Commit c44742e

Browse files
fix: move parse_tool_call_arguments inside try block
Move the parse_tool_call_arguments() call inside the try block so that JSONDecodeError is caught properly. Previously, unparseable JSON would cause the agent to crash instead of emitting a helpful AgentErrorEvent. Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 909d6b9 commit c44742e

File tree

1 file changed

+4
-4
lines changed
  • openhands-sdk/openhands/sdk/agent

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,13 +855,13 @@ def _get_action_event(
855855
tool: ToolDefinition | None = None
856856
# Store the normalized tool call to persist correct name/args in events.
857857
normalized_tool_call = tool_call
858-
859-
# Parse arguments outside the try block so we can reuse them in the
860-
# except handler without calling parse_tool_call_arguments twice.
861-
arguments = parse_tool_call_arguments(tool_call.arguments)
858+
arguments: dict[str, object] | None = None
862859

863860
security_risk: risk.SecurityRisk = risk.SecurityRisk.UNKNOWN
864861
try:
862+
# Parse arguments inside the try block so JSONDecodeError is caught.
863+
arguments = parse_tool_call_arguments(tool_call.arguments)
864+
865865
# Normalize tool call (handles aliasing, terminal fallback, etc.)
866866
tool_name, arguments = normalize_tool_call(
867867
requested_tool_name,

0 commit comments

Comments
 (0)