How powerful can you give you a calling agent using Jon Schema format

In this lesson, we will show empowering the cost of work in unique agents using the General Format. By describing the boundaries of your work with a clear schema, you can make your custom custom tools smooth without an agent – strong, powerful interactions.
We will be using AviationsStack API to obtain Real-Time Flight Status Status, indicating how foreign APIs can be compiled with funnels within the wrong agent.
Step 1: Setting to rely on
To include a negative library
Loading the inapor of an Appropriate API
You can get the API key from
from getpass import getpass
MISTRAL_API_KEY = getpass('Enter Mistral API Key: ')
Loading the Aviation Stack API key
You can sign up for the free API key from the dashboard to get started.
AVIATIONSTACK_API_KEY = getpass('Enter Aviation Stack API: ')
Step 2: Explaining the Custom Work
Next, describes the work of the Python Get_Flight_status () AviationsStack API to find the actual flight. The worker accepts Flight_atara Parameter option as a vital information such as airline, aircraft, travel and aircraft, and organized times. If no one flight is found, the error message returns.
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(" 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 an illegal client and agent
In this step, we create a negative agency that uses to summon the tool to collect real-time flight information. The agent, whose name is Flight Status Agent, prepared to use the “Mists Medium-2505” model installed custom service called Get_Flight_Status. This tool is defined using JSON Schema who accepts one required parameter: Airport code (eg, “AI101”). Once shipping, an agent can automatically urge this activity whenever receiving the relevant user question, enables the integration of seamlessly between the inclusion of natural APIs and the responses of formal API.
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: Starting a conversation and handling phone calling work
In this step, we start a conversation with the airport agent by asking a natural language question: “What is the current Ai101 state?”. The amazing model realizes that you should ask for Get_Flight_Status work and return the application to work. We also contradict the issues, run the work in the AviationsStack API, and restore the result back to the agent using functurmentry. Finally, the model includes an API response and issuing a natural language response in the current flight, printing on 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)
View the letter of writing in Githubub. All credit for this study goes to research for this project. Also, feel free to follow it Sane and don't forget to join ours 95k + ml subreddit Then sign up for Our newspaper.
I am the student of the community engineering (2022) from Jamia Millia Islamia, New Delhi, and I am very interested in data science, especially neural networks and their application at various locations.



