fix: strip <think> 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 <think>...</think> 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
This commit is contained in:
@@ -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 <think> 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 <think> 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)
|
||||
|
||||
Reference in New Issue
Block a user