fix: apply mergeToolResultText only for Mistral family models in OpenAI provider #10716
+22
−4
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: #10684
Related: #10618, #10540, #10695 (same root cause, different providers/approaches)
Description
This PR attempts to address Issue #10684 based on feedback from @maksir suggesting we should check the model family before applying the
mergeToolResultTextfix to avoid affecting other models.Changes:
isMistralFamilycheck that detects Mistral/Devstral models by checking if the model ID contains "mistral" or "devstral" (case-insensitive){ mergeToolResultText: true }toconvertToOpenAiMessages()only whenisMistralFamilyis trueconvertToOpenAiMessages()calls in the OpenAI provider (both streaming and non-streaming modes, including O3 family handlers)This follows the same pattern as PR #10630 which implements the model family check for OpenRouter.
Root Cause:
Mistral/Devstral models enforce strict message ordering and reject a "user" role message immediately after a "tool" role message. The
mergeToolResultTextoption merges text content into the last tool message instead of creating a separate user message.Test Procedure
Pre-Submission Checklist
mergeToolResultTextfunctionality is tested inopenai-format.spec.ts.Documentation Updates
Additional Notes
This approach is more conservative than PR #10695 which applies
mergeToolResultText: trueto all models. By checking the model family first, we avoid any potential side effects on models that do not require this fix.Feedback and guidance are welcome!
Important
Adds
isMistralFamilycheck inOpenAiHandlerto conditionally applymergeToolResultTextfor Mistral/Devstral models, ensuring correct message ordering.isMistralFamilycheck inOpenAiHandlerto identify Mistral/Devstral models by checkingmodelIdfor "mistral" or "devstral".{ mergeToolResultText: true }inconvertToOpenAiMessages()only ifisMistralFamilyis true.convertToOpenAiMessages()calls inOpenAiHandlerfor both streaming and non-streaming modes.This description was created by
for 5659e91. You can customize this summary. It will automatically update as commits are pushed.