mistral_common.protocol.instruct.tool_calls
ToolChoice = ToolChoiceEnum | NamedToolChoice
module-attribute
Tool choice can be either a ToolChoiceEnum value or a NamedToolChoice instance.
Function(**data)
Bases: FunctionName
Complete function definition for a tool.
Defines a callable function with its schema and metadata. Used within Tool definitions to specify what functions are available.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Function name. Used by the model to identify which function to call. |
description |
str
|
Human-readable description of the function's purpose. Displayed to help users understand when to use this function. |
parameters |
dict[str, Any]
|
JSON Schema object defining the function's parameters. Used for validation and to generate the function call arguments. Must have "type": "object" and define "properties" and optionally "required". |
strict |
bool
|
If |
Examples:
>>> function = Function(
... name="get_current_weather",
... description="Get the current weather in a given location",
... parameters={
... "type": "object",
... "properties": {
... "location": {
... "type": "string",
... "description": "The city and state, e.g. San Francisco, CA",
... },
... "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
... },
... "required": ["location"],
... },
... )
Source code in pydantic/main.py
from_openai(openai_function)
classmethod
Convert an OpenAI function definition to a Mistral Function.
Handles conversion from OpenAI's format, filtering out unknown fields and providing defaults for missing required fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_function
|
dict[str, Any]
|
Dictionary matching OpenAI's function schema. Must contain at least a "name" key. |
required |
Returns:
| Type | Description |
|---|---|
Function
|
Function instance with parameters and description defaulted to |
Function
|
empty dict and empty string respectively if not provided. |
Source code in src/mistral_common/protocol/instruct/tool_calls.py
FunctionCall(**data)
Bases: MistralBase
Represents a function call made by the model.
Contains the function name and its arguments as they would be passed to the actual function.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the function being called. |
arguments |
str
|
JSON string of the arguments to pass to the function. Stored as a string but parsed from/to dict for convenience. |
Examples:
>>> function_call = FunctionCall(
... name="get_current_weather",
... arguments={"location": "San Francisco, CA", "unit": "celsius"},
... )
Source code in pydantic/main.py
validate_arguments(v)
Convert arguments to a JSON string if they are a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
str | dict[str, Any] | None
|
The arguments value. Can be a dict (converted to JSON string),
str (used as-is), or |
required |
Returns:
| Type | Description |
|---|---|
str
|
The arguments as a JSON string. |
Source code in src/mistral_common/protocol/instruct/tool_calls.py
FunctionName(**data)
Bases: MistralBase
Identifier for a function by its name.
Used to reference a function without its full definition.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The function name string. Must be a valid identifier. |
Examples:
Source code in pydantic/main.py
NamedToolChoice(**data)
Bases: MistralBase
Forces the model to call a specific function.
Use this to constrain the model to use a particular function rather than letting it choose from available tools.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
ToolTypes
|
The tool type. Must be ToolTypes.function. |
function |
FunctionName
|
The FunctionName identifying which specific function to call. The model will only use this function, regardless of what tools are available. |
Examples:
>>> named = NamedToolChoice(function=FunctionName(name="get_weather"))
>>> isinstance(named, ToolChoice)
True
Source code in pydantic/main.py
Tool(**data)
Bases: MistralBase
Definition of a tool available to the model.
A tool combines a function definition with metadata about how it should be presented and used.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
ToolTypes
|
The tool type. Must be ToolTypes.function. |
function |
Function
|
The Function definition specifying the callable function, its parameters, and description. |
Examples:
>>> tool = Tool(
... function=Function(
... name="get_current_weather",
... description="Get the current weather in a given location",
... parameters={
... "type": "object",
... "properties": {
... "location": {
... "type": "string",
... "description": "The city and state, e.g. San Francisco, CA",
... },
... "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
... },
... "required": ["location"],
... },
... ),
... )
Source code in pydantic/main.py
from_openai(openai_tool)
classmethod
Create a Tool from an OpenAI tool definition.
Converts OpenAI's tool format to Mistral's format, delegating function
parsing to Function.from_openai.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_tool
|
dict[str, Any]
|
Dictionary matching OpenAI's tool schema. Must have "type" and optionally "function" keys. |
required |
Returns:
| Type | Description |
|---|---|
Tool
|
Tool instance with the function converted from OpenAI format. |
Source code in src/mistral_common/protocol/instruct/tool_calls.py
ToolCall(**data)
Bases: MistralBase
Represents a tool call made by the model during generation.
A tool call wraps a FunctionCall with metadata including a unique ID.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for this tool call. Must be a non-empty string for tokenizer version >= v13. Defaults to "null" for backwards compatibility. |
type |
ToolTypes
|
The tool type. Must be ToolTypes.function. |
function |
FunctionCall
|
The FunctionCall containing the function name and arguments. |
Examples:
>>> tool_call = ToolCall(
... id="call_abc123",
... function=FunctionCall(
... name="get_current_weather",
... arguments={"location": "San Francisco, CA", "unit": "celsius"},
... ),
... )
Source code in pydantic/main.py
from_openai(tool_call)
classmethod
Create a ToolCall from an OpenAI tool call definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call
|
dict[str, Any]
|
Dictionary matching OpenAI's tool call schema. |
required |
Returns:
| Type | Description |
|---|---|
ToolCall
|
ToolCall instance with fields parsed from the OpenAI format. |
Source code in src/mistral_common/protocol/instruct/tool_calls.py
ToolChoiceEnum
Enum controlling how the model selects tools.
Attributes:
| Name | Type | Description |
|---|---|---|
auto |
Model automatically decides whether to call tools. |
|
none |
Model will not call any tools. |
|
any |
Deprecated; use |
|
required |
Model must call at least one available tool. |
Examples: