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

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 6, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 6, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 6, 2025

      AI is currently in its teenage years, battling raging hormones

      June 6, 2025

      4 ways your organization can adapt and thrive in the age of AI

      June 6, 2025

      Google’s new Search tool turns financial info into interactive charts – how to try it

      June 6, 2025

      This rugged Android phone has something I’ve never seen on competing models

      June 6, 2025

      Anthropic’s new AI models for classified info are already in use by US gov

      June 6, 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

      Handling PostgreSQL Migrations in Node.js

      June 6, 2025
      Recent

      Handling PostgreSQL Migrations in Node.js

      June 6, 2025

      How to Add Product Badges in Optimizely Configured Commerce Spire

      June 6, 2025

      Salesforce Health Check Assessment Unlocks ROI

      June 6, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft: Run PS script now if you deleted “inetpub” on Windows 11, Windows 10

      June 6, 2025
      Recent

      Microsoft: Run PS script now if you deleted “inetpub” on Windows 11, Windows 10

      June 6, 2025

      Spf Permerror Troubleshooting Guide For Better Email Deliverability Today

      June 6, 2025

      Amap – Gather Info in Easy Way

      June 6, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Machine Learning»Hands-On Guide: Getting started with Mistral Agents API

    Hands-On Guide: Getting started with Mistral Agents API

    June 3, 2025

    The Mistral Agents API enables developers to create smart, modular agents equipped with a wide range of capabilities. Key features include:

    • Support for a variety of multimodal models, covering both text and image-based interactions.
    • Conversation memory, allowing agents to retain context across multiple user messages.
    • The flexibility to engage with individual models, standalone agents, or coordinate between multiple agents in a single flow.
    • Built-in access to essential tools like code execution, web browsing, image generation, and a document library.
    • A powerful agent handoff mechanism, enabling agents to collaborate by passing tasks between each other as needed.

    In this guide, we’ll demonstrate how to build a basic math-solving agent using the Mistral Agents API. Our agent will use the code interpreter tool to handle and solve math problems programmatically.

    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
    apiKey = getpass('Enter Mistral API Key: ')

    Step 2: Creating the Mistral client and Agent

    The following code creates a custom math agent using the Mistral Agents API. The agent, named Math Helper, is configured to solve mathematical problems, evaluate expressions, and explain concepts. It uses the mistral-medium-2505 model along with Mistral’s built-in code_interpreter tool, allowing it to run Python code when needed. The agent is initialized with clear instructions and tuned with specific completion parameters to ensure accurate and focused responses.

    Copy CodeCopiedUse a different Browser
    from mistralai import Mistral
    client = Mistral(apiKey)
    math_agent = client.beta.agents.create(
        model="mistral-medium-2505",
        description="An agent that solves math problems and evaluates expressions.",
        name="Math Helper",
        instructions="You are a helpful math assistant. You can explain concepts, solve equations, and evaluate math expressions using the code interpreter.",
        tools=[{"type": "code_interpreter"}],
        completion_args={
            "temperature": 0.2,
            "top_p": 0.9
        }
    )

    Step 3: Running the Agent

    Initializing the conversation

    The following code initiates a new conversation with the math_agent, asking it to solve the quadratic equation 2x² + 3x – 2 = 0. The start() method sends the input query to the agent, which uses the specified model and tools (like the code interpreter) to generate a response. The result, including the assistant’s explanation and code execution, is stored in the response variable.

    Copy CodeCopiedUse a different Browser
    response = client.beta.conversations.start(
        agent_id=math_agent.id, inputs="Solve the quadratic equation 2x² + 3x - 2 = 0", #store=False
    )
    
    print(response)

    You can use the following code to get the final output and the executed code:

    Copy CodeCopiedUse a different Browser
    response.outputs[2].content
    Copy CodeCopiedUse a different Browser
    print(response.outputs[1].info['code'])

    Plotting the results of the executed code

    Copy CodeCopiedUse a different Browser
    response = client.beta.conversations.append(
        conversation_id=response.conversation_id, inputs="Plot the function f(x) = 2x² + 3x - 2"
    )

    Continuing the conversation using conversations.append ensures that the agent retains the context and builds upon the previous interactions, allowing for a more natural and coherent dialogue.

    Copy CodeCopiedUse a different Browser
    file_id = response.outputs[2].content[0].file_id
    file_bytes = client.files.download(file_id=file_id).read()
    with open(f"image_generated.png", "wb") as file:
        file.write(file_bytes)

    This code will download the generated image as image_generated.png in the current directory. We can display the the same using the following code

    Copy CodeCopiedUse a different Browser
    from IPython.display import Image, display
    image_path = "image_generated.png"
    
    display(Image(filename=image_path))

    Check out the Notebook here. 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 Hands-On Guide: Getting started with Mistral Agents API appeared first on MarkTechPost.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleMistral AI Introduces Codestral Embed: A High-Performance Code Embedding Model for Scalable Retrieval and Semantic Understanding
    Next Article Meta Releases Llama Prompt Ops: A Python Package that Automatically Optimizes Prompts for Llama Models

    Related Posts

    Machine Learning

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

    June 6, 2025
    Machine Learning

    Build a Text-to-SQL solution for data consistency in generative AI using Amazon Nova

    June 6, 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-2024-42191 – HCL Traveler for Microsoft Outlook COM Hijacking Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    I’ve been testing one of the best value 4K OLED gaming monitors, and it’s awesome — but watch out for tariffs

    News & Updates
    Rilasciato OpenSSH 10: Un aggiornamento significativo per la sicurezza e la crittografia

    Rilasciato OpenSSH 10: Un aggiornamento significativo per la sicurezza e la crittografia

    Linux

    Researchers from AWS and Intuit Propose a Zero Trust Security Framework to Protect the Model Context Protocol (MCP) from Tool Poisoning and Unauthorized Access

    Machine Learning

    Highlights

    CVE-2025-45843 – TOTOLINK NR1800X Router Authenticated Stack Overflow Vulnerability

    May 8, 2025

    CVE ID : CVE-2025-45843

    Published : May 8, 2025, 4:15 p.m. | 3 hours, 22 minutes ago

    Description : TOTOLINK NR1800X V9.1.0u.6681_B20230703 was discovered to contain an authenticated stack overflow via the ssid parameter in the setWiFiGuestCfg function.

    Severity: 0.0 | NA

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

    CVE-2025-5179 – Realce Tecnologia Queue Ticket Kiosk Cross-Site Scripting Vulnerability

    May 26, 2025

    Is your phone truly waterproof? Here’s what the IP rating tells you

    February 21, 2025

    Samsung’s new Frame Pro TV is an expensive masterpiece – but you’ll love the features

    April 9, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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