How to Enable Function Calling in Mistral Agents Using the Standard JSON Schema Format

In this tutorial, we will explain how to enable the job summons in the wrong factors using the standard JSON chart format. By selecting your job entering parameters using a clear scheme, you can make your custom tools to be smoothly connected to the agent – which leads to strong and dynamic reactions.
We’ll use Adiationst API to recover the flight status data in the actual time, with how to incorporate external application programming facades as communicable functions within Mistral agent.
Step 1: Preparation of dependencies
Install Mistral Library
Download the Mistral Application Extra Directory key
You can get the API key from https://console.mistral.AI/api- Keys
from getpass import getpass
MISTRAL_API_KEY = getpass('Enter Mistral API Key: ')
Download API Apric
You can subscribe to a free API key from their dashboard to start.
AVIATIONSTACK_API_KEY = getpass('Enter Aviation Stack API: ')
Step 2: Determine the customer
Next, we define the Python Get_flight_status function () that calls for the Aviationstock applications interface to recover the status in the actual time of the trip. The job accepts an optional Flight_iata parameter and return the main details such as the airline name, flight status, departure and accessible airports, and scheduled times. If a matching journey is not found, it is gracefully returned an error message.
import requests
from typing import Dict
def get_flight_status(flight_iata=None):
"""
Retrieve flight status using optional filters: dep_iata, arr_iata, flight_iata.
"""
params = {
"access_key": AVIATIONSTACK_API_KEY,
"flight_iata": flight_iata
}
response = requests.get("http://api.aviationstack.com/v1/flights", params=params)
data = response.json()
if "data" in data and data["data"]:
flight = data["data"][0]
return {
"airline": flight["airline"]["name"],
"flight_iata": flight["flight"]["iata"],
"status": flight["flight_status"],
"departure_airport": flight["departure"]["airport"],
"arrival_airport": flight["arrival"]["airport"],
"scheduled_departure": flight["departure"]["scheduled"],
"scheduled_arrival": flight["arrival"]["scheduled"],
}
else:
return {"error": "No flight found for the provided parameters."}
Step 3: Create a customer and an agent Mistral
In this step, we create a Mistral agent that uses tools to bring to bring aviation information in actual time. The agent, a journey agent, was formed to use the “Mistral-Medium-2555” model and is equipped with a dedicated functional tool called Get_flight_status. This tool is defined using the JSON chart that accepts one required parameter: the iATA icon for the trip (for example, “AI101”). Once it is published, the agent can automatically call this function whenever the relevant user’s inquiries discover, allowing smooth integration between natural language inputs and structured API responses.
from mistralai import Mistral
client = Mistral(MISTRAL_API_KEY)
flight_status_agent = client.beta.agents.create(
model="mistral-medium-2505",
description="Provides real-time flight status using aviationstack API.",
name="Flight Status Agent",
tools=[
{
"type": "function",
"function": {
"name": "get_flight_status",
"description": "Retrieve the current status of a flight by its IATA code (e.g. AI101).",
"parameters": {
"type": "object",
"properties": {
"flight_iata": {
"type": "string",
"description": "IATA code of the flight (e.g. AI101)"
},
},
"required": ["flight_iata"]
}
}
}
]
)
Step 4: Start calling and dealing with the conversation job
In this step, we start a conversation with the journey agent by asking a natural language question: “What is the current situation of AI101?” The Mistral model discovers that it should require the function_flight_status function and return the job call. We analyze the media, occupy the function locally using Adiationstack API, and return the result again to the agent using Functionresultney. Finally, the model includes the API response and creates a natural response to the current flight, which we print to the console.
from mistralai import FunctionResultEntry
import json
# User starts a conversation
response = client.beta.conversations.start(
agent_id=flight_status_agent.id,
inputs=[{"role": "user", "content": "What's the current status of AI101?"}]
)
# Check if model requested a function call
if response.outputs[-1].type == "function.call" and response.outputs[-1].name == "get_flight_status":
args = json.loads(response.outputs[-1].arguments)
# Run the function
function_result = json.dumps(get_flight_status(**args))
# Create result entry
result_entry = FunctionResultEntry(
tool_call_id=response.outputs[-1].tool_call_id,
result=function_result
)
# Return result to agent
response = client.beta.conversations.append(
conversation_id=response.conversation_id,
inputs=[result_entry]
)
print(response.outputs[-1].content)
else:
print(response.outputs[-1].content)
Check the notebook on Gabbab. All the credit for this research goes to researchers in this project. Also, do not hesitate to follow us twitter And do not forget to join 95K+ ML Subreddit And subscribe to Our newsletter.
I am a graduate of civil engineering (2022) from Islamic Melia, New Delhi, and I have a strong interest in data science, especially nervous networks and their application in various fields.
Don’t miss more hot News like this! Click here to discover the latest in AI news!
2025-06-08 07:13:00