Skip to content

Python: migrate Mistral integration to official SDK - #7960

Merged
Evan Mattson (moonbox3) merged 4 commits into
microsoft:mainfrom
eavanvalkenburg:eavanvalkenburg-mistral-sdk-migration
Aug 31, 2026
Merged

Python: migrate Mistral integration to official SDK#7960
Evan Mattson (moonbox3) merged 4 commits into
microsoft:mainfrom
eavanvalkenburg:eavanvalkenburg-mistral-sdk-migration

Conversation

@eavanvalkenburg

@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) commented Aug 31, 2026

Copy link
Copy Markdown
Member

Motivation & Context

The Mistral integration currently maintains its own HTTP, SSE, response-validation, and error-handling code because older mistralai releases 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

  • What are the major changes? Replaces manual chat and embedding HTTP calls with 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.
  • What is the impact of these changes? Mistral requests now use the supported SDK transport, streaming parser, schema validation, and API errors while retaining existing Agent Framework message, tool, structured-output, telemetry, timeout, and single-response behavior. Injected embedding SDK clients must now be concrete mistralai.client.Mistral instances rather than structurally compatible wrappers; this intentionally tightens the API of the unreleased beta package.
  • What do you want reviewers to focus on? Client ownership and timeout semantics, direct SDK-model translation for streaming tool calls, and exception/usage mapping.

Related Issue

N/A — requested directly; no issue is required for this contribution.

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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3cc4a2d5-640a-4c05-8fc9-abe08f8134ee
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/mistral/agent_framework_mistral
   _chat_client.py4712894%246, 296–299, 301–305, 310, 312, 317–318, 320, 375, 379, 383, 401–403, 461, 480, 485–488, 857
   _embedding_client.py121695%139, 248, 275–278
   _http_client.py12191%23
TOTAL48276450790% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9836 36 💤 0 ❌ 0 🔥 2m 18s ⏱️

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

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 raised ChatClientInvalidResponseException. Catch decoder/validation failures separately and wrap them as ChatClientInvalidResponseException, 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.

Comment thread python/packages/mistral/agent_framework_mistral/_chat_client.py Outdated
Comment thread python/packages/mistral/agent_framework_mistral/_embedding_client.py Outdated
Comment thread python/packages/mistral/agent_framework_mistral/_chat_client.py Outdated
Comment thread python/packages/mistral/pyproject.toml
Comment thread python/packages/mistral/agent_framework_mistral/_chat_client.py
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

@github-actions github-actions Bot 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.

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

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
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3cc4a2d5-640a-4c05-8fc9-abe08f8134ee
@moonbox3
Evan Mattson (moonbox3) added this pull request to the merge queue Aug 31, 2026
Merged via the queue into microsoft:main with commit 11d628d Aug 31, 2026
37 checks passed
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.

3 participants