Python: Add Mistral chat client - #7392
Conversation
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Pull request overview
Adds a native Python MistralChatClient to the agent-framework-mistral integration, and switches both chat + embeddings to call the Mistral REST API directly via httpx (removing the mistralai SDK dependency to avoid OpenTelemetry version conflicts). This expands the Mistral provider feature set (streaming, tool calling, structured output, multimodal inputs, reasoning content), and wires the package into CI test runs.
Changes:
- Implement
MistralChatClient/RawMistralChatClientusinghttpx+ SSE streaming, including tool-call ID sanitization and streamed tool-call fragment coalescing. - Rework
MistralEmbeddingClientto use direct REST calls overhttpxand update unit/integration tests accordingly. - Add/refresh runnable samples + docs, and include Mistral tests + secrets/vars wiring in Python CI workflows.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| python/uv.lock | Drops mistralai and locks httpx as the Mistral package dependency. |
| python/samples/README.md | Documents required Mistral environment variables for samples. |
| python/samples/02-agents/providers/mistral/README.md | Updates provider sample README to include chat + agent sample. |
| python/samples/02-agents/providers/mistral/mistral_embeddings.py | Updates embeddings sample to close the client and clarifies options. |
| python/samples/02-agents/providers/mistral/mistral_agent_basic.py | Adds a runnable agent sample demonstrating tool use + streaming. |
| python/packages/mistral/tests/mistral/test_mistral_embedding_client.py | Replaces SDK-mocking tests with httpx.MockTransport wire-JSON tests and adds error cases. |
| python/packages/mistral/tests/mistral/test_mistral_chat_client.py | Adds comprehensive unit + integration coverage for the new chat client (streaming, tools, structured output, errors). |
| python/packages/mistral/README.md | Adds chat client documentation and refreshes embedding docs with proper client closing. |
| python/packages/mistral/pyproject.toml | Replaces mistralai dependency with httpx. |
| python/packages/mistral/AGENTS.md | Updates package documentation to include chat client and REST-over-httpx implementation notes. |
| python/packages/mistral/agent_framework_mistral/_embedding_client.py | Reimplements embeddings via REST + httpx, adds close semantics and improved error wrapping. |
| python/packages/mistral/agent_framework_mistral/_chat_client.py | New REST-based chat client with streaming SSE parsing, tool calling, structured output, and telemetry/middleware layers. |
| python/packages/mistral/agent_framework_mistral/init.py | Exports new chat client types and settings. |
| python/packages/core/tests/core/test_mistral_namespace.py | Ensures the agent_framework.mistral namespace exposes the new Mistral chat exports. |
| python/packages/core/agent_framework/mistral/init.pyi | Updates type-stub exports for the new Mistral chat types. |
| python/packages/core/agent_framework/mistral/init.py | Adds lazy-import mapping for the new Mistral chat exports. |
| python/.env.example | Adds MISTRAL_CHAT_MODEL and MISTRAL_SERVER_URL examples. |
| .github/workflows/python-merge-tests.yml | Includes Mistral package tests in the “misc” Python workflow and wires Mistral secrets/vars. |
| .github/workflows/python-integration-tests.yml | Includes Mistral package tests in integration workflow and wires Mistral secrets/vars. |
| .github/workflows/integration-tests-manual.yml | Adds MISTRAL_API_KEY secret to the manual integration workflow environment. |
|
Please make sure to use the defined PR template @orangeCatDeveloper |
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||
eavanvalkenburg
left a comment
There was a problem hiding this comment.
I'm not sure I agree wholeheartedly with not using the mistral package, it tends to ensure a bit better behavior, but I will look into that. Key thing to focus on is all the handling of function calls, most of that should already be covered by the framework, so there is no need to do that inside a provider in this way.
7e73467 to
be8d477
Compare
|
Thanks for the review! All feedback addressed in latest commit |
Implements native Mistral support (microsoft#7366) with streaming, tool calling, and structured output. Talks to the REST API directly over httpx: the mistralai SDK's pinned OpenTelemetry deps conflict with the workspace.
Drop the streamed tool-call accumulator and multi-choice parsing in favor of the framework's built-in fragment merging, mark n unsupported, omit unset strict from json_schema, and leave CI secret wiring to maintainers.
be8d477 to
581018b
Compare
Motivation & Context
Issue #7366 asks for a native Mistral chat client so agents can run on Mistral models with first-class support, instead of having no Python path at all (the package previously only shipped an embedding client). This PR implements it for the Python SDK.
Description & Review Guide
MistralChatClient/RawMistralChatClientinagent-framework-mistralwith streaming, tool calling, structured output, multimodal input, and reasoning content, plus a runnable agent sample and docs.httpxinstead of themistralaiSDK: the SDK pinsopentelemetry-semantic-conventions<0.61, which is unsatisfiable next to the workspace's OpenTelemetry stack (pinned to 0.64b0 bymicrosoft-opentelemetry). Same approach as LangChain'slangchain-mistralaiand LiteLLM; keeps the package incore[all]with a cleanpip check.MISTRAL_API_KEYis unset.from agent_framework.mistral import MistralChatClientnow works;agent-framework[all]includes Mistral again. No changes to other packages' behavior; themistralaidependency is dropped in favor ofhttpx.null/"null"), so fragments are accumulated per(choice, index)and emitted on the finish chunk. Also La Plateforme's 9-char alphanumeric tool-call ID requirement is handled via deterministic sanitization.Verified: 72 unit tests over
httpx.MockTransportasserting real wire JSON; mypy/pyright strict clean; live runs againstapi.mistral.aicovering chat, streaming, agent tool loop, structured output, embeddings (incl.output_dimensiononcodestral-embed), and both samples.Note for maintainers: running the CI integration tests requires the
MISTRAL_API_KEYsecret andMISTRAL_CHAT_MODEL_ID/MISTRAL_EMBEDDING_MODEL_IDrepo vars; without them the tests skip.Related Issue
Fixes #7366
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.