Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Make tool call json decode error recoverable (#8233)

Boxuan Li98cb2e24ee95
diff --git a/openhands/agenthub/codeact_agent/function_calling.py b/openhands/agenthub/codeact_agent/function_calling.py
index bbf291cdf4..040f762f6d 100644
--- a/openhands/agenthub/codeact_agent/function_calling.py
+++ b/openhands/agenthub/codeact_agent/function_calling.py
@@ -76,7 +76,7 @@ def response_to_actions(
try:
arguments = json.loads(tool_call.function.arguments)
except json.decoder.JSONDecodeError as e:
- raise RuntimeError(
+ raise FunctionCallValidationError(
f'Failed to parse tool call arguments: {tool_call.function.arguments}'
) from e
diff --git a/openhands/agenthub/readonly_agent/function_calling.py b/openhands/agenthub/readonly_agent/function_calling.py
index f327ddf0a5..a0b938e8bf 100644
--- a/openhands/agenthub/readonly_agent/function_calling.py
+++ b/openhands/agenthub/readonly_agent/function_calling.py
@@ -127,7 +127,7 @@ def response_to_actions(
try:
arguments = json.loads(tool_call.function.arguments)
except json.decoder.JSONDecodeError as e:
- raise RuntimeError(
+ raise FunctionCallValidationError(
f'Failed to parse tool call arguments: {tool_call.function.arguments}'
) from e
diff --git a/tests/unit/test_function_calling.py b/tests/unit/test_function_calling.py
index 57170bd08f..7f71dde470 100644
--- a/tests/unit/test_function_calling.py
+++ b/tests/unit/test_function_calling.py
@@ -215,6 +215,6 @@ def test_invalid_json_arguments():
}
],
)
- with pytest.raises(RuntimeError) as exc_info:
+ with pytest.raises(FunctionCallValidationError) as exc_info:
response_to_actions(response)
assert 'Failed to parse tool call arguments' in str(exc_info.value)