-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: add mergeToolResultText for Mistral/Devstral models in OpenRouter #10630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Fixes the "Unexpected role user after role tool" error for Mistral and Devstral models when using OpenRouter. Changes: - Extended model detection to include "devstral" (e.g. mistralai/devstral-2512) - Added mergeToolResultText: true to merge text content into tool messages instead of creating a separate user message that violates Mistral ordering Closes #10618
Review complete. No issues found. The change correctly extends Mistral model detection to include Devstral models and adds Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
|
@roomote What are the next steps to merge this? |
The PR was in draft status. I've marked it as ready for review. The code changes look good - the fix extends Mistral model detection to include Devstral models and adds Next steps: A maintainer can now review and merge this PR. |
Review complete. No issues found. The change correctly extends Mistral model detection to include Devstral models and adds Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Related GitHub Issue
Closes: #10618
Related: #10540 (same root cause, different provider)
Description
This PR attempts to address Issue #10618. Feedback and guidance are welcome.
Root Cause:
The error "Unexpected role 'user' after role 'tool'" occurs because Mistral/Devstral models have strict message ordering requirements. After a
toolrole message, the next message cannot be auserrole message.Solution:
mistralai/devstral-2512contains "devstral" not "mistral")mergeToolResultText: trueto the conversion options, which merges text content (like environment_details) into the last tool message instead of creating a separate user messageThis uses the same
mergeToolResultTextmechanism that PR #10598 exposes as a setting for OpenAI Compatible providers, but applies it automatically for Mistral family models in OpenRouter since we can detect them by model ID.Test Procedure
mistralai/devstral-2512)mergeToolResultTexttests inopenai-format.spec.tscover the underlying functionalityPre-Submission Checklist
mergeToolResultTextfunctionality is already tested.Documentation Updates
Additional Notes
This is a minimal fix that leverages existing infrastructure. The
mergeToolResultTextoption was added in a previous PR and is already used by DeepSeek, Z.ai, and MiniMax providers for similar message ordering issues.Important
Fixes message ordering error for Mistral/Devstral models in
OpenRouterHandlerby merging tool result text and extending model detection.OpenRouterHandlerby merging tool result text.createMessage()inopenrouter.tsto usemergeToolResultTextfor Mistral/Devstral models.modelIdfor "mistral" or "devstral" to apply the fix.mergeToolResultTexttests inopenai-format.spec.ts.This description was created by
for ce38fd4. You can customize this summary. It will automatically update as commits are pushed.