f5dfb1413e
* 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
2.3 KiB
2.3 KiB
Get Started with Microsoft Agent Framework Mistral AI
Please install this package:
pip install agent-framework-mistral --pre
and see the README for more information.
See the Mistral agent sample and the Mistral embedding sample for runnable examples.
Chat Client
The MistralChatClient provides chat completions using Mistral AI models, with support for
streaming, function tools, and structured output.
Quick Start
from agent_framework import Agent
from agent_framework.mistral import MistralChatClient
# Using environment variables (MISTRAL_API_KEY, MISTRAL_CHAT_MODEL)
# Parameters can also be passed directly:
# MistralChatClient(model="mistral-large-latest", api_key="your-api-key")
client = MistralChatClient()
try:
agent = Agent(client=client, instructions="You are a helpful assistant.")
response = await agent.run("Hello!")
print(response.text)
finally:
await client.close()
Configuration
| Environment Variable | Description |
|---|---|
MISTRAL_API_KEY |
Your Mistral AI API key |
MISTRAL_CHAT_MODEL |
Chat model name (e.g., mistral-large-latest) |
MISTRAL_SERVER_URL |
Optional server URL override |
Embedding Client
The MistralEmbeddingClient provides embedding generation using Mistral AI models.
Quick Start
from agent_framework.mistral import MistralEmbeddingClient
# Using environment variables (MISTRAL_API_KEY, MISTRAL_EMBEDDING_MODEL)
client = MistralEmbeddingClient()
try:
# Parameters can also be passed directly:
# MistralEmbeddingClient(model="mistral-embed", api_key="your-api-key")
result = await client.get_embeddings(["Hello, world!", "How are you?"])
for embedding in result:
print(f"Dimensions: {embedding.dimensions}")
print(f"Vector: {embedding.vector[:5]}...")
finally:
await client.close()
Configuration
| Environment Variable | Description |
|---|---|
MISTRAL_API_KEY |
Your Mistral AI API key |
MISTRAL_EMBEDDING_MODEL |
Embedding model name (e.g., mistral-embed) |
MISTRAL_SERVER_URL |
Optional server URL override |