mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-24 01:20:29 +01:00
b8c1b54f9e
Closes #31491 ### Problem Mistral API enforces strict conversation flow requirements that other providers don't. Specifically, after a `tool` message, the next message **must** be from the `assistant` role, not `user`. This causes the error: ``` "Unexpected role 'user' after role 'tool'" ``` This can also occur in normal conversation flow where mistral doesn't return the assistant message but that is something which can't be reproduce reliably. ### Root Cause When users interrupt an ongoing tool call sequence by sending a new message, we insert a `user` message directly after a `tool` message, violating Mistral's protocol. **Expected Mistral flow:** ``` user → assistant (with tool_calls) → tool (results) → assistant (processes results) → user (next input) ``` **What we were doing:** ``` user → assistant (with tool_calls) → tool (results) → user (interruption) ❌ ``` ### Solution Insert an empty `assistant` message between any `tool` → `user` sequence in the Mistral provider's request construction. This satisfies Mistral's API requirements without affecting other providers or requiring UX changes. ### Testing To reproduce the original error: 1. Start agent chat with `codestral-latest` 2. Send: "Describe this project using tool call only" 3. Once tool calls begin, send: "stop this" 4. Main branch: API error 5. This fix: Works correctly Release Notes: - Fixed Mistral tool calling in some cases