Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

assistant2: Handle empty tool results by providing placeholder text (#27130)

Agus Zubiagadfdca540ec02
diff --git a/crates/assistant2/src/tool_use.rs b/crates/assistant2/src/tool_use.rs
index e0d03edd91a..42020c4ce52 100644
--- a/crates/assistant2/src/tool_use.rs
+++ b/crates/assistant2/src/tool_use.rs
@@ -309,9 +309,19 @@ impl ToolUseState {
if let Some(tool_uses) = self.tool_uses_by_user_message.get(&message_id) {
for tool_use_id in tool_uses {
if let Some(tool_result) = self.tool_results.get(tool_use_id) {
- request_message
- .content
- .push(MessageContent::ToolResult(tool_result.clone()));
+ request_message.content.push(MessageContent::ToolResult(
+ LanguageModelToolResult {
+ tool_use_id: tool_use_id.clone(),
+ is_error: tool_result.is_error,
+ content: if tool_result.content.is_empty() {
+ // Surprisingly, the API fails if we return an empty string here.
+ // It thinks we are sending a tool use without a tool result.
+ "<Tool returned an empty string>".into()
+ } else {
+ tool_result.content.clone()
+ },
+ },
+ ));
}
}
}