fix: Enable agent to see instruction to use final output tool when it wasn't called (#3253)

This commit is contained in:
Jarrod Sibbison
2025-07-04 18:35:52 +10:00
committed by GitHub
parent 2e9a2a53be
commit 97a0c529f2
2 changed files with 8 additions and 4 deletions

View File

@@ -821,10 +821,14 @@ impl Agent {
if let Some(final_output_tool) = self.final_output_tool.lock().await.as_ref() {
if final_output_tool.final_output.is_none() {
tracing::warn!("Final output tool has not been called yet. Continuing agent loop.");
yield AgentEvent::Message(Message::user().with_text(FINAL_OUTPUT_CONTINUATION_MESSAGE));
let message = Message::assistant().with_text(FINAL_OUTPUT_CONTINUATION_MESSAGE);
messages.push(message.clone());
yield AgentEvent::Message(message);
continue;
} else {
yield AgentEvent::Message(Message::assistant().with_text(final_output_tool.final_output.clone().unwrap()));
let message = Message::assistant().with_text(final_output_tool.final_output.clone().unwrap());
messages.push(message.clone());
yield AgentEvent::Message(message);
}
}
break;

View File

@@ -9,7 +9,7 @@ use serde_json::Value;
pub const FINAL_OUTPUT_TOOL_NAME: &str = "recipe__final_output";
pub const FINAL_OUTPUT_CONTINUATION_MESSAGE: &str =
"You MUST call the `final_output` tool with your final output for the user.";
"I see I MUST call the `final_output` tool NOW with the final output for the user.";
pub struct FinalOutputTool {
pub response: Response,
@@ -76,7 +76,7 @@ impl FinalOutputTool {
pub fn system_prompt(&self) -> String {
formatdoc! {r#"
# Final Ouptut Instructions
# Final Output Instructions
You MUST use the `final_output` tool to collect the final output for a user.
The final output MUST be a valid JSON object that matches the following expected schema: