fix: add mergeToolResultText for Mistral/Devstral models in OpenRouter #10630
+7
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Extends model detection and uses
mergeToolResultTextfor Mistral/Devstral models inOpenRouterHandlerto fix message ordering errors.OpenRouterHandlerinopenrouter.ts.mergeToolResultText: truetoconvertToOpenAiMessages()for Mistral/Devstral models to prevent "Unexpected role 'user' after role 'tool'" errors.mergeToolResultTextmechanism from PR feat: add strict tool message ordering setting for OpenAI Compatible providers #10598 for Mistral family models.This description was created by
for ce38fd4. You can customize this summary. It will automatically update as commits are pushed.