Skip to content

Python: Add Mistral chat client - #7392

Open
orangeCatDeveloper wants to merge 2 commits into
microsoft:mainfrom
orangeCatDeveloper:python-mistral-chat-client
Open

Python: Add Mistral chat client#7392
orangeCatDeveloper wants to merge 2 commits into
microsoft:mainfrom
orangeCatDeveloper:python-mistral-chat-client

Conversation

@orangeCatDeveloper

@orangeCatDeveloper orangeCatDeveloper commented Jul 29, 2026

Copy link
Copy Markdown

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

  • What are the major changes?
    • New MistralChatClient / RawMistralChatClient in agent-framework-mistral with streaming, tool calling, structured output, multimodal input, and reasoning content, plus a runnable agent sample and docs.
    • Both the new chat client and the existing embedding client talk to the Mistral REST API directly over httpx instead of the mistralai SDK: the SDK pins opentelemetry-semantic-conventions<0.61, which is unsatisfiable next to the workspace's OpenTelemetry stack (pinned to 0.64b0 by microsoft-opentelemetry). Same approach as LangChain's langchain-mistralai and LiteLLM; keeps the package in core[all] with a clean pip check.
    • Integration tests wired into the misc CI job, skipping gracefully when MISTRAL_API_KEY is unset.
  • What is the impact of these changes?
    • from agent_framework.mistral import MistralChatClient now works; agent-framework[all] includes Mistral again. No changes to other packages' behavior; the mistralai dependency is dropped in favor of httpx.
  • What do you want reviewers to focus on?
    • Streaming tool-call handling: Mistral may split IDs/names/arguments across chunks and interleave parallel calls, and omits IDs on some paths (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.MockTransport asserting real wire JSON; mypy/pyright strict clean; live runs against api.mistral.ai covering chat, streaming, agent tool loop, structured output, embeddings (incl. output_dimension on codestral-embed), and both samples.

Note for maintainers: running the CI integration tests requires the MISTRAL_API_KEY secret and MISTRAL_CHAT_MODEL_ID/MISTRAL_EMBEDDING_MODEL_ID repo vars; without them the tests skip.

Related Issue

Fixes #7366

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings July 29, 2026 11:56
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Jul 29, 2026
@orangeCatDeveloper

Copy link
Copy Markdown
Author

@orangeCatDeveloper please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

Copilot AI 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.

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 / RawMistralChatClient using httpx + SSE streaming, including tool-call ID sanitization and streamed tool-call fragment coalescing.
  • Rework MistralEmbeddingClient to use direct REST calls over httpx and 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.

Comment thread python/packages/mistral/agent_framework_mistral/_chat_client.py Outdated
Comment thread python/samples/02-agents/providers/mistral/mistral_agent_basic.py
Comment thread python/packages/mistral/agent_framework_mistral/_chat_client.py
@eavanvalkenburg

Copy link
Copy Markdown
Member

Please make sure to use the defined PR template @orangeCatDeveloper

@github-actions

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/mistral/agent_framework_mistral
   _chat_client.py4580100% 
   _embedding_client.py930100% 
TOTAL46074447790% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9471 34 💤 0 ❌ 0 🔥 2m 23s ⏱️

@eavanvalkenburg eavanvalkenburg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread .github/workflows/integration-tests-manual.yml Outdated
Comment thread .github/workflows/python-integration-tests.yml Outdated
Comment thread python/packages/mistral/README.md Outdated
Comment thread python/packages/mistral/agent_framework_mistral/_chat_client.py Outdated
Comment thread python/packages/mistral/agent_framework_mistral/_chat_client.py Outdated
Comment thread python/packages/mistral/agent_framework_mistral/_chat_client.py Outdated
Comment thread python/packages/mistral/agent_framework_mistral/_chat_client.py Outdated
@orangeCatDeveloper

orangeCatDeveloper commented Jul 29, 2026

Copy link
Copy Markdown
Author

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Mistral Chat Client implementation

3 participants