Repository navigation
feat(assistant): add Mistral provider with tool-call compatibility - #3185
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Code reviewScope: PR #3185 (Mistral provider). The diff also carries the changes from the stacked PR #3171 (provider descriptions, the OpenRouter privacy routing, the CONTRIBUTING policy and the README rewording). I reviewed them as they appear in this diff. I could not build or run the tests here, so this review is from reading the code. Bugs
Security
Performance
Quality
AGENTS.md
Twins checked
Earlier review threads
Four inline comments are filed: README, Change sizeCompared: the whole PR against main (merge base af6e24c to PR head 0d2b19f).
|
|
The README’s “OpenRouter and other gateways” wording is intentional in #3171; Requesty, TrustedRouter and Opper remain available and documented. The privacy note also names OpenRouter account settings, which can reject a request while the local checkbox is off. Narrowing the message match further is left for the release quality pass, as recorded on #3171. Typed thinking/signature blocks are retained in the native conversation for replay. They are intentionally excluded from answer text; the regression checks both visible text and preserved native blocks. The privacy controls have separate documented scopes: desktop uses its saved checkbox, while CLI uses |
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the |
0d2b19f to
00c9c26
Compare
| Some(Value::String(text)) => text.clone(), | ||
| Some(Value::Array(parts)) => parts | ||
| .iter() | ||
| .filter(|p| p.get("type").and_then(Value::as_str) == Some("text")) |
There was a problem hiding this comment.
openai_content_text keeps only type: "text" parts and drops every other typed part without a trace. The visible reply and the stream preview therefore lose anything else a compatible server sends in content, such as a reference or citation chunk. AGENTS asks that a reader which drops data says what and how much (Session::notify or ToolResult::messages, one notice per kind with a count), and that lossy input has a test that expects the notice. Either count the skipped non-text parts and report them, or pin the chosen behaviour in a test. Confidence is low-to-medium: RustGIS sends only function tools, so I'm not sure the Mistral API returns these parts on this path.
Category: bug
There was a problem hiding this comment.
Fixed in be0e048. Unsupported display parts now generate one counted transcript notice per type, including for summary replies, while the native payload remains intact. Known thinking metadata does not generate a notice. The regression exercises streamed and whole replies through the agent, checks the exact count and native content, and fails with reporting reverted. Full fork CI passed. Mistral’s citation documentation confirms reference chunks can accompany function-tool replies.
| (Value::Array(parts), Value::Array(more)) => parts.extend(more.iter().cloned()), | ||
| (Value::Array(parts), Value::String(text)) => parts.push(json!({"type":"text", "text":text})), | ||
| (Value::String(text), Value::Array(parts)) => { | ||
| let mut all = vec![json!({"type":"text", "text":text})]; |
There was a problem hiding this comment.
When the first content delta is an empty string (common in the opening chunk of a stream), this arm stores an empty {"type":"text","text":""} part. That part is replayed to Mistral in the native message. I can't confirm from here whether Mistral rejects empty text chunks, but skipping empty text avoids sending one for no reason. Small fix:
| let mut all = vec![json!({"type":"text", "text":text})]; | |
| let mut all = if text.is_empty() { Vec::new() } else { vec![json!({"type":"text", "text":text})] }; |
Category: quality
There was a problem hiding this comment.
Fixed in be0e048 by ignoring empty string deltas before assembly. The regression opens and closes a typed stream with empty deltas and checks the exact native payload. It fails with the filter reverted. Full fork CI passed.
| | Requesty | A UK gateway to hundreds of models, which can move to another service when one fails. It logs requests up to 30 days by default; you can turn that off for each key. Some upstreams train on requests on paid plans too; Requesty may also train on free-plan requests. | `anthropic/claude-sonnet-5-5` | [app.requesty.ai](https://app.requesty.ai/api-keys), or `REQUESTY_API_KEY`; for the EU, set the **Address** to `https://router.eu.requesty.ai/v1` | | ||
| | TrustedRouter | A US gateway to models from many services, run on servers whose software can be checked independently. The gateway doesn't keep request content; each service behind it follows its own policy and may keep or train on requests. | `trustedrouter/auto` | [trustedrouter.com](https://trustedrouter.com), or `TRUSTEDROUTER_API_KEY` | | ||
| | Opper | A Swedish gateway to hundreds of models, built for keeping data in the EU. It doesn't store request content by default, but a model name without a route prefix may run outside the EU. | `claude-sonnet-5-5` | [platform.opper.ai](https://platform.opper.ai), or `OPPER_API_KEY` | | ||
| | Mistral | Mistral AI's own API, from France. Paid API requests aren't used for training by default; on a free account, turn training off under Privacy in the admin panel. Labs and Preview models may train regardless of that setting. | `mistral-small-2603` | [console.mistral.ai](https://console.mistral.ai/api-keys), or `MISTRAL_API_KEY`; for the EU, set **Address** to `https://api.eu.mistral.ai/v1` | |
There was a problem hiding this comment.
The guide row states that https://api.eu.mistral.ai/v1 is the EU address for Mistral. I can't check that from here (no network access). Please confirm it against Mistral's current API documentation before merge. If it isn't a documented regional endpoint, users who follow this row will get connection failures. The same claim is in the preset description in provider.rs, though that text only says the service is based in France.
Category: quality
There was a problem hiding this comment.
Confirmed against Mistral’s current regional inference documentation, which shows https://api.eu.mistral.ai/v1/chat/completions. The guide now links that source and notes supported-model limits and the 10% regional surcharge. This update is in be0e048; full fork CI passed.
Code reviewScope: Mistral added as an OpenAI-compatible preset, with call-ID remapping for Mistral's nine-character ID rule, typed-content parsing for streamed and whole replies, and matching CLI and docs updates. I reviewed the diff against the surrounding Bugs
Security
Performance
Quality
AGENTS.md
Checked for twins: the other OpenAI-shaped read paths (non-streamed and streamed) and the stream preview, plus the Anthropic, Gemini and Responses parsers, which the diff does not touch. Tool-call ID remapping covers cross-provider calls because it runs on the outgoing message list. Prior concerns: 0 review threads existed, so none were left alone. Change sizeCompared: the whole PR against main (merge base 9b0f0f9 to PR head 00c9c26).
|
| } | ||
| } | ||
| let mut message = json!({"role": "assistant", "content": if content.is_empty() { Value::Null } else { json!(content) }}); | ||
| if content.as_str() == Some("") { |
There was a problem hiding this comment.
This check can no longer fire. The delta filter above never stores an empty string (v.as_str() != Some("")), and every push_str/append adds non-empty content, so content is never "". Meanwhile an all-empty array delta ("content": []) is stored as [], which the old code turned into null. A [] now goes into the native assistant message, and Mistral replays that native message on later turns. Normalising both empty shapes keeps the old behaviour and makes the check do its job:
| if content.as_str() == Some("") { | |
| if content.as_str() == Some("") || content.as_array().is_some_and(Vec::is_empty) { | |
| content = Value::Null; | |
| } |
Confidence: high that the string branch is dead; medium that an empty array is a real replay problem (I can't test against the live API here).
Category: quality
There was a problem hiding this comment.
Empty-array normalization and removing the now-redundant string check are left for the release quality pass. The existing fix prevents empty string deltas from creating replay text blocks; no empty-array rejection has been demonstrated.
| Turn::Assistant { native: Some((Api::OpenAi, m)), .. } => messages.push(m.clone()), | ||
| Turn::Assistant { native: Some((Api::OpenAi, m)), .. } => { | ||
| let mut message = m.clone(); | ||
| // Mistral thinking/signature blocks are not valid assistant content for other |
There was a problem hiding this comment.
For Mistral, this keeps the full native message, including every thinking block and its signature, and sends it back on each later request. Compaction does not reclaim that space. compact::trim (crates/assistant/src/compact.rs:157-167) strips thinking only for Api::Responses (reasoning) and Api::Anthropic (thinking, redacted_thinking). For Api::OpenAi it matches _ => &[], and it only edits native values that are arrays, while this one is an object. So Mistral thinking stays in every request for the rest of the conversation, and compact::size counts it toward the budget. That makes compaction trigger earlier and raises per-turn tokens for the whole session. Either drop the thinking parts from older OpenAI-shaped native turns in trim (the way the Anthropic branch does), or say in the PR why replay must keep them for all turns. Confidence: medium-high from reading the code; I have not measured the size.
Category: performance
There was a problem hiding this comment.
Full compaction does reclaim these blocks: compact::apply drains the summarized turns, including their native payloads. The earlier trimming pass does not strip OpenAI-shaped thinking, as noted. Adding that optimization, with provider replay validation, is left for the release quality pass; native reasoning is retained until the existing summary path replaces those turns.
Code reviewReviewed PR #3185 (Mistral provider). I read the full diff, the base-branch AGENTS.md, the prior threads, and the code around the changed lines ( Bugs
Security
Performance
Quality
AGENTS.md
Earlier concerns left alone: 3.
Change sizeCompared with the base branch (merge base 9b0f0f9 to PR head be0e048).
|
|
Bounding the provider-supplied content-kind label further is left for the release quality pass. Its current size remains bounded by the response limit. |
Summary
Adds Mistral AI's first-party API to the Assistant provider picker and CLI, using
MISTRAL_API_KEYand the existing streamed OpenAI-compatible transport. The default is the generally availablemistral-small-2603; Large 4 is a preview whose training exceptions make it unsuitable as the default. The same privacy description appears in settings and the guide; the guide explains the EU address override.An older first-party Mistral model card requires nine alphanumeric characters for tool-call IDs; this preset applies that compatible format to all requests. Outgoing requests remap call IDs and matching results together, including native messages from another compatible provider, without changing conversation storage or requests to other providers. Ordinals avoid hash/truncation collisions. Picture captions retain original IDs as provenance.
The parser also accepts Mistral's documented typed text/thinking chunks, showing only visible text while preserving the native blocks and signatures for replay. It handles mixed string/array stream chunks and whole replies. Unsupported display parts, such as references, produce one counted transcript notice per type while their native payload remains intact. Thinking stays out of the displayed answer, and empty stream deltas do not add empty text blocks.
As with other keyed presets, environment-based selection uses Mistral when its key is set and no earlier preset has a key.
No affiliation with Mistral. Operator: Mistral AI SAS, France. Primary sources: model and capabilities, chat API, commercial terms §4, retention policy §5 (chat API content is normally kept for 30 rolling days for abuse monitoring, unless ZDR is activated), training controls, and the first-party model-card ID requirement. No other project's code was followed.
Shared preset/transport reaches desktop, browser, CLI and phone. Python/MCP/plugins use existing commands and need no new interface. No project-data copies or undoable map mutation are added; switching provider uses existing conversation behavior.
Testing
Tests cover native/cross-provider call/result pairing, distinct IDs and isolation from OpenAI, plus model-list authentication and typed-content parsing/preview/replay. Independent review completed; formatting and local preflight passed. Full fork CI passed on
be0e0483910ef2cd139f3a3e33c60ebada75e57fin 30 minutes. The three new protocol fixtures passed locally (about 0.018 seconds combined on warm runs, including process startup); the typed-stream regression also failed with the old parser and passed with this change. The additional transcript-notice regression covers streamed and whole replies, exact per-type counts and native preservation; it fails when either notice reporting or empty-delta filtering is reverted. It takes 0.032–0.043 seconds on warm runs, including startup, versus 0.006–0.008 seconds with that test skipped. Formatting, preflight and targeted translation-template checks passed. Rendered and inspected the actual Mistral settings and before/after transcript using a synthetic response. Browser-origin CORS preflight returned 200 and allows Authorization and Content-Type. No API key was available, so authenticated model, image and tool streaming have not been live-tested. In particular, tool-returned image role ordering and fragmented thinking/signature replay remain unverified against the live service.UI evidence
Before the content notice:
After:
Related issue
Follows merged #3171. This diff now contains only the Mistral addition and its protocol support. Azure is outside this scope.
Summary by CodeRabbit