Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix: Remove strip() from parameter value extraction to preserve indentation (#8739)

Xingyao Wang35f7efb9d74f
diff --git a/openhands/llm/fn_call_converter.py b/openhands/llm/fn_call_converter.py
index 09079d4d76..0218107ca6 100644
--- a/openhands/llm/fn_call_converter.py
+++ b/openhands/llm/fn_call_converter.py
@@ -582,7 +582,7 @@ def _extract_and_validate_params(
found_params = set()
for param_match in param_matches:
param_name = param_match.group(1)
- param_value = param_match.group(2).strip()
+ param_value = param_match.group(2)
# Validate parameter is allowed
if allowed_params and param_name not in allowed_params:
diff --git a/tests/unit/test_llm_fncall_converter.py b/tests/unit/test_llm_fncall_converter.py
index 7d3694086b..5bfc14b91e 100644
--- a/tests/unit/test_llm_fncall_converter.py
+++ b/tests/unit/test_llm_fncall_converter.py
@@ -652,6 +652,34 @@ NON_FNCALL_RESPONSE_MESSAGE = {
<parameter=command>view</parameter>
<parameter=path>/test/file.py</parameter>
<parameter=view_range>[1, 10]</parameter>
+</function>""",
+ ),
+ # Test case with indented code block to verify indentation is preserved
+ (
+ [
+ {
+ 'index': 1,
+ 'function': {
+ 'arguments': '{"command": "str_replace", "path": "/test/file.py", "old_str": "def example():\\n pass", "new_str": "def example():\\n # This is indented\\n print(\\"hello\\")\\n return True"}',
+ 'name': 'str_replace_editor',
+ },
+ 'id': 'test_id',
+ 'type': 'function',
+ }
+ ],
+ """<function=str_replace_editor>
+<parameter=command>str_replace</parameter>
+<parameter=path>/test/file.py</parameter>
+<parameter=old_str>
+def example():
+ pass
+</parameter>
+<parameter=new_str>
+def example():
+ # This is indented
+ print("hello")
+ return True
+</parameter>
</function>""",
),
],