Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Mistralai Client python ToolCall Model

From Leeroopedia
Knowledge Sources
Domains Function_Calling, API_Design
Last Updated 2026-02-15 14:00 GMT

Overview

Concrete tool for representing and parsing function call requests from model responses provided by the ToolCall and FunctionCall models.

Description

ToolCall and FunctionCall are Pydantic models representing a model's request to invoke a function. ToolCall contains a unique id (for linking results back), a type ("function"), and a function field of type FunctionCall. FunctionCall contains the name of the function to call and arguments as a JSON-encoded string.

Usage

Access these models from response.choices[0].message.tool_calls after a chat completion that includes tool definitions. Parse tool_call.function.arguments with json.loads() to get a dictionary of arguments.

Code Reference

Source Location

  • Repository: client-python
  • File: src/mistralai/client/models/toolcall.py (L1-26), src/mistralai/client/models/functioncall.py (L1-23)

Signature

class FunctionCall(BaseModel):
    name: str
    arguments: str  # JSON-encoded arguments

class ToolCall(BaseModel):
    id: str
    function: FunctionCall
    type: Optional[ToolTypes] = None

Import

from mistralai.models import ToolCall, FunctionCall
# Typically accessed via response.choices[0].message.tool_calls

I/O Contract

Inputs

Name Type Required Description
response ChatCompletionResponse Yes Response from chat.complete() with tools

Outputs

Name Type Description
tool_calls List[ToolCall] List of function call requests from the model
tool_call.id str Unique ID for linking results back
tool_call.function.name str Name of function to call
tool_call.function.arguments str JSON string of function arguments

Usage Examples

Detect and Parse Tool Calls

import json

response = client.chat.complete(
    model="mistral-large-latest",
    messages=[UserMessage(content="What's the weather in Paris?")],
    tools=[weather_tool],
)

# Check if model wants to call tools
message = response.choices[0].message
if message.tool_calls:
    for tool_call in message.tool_calls:
        name = tool_call.function.name
        args = json.loads(tool_call.function.arguments)
        call_id = tool_call.id
        print(f"Call {name}({args}), id={call_id}")

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment