only emit final response once

This commit is contained in:
Dhanji Prasanna
2025-09-29 08:22:26 +10:00
parent 39ef13e317
commit 315596e316

View File

@@ -1027,7 +1027,9 @@ The tool will execute immediately and you'll receive the result (success or erro
io::stdout().flush()?;
// Add the tool call and result to the context window
let tool_message = Message {
// Only include the text content if it's not already in full_response
let tool_message = if !full_response.contains(final_display_content) {
Message {
role: MessageRole::Assistant,
content: format!(
"{}\n\n{{\"tool\": \"{}\", \"args\": {}}}",
@@ -1035,6 +1037,17 @@ The tool will execute immediately and you'll receive the result (success or erro
tool_call.tool,
tool_call.args
),
}
} else {
// If we've already added the text, just include the tool call
Message {
role: MessageRole::Assistant,
content: format!(
"{{\"tool\": \"{}\", \"args\": {}}}",
tool_call.tool,
tool_call.args
),
}
};
let result_message = Message {
role: MessageRole::User,
@@ -1052,7 +1065,10 @@ The tool will execute immediately and you'll receive the result (success or erro
request.tools = Some(Self::create_tool_definitions());
}
// Only add to full_response if we haven't already added it
if !full_response.contains(final_display_content) {
full_response.push_str(final_display_content);
}
tool_executed = true;
// Reset parser for next iteration