duplicate output fix

This commit is contained in:
Dhanji R. Prasanna
2025-12-23 17:20:23 +11:00
parent ed246ce434
commit 382b905441

View File

@@ -4848,10 +4848,11 @@ impl<W: UiWriter> Agent<W> {
// break to let the outer loop's auto-continue logic handle it // break to let the outer loop's auto-continue logic handle it
if any_tool_executed && !final_output_called { if any_tool_executed && !final_output_called {
debug!("Tools were executed but final_output not called - breaking to auto-continue"); debug!("Tools were executed but final_output not called - breaking to auto-continue");
// Add the text response to context before breaking // NOTE: We intentionally do NOT set full_response here.
if has_text_response && !current_response.trim().is_empty() { // The content was already displayed during streaming.
full_response = current_response.clone(); // Setting full_response would cause duplication when the
} // function eventually returns.
// Context window is updated separately via add_message().
break; break;
} }
@@ -5095,14 +5096,15 @@ impl<W: UiWriter> Agent<W> {
} else if has_response { } else if has_response {
// Only set full_response if it's empty (first iteration without tools) // Only set full_response if it's empty (first iteration without tools)
// This prevents duplication when the agent responds without calling final_output // This prevents duplication when the agent responds without calling final_output
if full_response.is_empty() && !current_response.is_empty() { // NOTE: We intentionally do NOT set full_response here anymore.
full_response = current_response.clone(); // The content was already displayed during streaming via print_agent_response().
// Setting full_response would cause the CLI to print it again.
// We only need full_response for the context window (handled separately).
debug!( debug!(
"Set full_response from current_response: {} chars", "Response already streamed, not setting full_response. current_response: {} chars",
full_response.len() current_response.len()
); );
} }
}
let _ttft = first_token_time.unwrap_or_else(|| stream_start.elapsed()); let _ttft = first_token_time.unwrap_or_else(|| stream_start.elapsed());