Prevent agent mode from stopping after first TODO phase
- Add TODO completion check to final_output tool in autonomous mode only - When incomplete TODO items exist, reject final_output and prompt LLM to continue - Non-autonomous modes (interactive, chat) are unaffected - Add 6 tests verifying behavior in both autonomous and non-autonomous modes Fixes issue where LLM would call final_output after completing first phase, causing agent to stop prematurely instead of continuing with remaining phases.
This commit is contained in:
@@ -4016,6 +4016,25 @@ impl<W: UiWriter> Agent<W> {
|
||||
"final_output" => {
|
||||
if let Some(summary) = tool_call.args.get("summary") {
|
||||
if let Some(summary_str) = summary.as_str() {
|
||||
// In autonomous mode, check for incomplete TODO items before allowing completion
|
||||
// This prevents the agent from stopping prematurely when there's more work to do
|
||||
if self.is_autonomous {
|
||||
let todo_content = self.todo_content.read().await;
|
||||
let has_incomplete_todos = todo_content.lines().any(|line| {
|
||||
let trimmed = line.trim();
|
||||
trimmed.starts_with("- [ ]")
|
||||
});
|
||||
drop(todo_content); // Release the lock
|
||||
|
||||
if has_incomplete_todos {
|
||||
return Ok(
|
||||
"There are still incomplete TODO items. Please continue until \
|
||||
*ALL* TODO items in *ALL* phases are marked complete, and \
|
||||
*ONLY* then call `final_output`.".to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Save session continuation artifact
|
||||
self.save_session_continuation(Some(summary_str.to_string()));
|
||||
Ok(summary_str.to_string())
|
||||
|
||||
Reference in New Issue
Block a user