mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-09 14:57:59 -05:00
fix: prevent newline accumulation in XML parameter serialization (#11767)
Co-authored-by: Lai Jinyi <laijinyi@tp-link.com.cn>
This commit is contained in:
@@ -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"]}'
|
f'Failed to parse arguments as JSON. Arguments: {tool_call["function"]["arguments"]}'
|
||||||
) from e
|
) from e
|
||||||
for param_name, param_value in args.items():
|
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'<parameter={param_name}>'
|
ret += f'<parameter={param_name}>'
|
||||||
if is_multiline:
|
|
||||||
ret += '\n'
|
|
||||||
if isinstance(param_value, list) or isinstance(param_value, dict):
|
if isinstance(param_value, list) or isinstance(param_value, dict):
|
||||||
ret += json.dumps(param_value)
|
ret += json.dumps(param_value)
|
||||||
else:
|
else:
|
||||||
ret += f'{param_value}'
|
ret += f'{param_value}'
|
||||||
if is_multiline:
|
|
||||||
ret += '\n'
|
|
||||||
ret += '</parameter>\n'
|
ret += '</parameter>\n'
|
||||||
ret += '</function>'
|
ret += '</function>'
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
@@ -701,6 +701,8 @@ NON_FNCALL_RESPONSE_MESSAGE = {
|
|||||||
</function>""",
|
</function>""",
|
||||||
),
|
),
|
||||||
# Test case with indented code block to verify indentation is preserved
|
# 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 = {
|
|||||||
"""<function=str_replace_editor>
|
"""<function=str_replace_editor>
|
||||||
<parameter=command>str_replace</parameter>
|
<parameter=command>str_replace</parameter>
|
||||||
<parameter=path>/test/file.py</parameter>
|
<parameter=path>/test/file.py</parameter>
|
||||||
<parameter=old_str>
|
<parameter=old_str>def example():
|
||||||
def example():
|
pass</parameter>
|
||||||
pass
|
<parameter=new_str>def example():
|
||||||
</parameter>
|
|
||||||
<parameter=new_str>
|
|
||||||
def example():
|
|
||||||
# This is indented
|
# This is indented
|
||||||
print("hello")
|
print("hello")
|
||||||
return True
|
return True</parameter>
|
||||||
</parameter>
|
|
||||||
</function>""",
|
</function>""",
|
||||||
),
|
),
|
||||||
# Test case with list parameter value
|
# Test case with list parameter value
|
||||||
|
|||||||
Reference in New Issue
Block a user