From d984d61123e757bd5c6dc15829bb89070154aaf5 Mon Sep 17 00:00:00 2001 From: Dabao21 <642011598@qq.com> Date: Sat, 25 Apr 2026 07:41:46 +0800 Subject: [PATCH] fix: correct regex replacement logic in _clean_content() The previous implementation used '\\n' in p to decide replacement string, which incorrectly matched the raw string literal \\n in all three patterns. This caused and tags to be replaced with newlines instead of empty strings. Now each pattern is explicitly paired with its correct replacement. --- agent_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent_loop.py b/agent_loop.py index 4f1a3947..d6cc3854 100644 --- a/agent_loop.py +++ b/agent_loop.py @@ -106,8 +106,8 @@ def _shrink_code(m): preview = '\n'.join(body[:5]) return f'```{lang}\n{preview}\n ... ({len(body)} lines)\n```' text = re.sub(r'```[\s\S]*?```', _shrink_code, text) - for p in [r'[\s\S]*?', r'[\s\S]*?', r'(\r?\n){3,}']: - text = re.sub(p, '\n\n' if '\\n' in p else '', text) + for p, repl in [(r'[\s\S]*?', ''), (r'[\s\S]*?', ''), (r'(\r?\n){3,}', '\n\n')]: + text = re.sub(p, repl, text) return text.strip() def _compact_tool_args(name, args):