Fix auto-continue bug: don't return early when tools executed but final_output not called
The bug was in the chunk.finished block inside stream_completion_with_tools. When no tool was executed in the CURRENT iteration (!tool_executed), the code would return early without checking if tools were executed in PREVIOUS iterations (any_tool_executed) and final_output was never called. This caused the agent to terminate prematurely after executing tools like todo_read when the LLM responded with text instead of calling final_output. The fix adds a check: if any_tool_executed && !final_output_called, we break to let the outer loop's auto-continue logic prompt the LLM to continue. Also fixed missing debug! import in g3-console/src/main.rs.
This commit is contained in:
@@ -4884,6 +4884,17 @@ impl<W: UiWriter> Agent<W> {
|
||||
));
|
||||
}
|
||||
|
||||
// If tools were executed in previous iterations but final_output wasn't called,
|
||||
// break to let the outer loop's auto-continue logic handle it
|
||||
if any_tool_executed && !final_output_called {
|
||||
debug!("Tools were executed but final_output not called - breaking to auto-continue");
|
||||
// Add the text response to context before breaking
|
||||
if has_text_response && !current_response.trim().is_empty() {
|
||||
full_response = current_response.clone();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Set full_response to current_response (don't append)
|
||||
// current_response already contains everything that was displayed
|
||||
// Don't set full_response here - it would duplicate the output
|
||||
|
||||
Reference in New Issue
Block a user