From 98cb2e24ee950cfeb3b762a7dd7acfded8c9a6ce Mon Sep 17 00:00:00 2001 From: Boxuan Li Date: Sat, 3 May 2025 23:01:32 +0800 Subject: [PATCH] Make tool call json decode error recoverable (#8233) --- openhands/agenthub/codeact_agent/function_calling.py | 2 +- openhands/agenthub/readonly_agent/function_calling.py | 2 +- tests/unit/test_function_calling.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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)