Code interpreter
Python code execution for data analysis, calculations, and visualizations.
The code interpreter tool gives agents the ability to execute Python code for data analysis, calculations, visualizations, and complex queries.
Create a code interpreter tool
from seekrai import SeekrFlow
from seekrai.types import CreateRunPython
client = SeekrFlow()
code_tool = client.tools.create(
CreateRunPython(
name="my_code_interpreter",
description="Execute Python code for data analysis, calculations, and visualizations."
)
)
print(f"Tool created: {code_tool.id}")Parameters
| Parameter | Required | Description |
|---|---|---|
name | Yes | A unique name for the tool. |
description | Yes | Description that helps the agent understand when to use this tool. |
Link to an agent
from seekrai.types import CreateAgentRequest
agent = client.agents.create(
CreateAgentRequest(
name="DataAnalystBot",
instructions="You are an expert data analyst. Use Python to analyze data, create visualizations, and perform calculations. Always explain your code and findings.",
model_id="meta-llama/Llama-3.3-70B-Instruct",
tool_ids=[code_tool.id]
)
)
print(f"Agent ID: {agent.id}")
print(f"Agent status: {agent.status}")Best practices
Tool description
- Write a description that specifies when the agent should execute code versus answering from its training data — for example, "Use this tool to perform calculations, generate charts, or transform data. Do not use it for general knowledge questions."
- If the agent has access to other tools, clarify how the code interpreter relates to them — for example, "Use code interpreter for calculations and data transformations. Use file search for retrieving company documents."
Updated about 1 month ago
