Mysteral agents enable API developers to create smart, modular agents equipped with various capabilities. Key features include:
- Support for different multimodal models, covers both text and image -based interactions.
- Conversation memory allows agents to maintain reference to multiple user messages.
- Relief to coordinate between individual models, single agents or multiple agents in the same stream.
- Built-in of essential tools such as code execution, web browsing, image generation and document library.
- A powerful agent handoff mechanism enables agents to collaborate by passing tasks between each other as needed.
In this guide, we will show how to create a basic math-hull agent using Mysteral Agents API. Our agent will use the Code Interpreter Tool to handle and solve math problems as programm.
Step 1: Setting up dependence
Establishing a Mysteral Library
Loading Mysterl API key
You can get the API key from https://console.mistral.ai/api-keys
from getpass import getpass
apiKey = getpass('Enter Mistral API Key: ')
Step 2: Creating a Mysteral Client and Agent
The following code creates a custom math agent using Myster’s Agents API. Agent, named Mathematical assistantOrganized to solve mathematical problems, evaluate expressions, and explain concepts. It uses Incorrect medium -2505 Model with Myster’s Built-in Code_INTERPRETER The tool allows it to run the Python code when needed. The agent is initiated with clear instructions to ensure accurate and concentrated answers and tuned with specific full dimensions.
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 an agent
Starting a conversation
The following code begins a new conversation with Meth_Gent, asking him to solve the quadrilateral equation 2x² + 3x – 2 = 0. Start () method sends an input query to the agent, which uses clear model and tools (like code interpreters) to produce feedback. The result, including the assistant’s explanation and code execution, is stored in the feedback variable.
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 obtain the final output and executed code:
response.outputs(2).content
print(response.outputs(1).info('code'))
Plot the results of the executed code
response = client.beta.conversations.append(
conversation_id=response.conversation_id, inputs="Plot the function f(x) = 2x² + 3x - 2"
)
Continuing a conversation using Conversations Ensures that the agent maintains reference and pushes previous interactions, allowing more natural and consistent dialogue.
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 Image_genrated PNG In the current directory. We can display the same by using the following code
from IPython.display import Image, display
image_path = "image_generated.png"
display(Image(filename=image_path))
Check the notebook here. All credit for this research goes to researchers of this project. Also, feel free to follow us Twitter And don’t forget to join us 95K+ ML Subredit And subscribe Our newsletter.

I am Jamia Milia Islamia, New Delhi Civil Engineering Graduate (2022) and I am more interested in their application in the data, especially the neural network and in various fields.