Python: migrate Mistral integration to official SDK - #7960
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3cc4a2d5-640a-4c05-8fc9-abe08f8134ee
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
Migrates the Python Mistral integration from custom HTTP/SSE handling to the official mistralai SDK.
Changes:
- Replaces manual chat and embedding transports with SDK calls and models.
- Adds service-tier and extended usage metadata.
- Updates dependencies, documentation, and tests for SDK behavior.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
python/uv.lock |
Locks the Mistral SDK and transitive dependencies. |
python/packages/mistral/pyproject.toml |
Replaces the HTTP dependency with mistralai. |
python/packages/mistral/AGENTS.md |
Documents the SDK-based architecture. |
python/packages/mistral/agent_framework_mistral/_chat_client.py |
Migrates chat and streaming behavior to the SDK. |
python/packages/mistral/agent_framework_mistral/_embedding_client.py |
Migrates embedding requests to the SDK. |
python/packages/mistral/tests/mistral/test_mistral_chat_client.py |
Updates chat and streaming tests. |
python/packages/mistral/tests/mistral/test_mistral_embedding_client.py |
Updates embedding and client-injection tests. |
Suppressed comments (1)
python/packages/mistral/agent_framework_mistral/_chat_client.py:458
- Malformed streamed events no longer retain the existing invalid-response mapping. The SDK SSE decoder raises a Pydantic validation error for malformed JSON or an invalid chunk shape, but this catch-all converts it to
ChatClientException; before this migration these cases raisedChatClientInvalidResponseException. Catch decoder/validation failures separately and wrap them asChatClientInvalidResponseException, while leaving transport failures on the generic path.
except Exception as ex:
raise ChatClientException(
f"Mistral streaming chat request failed: {ex}",
inner_exception=ex,
) from ex
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3cc4a2d5-640a-4c05-8fc9-abe08f8134ee
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3cc4a2d5-640a-4c05-8fc9-abe08f8134ee
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): d6dcfade1b6f
Model: gpt-5.6-sol
Overview
The migration delegates transport, SSE parsing, schema validation, and API errors to the official SDK while preserving client injection, ownership tracking, response translation, and broad tool-call/usage coverage. The added tests establish most request and response mappings, including fragmented streaming tool calls and client-close ownership. Residual risks remain around per-call transport overrides, abandoned stream cleanup, timeout compatibility, and the deprecated embedding client path.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
4 verified findings remained after source verification (2 high, 2 medium) across 2 files. Details are attached to the affected lines below.
Affected areas: python/packages/mistral/agent_framework_mistral/_chat_client.py, python/packages/mistral/agent_framework_mistral/_embedding_client.py
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3cc4a2d5-640a-4c05-8fc9-abe08f8134ee
Motivation & Context
The Mistral integration currently maintains its own HTTP, SSE, response-validation, and error-handling code because older
mistralaireleases constrained OpenTelemetry semantic conventions incompatibly with Agent Framework. Mistral SDK 2.9.2 relaxed that constraint, allowing the official SDK to resolve with the framework's OpenTelemetry stack and replace duplicated transport logic.Description & Review Guide
mistralai, translates SDK models directly into Agent Framework types, preserves injectable SDK and HTTP clients with a deprecated HTTP-client compatibility path, and adds support for service tiers plus extended cache/audio usage metadata.mistralai.client.Mistralinstances rather than structurally compatible wrappers; this intentionally tightens the API of the unreleased beta package.Related Issue
N/A — requested directly; no issue is required for this contribution.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.