Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      CodeSOD: A Unique Way to Primary Key

      July 22, 2025

      BrowserStack launches Figma plugin for detecting accessibility issues in design phase

      July 22, 2025

      Parasoft brings agentic AI to service virtualization in latest release

      July 22, 2025

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 22, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 22, 2025

      I’m a wearables editor and here are the 7 Pixel Watch 4 rumors I’m most curious about

      July 22, 2025

      8 ways I quickly leveled up my Linux skills – and you can too

      July 22, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025
      Recent

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 22, 2025

      Execute Ping Commands and Get Back Structured Data in PHP

      July 22, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025
      Recent

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025

      “I don’t think I changed his mind” — NVIDIA CEO comments on H20 AI GPU sales resuming in China following a meeting with President Trump

      July 22, 2025

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Machine Learning»How to Enable Function Calling in Mistral Agents Using the Standard JSON Schema Format

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

    June 8, 2025

    In this tutorial, we’ll demonstrate how to enable function calling in Mistral Agents using the standard JSON schema format. By defining your function’s input parameters with a clear schema, you can make your custom tools seamlessly callable by the agent—enabling powerful, dynamic interactions.

    We will be using the AviationStack API to retrieve real-time flight status data, showcasing how external APIs can be integrated as callable functions within a Mistral Agent.

    Step 1: Setting up dependencies

    Installing the Mistral library

    Copy CodeCopiedUse a different Browser
    pip install mistralai

    Loading the Mistral API Key

    You can get an API key from https://console.mistral.ai/api-keys

    Copy CodeCopiedUse a different Browser
    from getpass import getpass
    MISTRAL_API_KEY = getpass('Enter Mistral API Key: ')

    Loading the Aviation Stack API Key

    You can sign up for a free API key from their dashboard to get started.

    Copy CodeCopiedUse a different Browser
    AVIATIONSTACK_API_KEY = getpass('Enter Aviation Stack API: ')

    Step 2: Defining the Custom Function

    Next, we define a Python function get_flight_status() that calls the AviationStack API to retrieve the real-time status of a flight. The function accepts an optional flight_iata parameter and returns key details such as airline name, flight status, departure and arrival airports, and scheduled times. If no matching flight is found, it gracefully returns an error message.

    Copy CodeCopiedUse a different Browser
    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: Creating the Mistral client and Agent

    In this step, we create a Mistral Agent that uses tool-calling to fetch real-time flight information. The agent, named Flight Status Agent, is configured to use the “mistral-medium-2505” model and is equipped with a custom function tool named get_flight_status. This tool is defined using a JSON schema that accepts a single required parameter: the flight’s IATA code (e.g., “AI101”). Once deployed, the agent can automatically invoke this function whenever it detects a relevant user query, enabling seamless integration between natural language inputs and structured API responses.

    Copy CodeCopiedUse a different Browser
    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 the Conversation and handling Function Calling

    In this step, we initiate a conversation with the Flight Status Agent by asking a natural language question: “What’s the current status of AI101?”. The Mistral model detects that it should invoke the get_flight_status function and returns a function call request. We parse the arguments, run the function locally using the AviationStack API, and return the result back to the agent using FunctionResultEntry. Finally, the model incorporates the API response and generates a natural language reply with the current flight status, which we print to the console.

    Copy CodeCopiedUse a different Browser
    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 out the Notebook on GitHub. All credit for this research goes to the researchers of this project. Also, feel free to follow us on Twitter and don’t forget to join our 95k+ ML SubReddit and Subscribe to our Newsletter.

    The post How to Enable Function Calling in Mistral Agents Using the Standard JSON Schema Format appeared first on MarkTechPost.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous Article50+ Model Context Protocol (MCP) Servers Worth Exploring
    Next Article Meet BioReason: The World’s First Reasoning Model in Biology that Enables AI to Reason about Genomics like a Biology Expert

    Related Posts

    Machine Learning

    How to Evaluate Jailbreak Methods: A Case Study with the StrongREJECT Benchmark

    July 22, 2025
    Machine Learning

    Boolformer: Symbolic Regression of Logic Functions with Transformers

    July 22, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    CVE-2025-6455 – Code-projects Online Hotel Reservation System SQL Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Le notizie minori del mondo GNU/Linux e dintorni della settimana nr 28/2025

    Linux

    CVE-2025-6530 – “70mai M300 Telnet Service Denial of Service Vulnerability”

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-37831 – Apple Soc cpufreq Null Pointer Dereference

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CVE-2025-46530 – HuangYe WuDeng Hacklog Remote Attachment CSRF Stored XSS

    April 24, 2025

    CVE ID : CVE-2025-46530

    Published : April 24, 2025, 4:15 p.m. | 2 hours, 44 minutes ago

    Description : Cross-Site Request Forgery (CSRF) vulnerability in HuangYe WuDeng Hacklog Remote Attachment allows Stored XSS. This issue affects Hacklog Remote Attachment: from n/a through 1.3.2.

    Severity: 7.1 | HIGH

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    How to Install DeepSeek on Ubuntu 24.04 (Locally)

    June 15, 2025

    The iPad Mini is on sale right now, but I love this gaming tablet more and it’s STILL $50 cheaper

    July 8, 2025

    Suraksha Catalyst and The Cyber Express to Launch Candid On-Site Podcast Series at Black Hat USA 2025

    July 4, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.