Skip to content

fix: _clean_content deletes excess newlines instead of condensing them #87

@kuishou68

Description

@kuishou68

Bug in agent_loop.py_clean_content function

In _clean_content, the following loop is used:

for p in [r'<file_content>[\s\S]*?</file_content>', r'<tool_(?:use|call)>[\s\S]*?</tool_(?:use|call)>', r'(\r?\n){3,}']:
    text = re.sub(p, '\n\n' if '\\\\n' in p else '', text)

The condition '\\\\n' in p is checking for a 3-character string (\\n: backslash, backslash, n) inside the third pattern r'(\r?\n){3,}', which only contains the 2-character sequence \n (backslash, n).

Because this check is always False for the third pattern, 3+ consecutive newlines are deleted entirely (replaced with '') instead of being condensed to two newlines ('\n\n').

This causes all paragraph spacing in LLM responses to disappear in non-verbose mode.

Fix

Change '\\\\n' to '\\n' so the condition correctly identifies the newline-collapse pattern:

for p in [r'<file_content>[\s\S]*?</file_content>', r'<tool_(?:use|call)>[\s\S]*?</tool_(?:use|call)>', r'(\r?\n){3,}']:
    text = re.sub(p, '\n\n' if '\\n' in p else '', text)

Signed-off-by: Cocoon-Break 54054995+kuishou68@users.noreply.github.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions