diff --git a/openhands/llm/fn_call_converter.py b/openhands/llm/fn_call_converter.py index 7de8824516..826b278dc4 100644 --- a/openhands/llm/fn_call_converter.py +++ b/openhands/llm/fn_call_converter.py @@ -421,16 +421,12 @@ def convert_tool_call_to_string(tool_call: dict) -> str: f'Failed to parse arguments as JSON. Arguments: {tool_call["function"]["arguments"]}' ) from e for param_name, param_value in args.items(): - is_multiline = isinstance(param_value, str) and '\n' in param_value + # Don't add extra newlines - keep parameter value as-is ret += f'' - if is_multiline: - ret += '\n' 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' ret += '' return ret diff --git a/tests/unit/llm/test_llm_fncall_converter.py b/tests/unit/llm/test_llm_fncall_converter.py index ff4b7961ef..b4270f89b0 100644 --- a/tests/unit/llm/test_llm_fncall_converter.py +++ b/tests/unit/llm/test_llm_fncall_converter.py @@ -701,6 +701,8 @@ NON_FNCALL_RESPONSE_MESSAGE = { """, ), # Test case with indented code block to verify indentation is preserved + # Note: multiline parameter values should NOT have extra newlines before/after + # to prevent newline accumulation across multiple LLM response cycles ( [ { @@ -716,16 +718,12 @@ NON_FNCALL_RESPONSE_MESSAGE = { """ str_replace /test/file.py - -def example(): - pass - - -def example(): +def example(): + pass +def example(): # This is indented print("hello") - return True - + return True """, ), # Test case with list parameter value