fix: add mergeToolResultText for Mistral/Devstral models in OpenRouter #10751
+5
−2
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 exists for other providers (DeepSeek, Z.ai, MiniMax) and 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 functionality (all 27 tests pass)Pre-Submission Checklist
mergeToolResultTextfunctionality is already tested.Documentation Updates
Additional Notes
This is a minimal fix that leverages existing infrastructure. The
mergeToolResultTextoption is already well-tested and used by other providers for similar message ordering requirements.Note: PR #10630 was previously opened for this issue but this is a fresh implementation with the latest codebase.
Important
Fixes message ordering error for Mistral/Devstral models in OpenRouter by merging tool result text and extending model detection.
OpenRouterHandlerby merging tool result text into the last tool message.createMessage()inopenrouter.tsto usemergeToolResultTextfor Mistral family models.mergeToolResultTextmechanism for message conversion.mergeToolResultTexttests inopenai-format.spec.tscover functionality.This description was created by
for 226469d. You can customize this summary. It will automatically update as commits are pushed.