From 1e463a8e39a8c0ae827ad646b6779f2454a7de6d Mon Sep 17 00:00:00 2001 From: Bartok9 Date: Sat, 28 Feb 2026 03:06:20 -0500 Subject: [PATCH] fix: strip blocks from final response to users Fixes #149 The _strip_think_blocks() method existed but was not applied to the final_response in the normal completion path. This caused ... XML tags to leak into user-facing responses on all platforms (CLI, Telegram, Discord, Slack, WhatsApp). Changes: - Strip think blocks from final_response before returning in normal path (line ~2600) - Strip think blocks from fallback content when salvaging from prior tool_calls turn Notes: - The raw content with think blocks is preserved in messages[] for trajectory export - this only affects the user-facing final_response - The _has_content_after_think_block() check still uses raw content before stripping, which is correct for detecting think-only responses --- run_agent.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/run_agent.py b/run_agent.py index 59a547f0d..c32d92d7e 100644 --- a/run_agent.py +++ b/run_agent.py @@ -2567,7 +2567,8 @@ class AIAgent: tool_names.append(fn.get("name", "unknown")) msg["content"] = f"Calling the {', '.join(tool_names)} tool{'s' if len(tool_names) > 1 else ''}..." break - final_response = fallback + # Strip blocks from fallback content for user display + final_response = self._strip_think_blocks(fallback).strip() break # No fallback -- append the empty message as-is @@ -2596,6 +2597,9 @@ class AIAgent: if hasattr(self, '_empty_content_retries'): self._empty_content_retries = 0 + # Strip blocks from user-facing response (keep raw in messages for trajectory) + final_response = self._strip_think_blocks(final_response).strip() + final_msg = self._build_assistant_message(assistant_message, finish_reason) messages.append(final_msg)