agent: Re-add workaround for language model behavior with empty tool result (#37196)

This is just copying over the same workaround here:


https://github.com/zed-industries/zed/blob/e6679b84df7a36051e0094bc600281fc6aa273bd/crates/agent/src/thread.rs#L1455-L1459

Into the agent2 code.

Release Notes:

- agent: Fixed an issue where some tool calls in the Zed agent could
return an error like "`tool_use` ids were found without `tool_result`
blocks immediately after"
This commit is contained in:
Cole Miller authored and GitHub committed 2025-08-29 18:26:11 -04:00
1 parent a869056cd4
commit c50a148501
1 file changed
+7 -3
+7 -3
View File
@@ -484,11 +484,15 @@ impl AgentMessage {
};
for tool_result in self.tool_results.values() {
let mut tool_result = tool_result.clone();
// Surprisingly, the API fails if we return an empty string here.
// It thinks we are sending a tool use without a tool result.
if tool_result.content.is_empty() {
tool_result.content = "<Tool returned an empty string>".into();
}
user_message
.content
.push(language_model::MessageContent::ToolResult(
tool_result.clone(),
));
.push(language_model::MessageContent::ToolResult(tool_result));
}
let mut messages = Vec::new();