Skip to content

Commit 35f7efb

Browse files
Fix: Remove strip() from parameter value extraction to preserve indentation (OpenHands#8739)
Co-authored-by: openhands <[email protected]>
1 parent 14498c5 commit 35f7efb

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

openhands/llm/fn_call_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def _extract_and_validate_params(
582582
found_params = set()
583583
for param_match in param_matches:
584584
param_name = param_match.group(1)
585-
param_value = param_match.group(2).strip()
585+
param_value = param_match.group(2)
586586

587587
# Validate parameter is allowed
588588
if allowed_params and param_name not in allowed_params:

tests/unit/test_llm_fncall_converter.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,34 @@ def test_get_example_for_tools_all_tools():
652652
<parameter=command>view</parameter>
653653
<parameter=path>/test/file.py</parameter>
654654
<parameter=view_range>[1, 10]</parameter>
655+
</function>""",
656+
),
657+
# Test case with indented code block to verify indentation is preserved
658+
(
659+
[
660+
{
661+
'index': 1,
662+
'function': {
663+
'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"}',
664+
'name': 'str_replace_editor',
665+
},
666+
'id': 'test_id',
667+
'type': 'function',
668+
}
669+
],
670+
"""<function=str_replace_editor>
671+
<parameter=command>str_replace</parameter>
672+
<parameter=path>/test/file.py</parameter>
673+
<parameter=old_str>
674+
def example():
675+
pass
676+
</parameter>
677+
<parameter=new_str>
678+
def example():
679+
# This is indented
680+
print("hello")
681+
return True
682+
</parameter>
655683
</function>""",
656684
),
657685
],

0 commit comments

Comments
 (0)