Skip to content

Add LOW and MEDIUM reasoning effort for Mistral AI - #7320

Open
Ajax-1 wants to merge 2 commits into
spring-projects:mainfrom
Ajax-1:fix/mistral-reasoning-effort-7312
Open

Ajax-1 wants to merge 2 commits into
spring-projects:mainfrom
Ajax-1:fix/mistral-reasoning-effort-7312

Conversation

@Ajax-1

@Ajax-1 Ajax-1 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Description

MistralAiApi.ChatCompletionRequest.ReasoningEffort only had HIGH and NONE. Mistral Large 4 accepts low, medium and high and rejects none, so it could not be used with a lower reasoning level: spring.ai.mistralai.chat.reasoning-effort=low (or medium) failed at property binding, and the MistralAiChatOptions builder had no constant for these levels either.

This adds LOW and MEDIUM, serialized as "low" and "medium". HIGH and NONE stay as they are, so Mistral Small 4 and Mistral Medium 3.5 are unaffected.

Fixes #7312

Changes

  • MistralAiApi: add ReasoningEffort.LOW and ReasoningEffort.MEDIUM, list the constants from lowest to highest, and say in the Javadoc which levels each model accepts, with a link to the Mistral reasoning docs.
  • MistralAiChatOptions: point the field Javadoc at ReasoningEffort instead of listing only HIGH/NONE.
  • mistralai-chat.adoc: list all four values for spring.ai.mistralai.chat.reasoning-effort, add Mistral Large 4 to the adjustable reasoning models, and add a short note on which levels each model accepts.
  • Tests:
    • MistralAiPropertiesTests: reasoning-effort set to none/low/medium/high binds to the matching constant and reaches toOptions() (this is the startup failure from the issue).
    • MistralAiChatOptionsTests: every constant serializes to its lowercase API value and deserializes back.

Notes

  • The Mistral API reference lists none | minimal | low | medium | high | xhigh for reasoning_effort, but the reasoning docs don't name a current Mistral model that accepts minimal or xhigh. I kept this PR to the levels from the issue; happy to add the other two if you'd rather mirror the full API enum.
  • MistralAiApi.ChatModel has no Mistral Large 4 constant (MISTRAL_LARGE points to the deprecated mistral-large-latest). I left that out of this PR since the model can be set by name.

Testing

  • ./mvnw -pl models/spring-ai-mistral-ai,auto-configurations/models/spring-ai-autoconfigure-model-mistral-ai test: 128 tests in spring-ai-mistral-ai and 16 in the auto-configuration module, 0 failures, 0 errors (2 skipped in MistralAiRetryTests, unrelated).
  • With the enum reverted to main, the LOW and MEDIUM cases of both new tests fail (No enum constant ...ReasoningEffort.LOW / MEDIUM); they pass with this change.
  • spring-javaformat:validate passes and checkstyle reports 0 violations on both modules.
  • Integration tests (*IT) were not run, as they need a Mistral API key.

@nicolaskrier nicolaskrier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! Adding the missing low and medium reasoning effort levels is a feature I have been looking forward to. I left a few review comments.

void chatReasoningEffortProperty(String value, ReasoningEffort expected) {

new ApplicationContextRunner()
.withPropertyValues("spring.ai.mistralai.api-key=API_KEY", "spring.ai.mistralai.chat.model=mistral-large-4",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consider updating the value of ‎MistralAiApi.ChatModel.MISTRAL_LARGE to mistral-large-4 and removing its deprecation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, thanks! Updated MISTRAL_LARGE to mistral-large-4 and removed its deprecation. I also added a note to the 2.1.0 upgrade notes about the value change.


@ParameterizedTest
@CsvSource({ "NONE, none", "LOW, low", "MEDIUM, medium", "HIGH, high" })
void testJsonSerializationOfReasoningEffort(ReasoningEffort reasoningEffort, String value) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you have a look at ThinkingModelSource and ThinkingModelUtils? They are used in the following IT classes:

  • MistralAiApiIT,
  • MistralAiChatModelIT.

It would be great if you could add MISTRAL_LARGE and one of the new reasoning efforts associated with it, maybe LOW to get faster responses.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. MISTRAL_LARGE is now included in ThinkingModelSource / ThinkingModelUtils with LOW reasoning effort (Small and Medium stay on HIGH).
One caveat: I don't have a Mistral API key locally, so I couldn't run the ITs. thinkingCall / thinkingStream and two tests in MistralAiApiIT assert that thinking content is returned. If Large with LOW turns out not to return thinking, switching it to MEDIUM should fix that. Happy to adjust.

* {@link ReasoningEffort#HIGH} enables comprehensive reasoning traces,
* {@link ReasoningEffort#NONE} disables reasoning effort.
* Controls the reasoning effort level for adjustable reasoning models. The
* accepted levels depend on the model: Mistral Small 4 and Mistral Medium 3.5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should describe the supported reasoning effort levels per model here. That would have to be maintained over time, whereas simply referring to Mistral AI's documentation might be enough.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that would be hard to keep in sync. The ReasoningEffort Javadoc and mistralai-chat.adoc now link to the Mistral AI reasoning docs instead of listing levels per model.

@Ajax-1
Ajax-1 force-pushed the fix/mistral-reasoning-effort-7312 branch from ab058e7 to 00b9d35 Compare November 13, 2026 11:13
@Ajax-1
Ajax-1 force-pushed the fix/mistral-reasoning-effort-7312 branch from 00b9d35 to eca652e Compare November 21, 2026 05:03
Mistral Large 4 accepts the low, medium and high reasoning effort
levels, but ReasoningEffort only defined HIGH and NONE, so setting
spring.ai.mistralai.chat.reasoning-effort to low or medium failed at
property binding. Add LOW and MEDIUM, document which levels each model
accepts, and cover binding and JSON serialization with tests.

Fixes spring-projects#7312

Signed-off-by: Ajax-1 <85230126+Ajax-1@users.noreply.github.com>
Point ChatModel.MISTRAL_LARGE at mistral-large-4 and drop its
deprecation, cover that model in the reasoning tests at LOW effort,
and refer readers to the Mistral documentation for supported levels.

Signed-off-by: Ajax-1 <85230126+Ajax-1@users.noreply.github.com>
@Ajax-1
Ajax-1 force-pushed the fix/mistral-reasoning-effort-7312 branch from eca652e to db14095 Compare November 27, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsupported LOW and MEDIUM reasoning effort for Mistral Large 4

3 participants