Skip to content

strands.models.mistral

Mistral AI model provider.

class MistralModel(Model)

Defined in: src/strands/models/mistral.py:28

Mistral API model provider implementation.

The implementation handles Mistral-specific features such as:

  • Chat and text completions
  • Streaming responses
  • Tool/function calling
  • System prompts
class MistralConfig(TypedDict)

Defined in: src/strands/models/mistral.py:39

Configuration parameters for Mistral models.

Attributes:

  • model_id - Mistral model ID (e.g., “mistral-large-latest”, “mistral-medium-latest”).
  • max_tokens - Maximum number of tokens to generate in the response.
  • temperature - Controls randomness in generation (0.0 to 1.0).
  • top_p - Controls diversity via nucleus sampling.
  • stream - Whether to enable streaming responses.
def __init__(api_key: str | None = None,
*,
client_args: dict[str, Any] | None = None,
**model_config: Unpack[MistralConfig]) -> None

Defined in: src/strands/models/mistral.py:56

Initialize provider instance.

Arguments:

  • api_key - Mistral API key. If not provided, will use MISTRAL_API_KEY env var.
  • client_args - Additional arguments for the Mistral client.
  • **model_config - Configuration options for the Mistral model.
@override
def update_config(**model_config: Unpack[MistralConfig]) -> None

Defined in: src/strands/models/mistral.py:101

Update the Mistral Model configuration with the provided arguments.

Arguments:

  • **model_config - Configuration overrides.
@override
def get_config() -> MistralConfig

Defined in: src/strands/models/mistral.py:111

Get the Mistral model configuration.

Returns:

The Mistral model configuration.

def format_request(messages: Messages,
tool_specs: list[ToolSpec] | None = None,
system_prompt: str | None = None) -> dict[str, Any]

Defined in: src/strands/models/mistral.py:244

Format a Mistral chat streaming request.

Arguments:

  • messages - List of message objects to be processed by the model.
  • tool_specs - List of tool specifications to make available to the model.
  • system_prompt - System prompt to provide context to the model.

Returns:

A Mistral chat streaming request.

Raises:

  • TypeError - If a message contains a content block type that cannot be converted to a Mistral-compatible format.
def format_chunk(event: dict[str, Any]) -> StreamEvent

Defined in: src/strands/models/mistral.py:290

Format the Mistral response events into standardized message chunks.

Arguments:

  • event - A response event from the Mistral model.

Returns:

The formatted chunk.

Raises:

  • RuntimeError - If chunk_type is not recognized.
@override
async def stream(messages: Messages,
tool_specs: list[ToolSpec] | None = None,
system_prompt: str | None = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any) -> AsyncGenerator[StreamEvent, None]

Defined in: src/strands/models/mistral.py:401

Stream conversation with the Mistral model.

Arguments:

  • messages - List of message objects to be processed by the model.
  • tool_specs - List of tool specifications to make available to the model.
  • system_prompt - System prompt to provide context to the model.
  • tool_choice - Selection strategy for tool invocation. Note: This parameter is accepted for interface consistency but is currently ignored for this model provider.
  • **kwargs - Additional keyword arguments for future extensibility.

Yields:

Formatted message chunks from the model.

Raises:

  • ModelThrottledException - When the model service is throttling requests.
@override
async def structured_output(
output_model: type[T],
prompt: Messages,
system_prompt: str | None = None,
**kwargs: Any) -> AsyncGenerator[dict[str, T | Any], None]

Defined in: src/strands/models/mistral.py:510

Get structured output from the model.

Arguments:

  • output_model - The output model to use for the agent.
  • prompt - The prompt messages to use for the agent.
  • system_prompt - System prompt to provide context to the model.
  • **kwargs - Additional keyword arguments for future extensibility.

Returns:

An instance of the output model with the generated data.

Raises:

  • ValueError - If the response cannot be parsed into the output model.