Edit

Mistral

The Mistral integration provides MistralChatClient for chat agents and MistralEmbeddingClient for text embeddings in Agent Framework Python.

Install the package

pip install agent-framework-mistral --pre

Configuration

MISTRAL_API_KEY="<api-key>"
MISTRAL_CHAT_MODEL="mistral-small-latest"
MISTRAL_EMBEDDING_MODEL="mistral-embed"
# Optional compatible endpoint:
MISTRAL_SERVER_URL="<server-url>"

You can also pass api_key, model, and server_url directly to either client.

Create a chat agent

Create an Agent with MistralChatClient. The client reads the API key and chat model from the environment variables shown in the previous section.

import asyncio

from agent_framework import Agent
from agent_framework.mistral import MistralChatClient


async def main() -> None:
    client = MistralChatClient()
    try:
        agent = Agent(
            client=client,
            instructions="You are a helpful assistant.",
        )
        response = await agent.run("How many days are in a week?")
        print(response.text)
    finally:
        await client.close()


asyncio.run(main())

The selected Mistral model determines which model-level capabilities are available.

Chat capabilities

MistralChatClient supports the following Agent Framework features:

Capability Usage
Streaming Call agent.run(..., stream=True) to iterate over response updates.
Function tools Add Agent Framework function tools to Agent(tools=...).
Structured output Pass a Pydantic model, JSON schema mapping, or JSON object mode through response_format.
Multimodal input Send image data or URLs and PDF document URLs in user messages.
Reasoning Set reasoning_effort for supported models and read returned thinking as text_reasoning content.

For a runnable function-tool and streaming example, see the Mistral agent sample.

Generate embeddings

Create the client and call get_embeddings().

async def basic_embedding_example() -> None:
    """Generate embeddings for a list of texts."""
    print("=== Basic Embedding Generation ===")

    # 1. Create the embedding client using environment-based configuration.
    client = MistralEmbeddingClient()

    # 2. Generate embeddings for multiple texts.
    texts = ["Hello, world!", "How are you?", "Agent Framework with Mistral AI"]
    try:
        result = await client.get_embeddings(texts)

        # 3. Print the generated vectors and usage metadata.
        print(f"Generated {len(result)} embeddings")
        for i, embedding in enumerate(result):
            print(f"  Text {i + 1}: dimensions={embedding.dimensions}, vector={embedding.vector[:5]}...")

        if result.usage:
            print(
                f"  Usage: {result.usage['input_token_count']} input tokens, "
                f"{result.usage['total_token_count']} total tokens"
            )
    finally:
        await client.close()


async def embedding_with_options_example() -> None:
    """Generate embeddings with custom dimensions."""
    print("\n=== Embedding with Custom Dimensions ===")

    from agent_framework.mistral import MistralEmbeddingOptions

    # Only some models support a custom output dimension (e.g. codestral-embed; mistral-embed does not).
    client = MistralEmbeddingClient(model="codestral-embed")

    options: MistralEmbeddingOptions = {"dimensions": 256}

Use MistralEmbeddingOptions to request a supported output dimension. You can also set MISTRAL_SERVER_URL when the application uses a custom compatible endpoint.

Important

Mistral AI is a third-party system. Review its service terms, data handling, regional boundaries, model licensing, and usage costs before sending application data.

Tools

MistralChatClient supports locally invoked function tools and the Agent Framework function-invocation loop. The selected model must support function calling.

Next steps

RAG