fix: avoid duplicate messages on retry and reset final_content
Address review feedback: - Remove on_progress call for interim text to prevent duplicate messages when the model simply answers a direct question - Reset final_content to None before continue to avoid stale interim text leaking as the final response on empty retry Closes #705
This commit is contained in:
@@ -230,17 +230,18 @@ class AgentLoop:
|
|||||||
# Some models (MiniMax, Gemini Flash, GPT-4.1, etc.) send an
|
# Some models (MiniMax, Gemini Flash, GPT-4.1, etc.) send an
|
||||||
# interim text response (e.g. "Let me investigate...") before
|
# interim text response (e.g. "Let me investigate...") before
|
||||||
# making tool calls. If no tools have been used yet and we
|
# making tool calls. If no tools have been used yet and we
|
||||||
# haven't already retried, forward the text as progress and
|
# haven't already retried, add the text to the conversation
|
||||||
# give the model one more chance to use tools.
|
# and give the model one more chance to use tools.
|
||||||
|
# We do NOT forward the interim text as progress to avoid
|
||||||
|
# duplicate messages when the model simply answers directly.
|
||||||
if not tools_used and not text_only_retried and final_content:
|
if not tools_used and not text_only_retried and final_content:
|
||||||
text_only_retried = True
|
text_only_retried = True
|
||||||
logger.debug(f"Interim text response (no tools used yet), retrying: {final_content[:80]}")
|
logger.debug(f"Interim text response (no tools used yet), retrying: {final_content[:80]}")
|
||||||
if on_progress:
|
|
||||||
await on_progress(final_content)
|
|
||||||
messages = self.context.add_assistant_message(
|
messages = self.context.add_assistant_message(
|
||||||
messages, response.content,
|
messages, response.content,
|
||||||
reasoning_content=response.reasoning_content,
|
reasoning_content=response.reasoning_content,
|
||||||
)
|
)
|
||||||
|
final_content = None
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user