diff --git a/openhands/llm/fn_call_converter.py b/openhands/llm/fn_call_converter.py index 90827d10fb..64f67cf086 100644 --- a/openhands/llm/fn_call_converter.py +++ b/openhands/llm/fn_call_converter.py @@ -426,7 +426,10 @@ def convert_tool_call_to_string(tool_call: dict) -> str: ret += f'' if is_multiline: ret += '\n' - ret += f'{param_value}' + if isinstance(param_value, list) or isinstance(param_value, dict): + ret += json.dumps(param_value) + else: + ret += f'{param_value}' if is_multiline: ret += '\n' ret += '\n' diff --git a/tests/unit/test_llm_fncall_converter.py b/tests/unit/test_llm_fncall_converter.py index 5bfc14b91e..52274f8abe 100644 --- a/tests/unit/test_llm_fncall_converter.py +++ b/tests/unit/test_llm_fncall_converter.py @@ -680,6 +680,44 @@ def example(): print("hello") return True +""", + ), + # Test case with list parameter value + ( + [ + { + 'index': 1, + 'function': { + 'arguments': '{"command": "test", "path": "/test/file.py", "tags": ["tag1", "tag2", "tag with spaces"]}', + 'name': 'test_function', + }, + 'id': 'test_id', + 'type': 'function', + } + ], + """ +test +/test/file.py +["tag1", "tag2", "tag with spaces"] +""", + ), + # Test case with dict parameter value + ( + [ + { + 'index': 1, + 'function': { + 'arguments': '{"command": "test", "path": "/test/file.py", "metadata": {"key1": "value1", "key2": 42, "nested": {"subkey": "subvalue"}}}', + 'name': 'test_function', + }, + 'id': 'test_id', + 'type': 'function', + } + ], + """ +test +/test/file.py +{"key1": "value1", "key2": 42, "nested": {"subkey": "subvalue"}} """, ), ],