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.

agent: Fix Mistral tool use error message (#34692)

Oleksandr Mykhailenko29111304dde3
diff --git a/crates/language_models/src/provider/mistral.rs b/crates/language_models/src/provider/mistral.rs
index 11497fda350..fb385308fac 100644
--- a/crates/language_models/src/provider/mistral.rs
+++ b/crates/language_models/src/provider/mistral.rs
@@ -410,8 +410,20 @@ pub fn into_mistral(
.push_part(mistral::MessagePart::Text { text: text.clone() });
}
MessageContent::RedactedThinking(_) => {}
- MessageContent::ToolUse(_) | MessageContent::ToolResult(_) => {
- // Tool content is not supported in User messages for Mistral
+ MessageContent::ToolUse(_) => {
+ // Tool use is not supported in User messages for Mistral
+ }
+ MessageContent::ToolResult(tool_result) => {
+ let tool_content = match &tool_result.content {
+ LanguageModelToolResultContent::Text(text) => text.to_string(),
+ LanguageModelToolResultContent::Image(_) => {
+ "[Tool responded with an image, but Zed doesn't support these in Mistral models yet]".to_string()
+ }
+ };
+ messages.push(mistral::RequestMessage::Tool {
+ content: tool_content,
+ tool_call_id: tool_result.tool_use_id.to_string(),
+ });
}
}
}
@@ -482,24 +494,6 @@ pub fn into_mistral(
}
}
- for message in &request.messages {
- for content in &message.content {
- if let MessageContent::ToolResult(tool_result) = content {
- let content = match &tool_result.content {
- LanguageModelToolResultContent::Text(text) => text.to_string(),
- LanguageModelToolResultContent::Image(_) => {
- "[Tool responded with an image, but Zed doesn't support these in Mistral models yet]".to_string()
- }
- };
-
- messages.push(mistral::RequestMessage::Tool {
- content,
- tool_call_id: tool_result.tool_use_id.to_string(),
- });
- }
- }
- }
-
// The Mistral API requires that tool messages be followed by assistant messages,
// not user messages. When we have a tool->user sequence in the conversation,
// we need to insert a placeholder assistant message to maintain proper conversation