Files
microsoft--agent-framework/python/packages/mistral/AGENTS.md
NekoPunch f5dfb1413e Python: Add Mistral chat client (#7392)
* feat(python): add Mistral chat client

Implements native Mistral support (#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.

* refactor(python): simplify Mistral client per review

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.

* test(python): drop n forwarding assertion

n is typed as unsupported on MistralChatOptions; the option-mapping test
still passed n, failing pyrefly/ty/zuban/mypy in CI.

* refactor(python): drop n from MistralChatOptions

n is not part of the base ChatOptions, so removing the key rejects it
without an explicit None override.

* feat(python): mark Mistral feature usage

Both clients flip the shared FeatureIndex.MISTRAL bit before each
request, matching the feature-usage telemetry other providers emit.

* fix(python): key streamed tool calls by index

Mistral omits the tool call id on continuation fragments, and the
framework only coalesces empty-id fragments into the immediately
preceding call, so interleaved parallel calls merged into the wrong
call with corrupted arguments. Accumulate fragments per (choice,
index) and emit each call only once complete.

* fix(python): restore Mistral SDK client injection

Dropping the mistralai dependency turned the embedding client's
client= parameter into a breaking change for injected SDK clients.
Add http_client= for httpx.AsyncClient and keep client= working:
httpx goes to the REST path, a duck-typed mistralai.Mistral goes
through the legacy SDK path with a DeprecationWarning until the
next major release.

* chore(python): tidy Mistral sample header
2026-08-03 06:29:09 +00:00

1.7 KiB

Mistral Package (agent-framework-mistral)

Integration with Mistral AI for chat completions and embedding generation.

Implementation Notes

  • Talks to the Mistral REST API directly over httpx; the official mistralai SDK is not used because its pinned OpenTelemetry requirements conflict with the rest of the framework.

Main Classes

  • MistralChatClient - Chat client for Mistral AI models with function invocation, middleware, and telemetry
  • RawMistralChatClient - Chat client without the batteries-included layers
  • MistralChatOptions - Options TypedDict for Mistral-specific chat parameters
  • MistralSettings - TypedDict settings for Mistral chat configuration
  • MistralEmbeddingClient - Embedding client for Mistral AI models
  • MistralEmbeddingOptions - Options TypedDict for Mistral-specific embedding parameters
  • MistralEmbeddingSettings - TypedDict settings for Mistral configuration

Usage

from agent_framework import Agent
from agent_framework.mistral import MistralChatClient

# Requires MISTRAL_API_KEY environment variable (or pass api_key= directly)
client = MistralChatClient(model="mistral-large-latest")
try:
    agent = Agent(client=client)
    result = await agent.run("Hello!")
finally:
    await client.close()
from agent_framework.mistral import MistralEmbeddingClient

# Requires MISTRAL_API_KEY environment variable (or pass api_key= directly)
client = MistralEmbeddingClient(model="mistral-embed")
try:
    result = await client.get_embeddings(["Hello, world!"])
    print(result[0].vector)
finally:
    await client.close()

Import Path

from agent_framework.mistral import MistralChatClient, MistralEmbeddingClient