Calculator
CalculatorTools gives an agent add, subtract, multiply, divide, and other math operations for step-by-step calculations.
CalculatorTools enables an Agent to perform mathematical calculations.
Prerequisites
Create and activate a virtual environment, then install:
uv pip install agno openaiThe Agent model uses an OpenAI key, separately from any toolkit provider credentials.
Set OpenAI Key
Set your OPENAI_API_KEY as an environment variable. You can get one from OpenAI.
export OPENAI_API_KEY=sk-***Example
The following agent will calculate the result of 10*5 and then raise it to the power of 2:
from agno.agent import Agent
from agno.tools.calculator import CalculatorTools
agent = Agent(
tools=[CalculatorTools()],
markdown=True,
)
agent.print_response("What is 10*5 then to the power of 2, do it step by step")Toolkit Functions
| Function | Description |
|---|---|
add | Adds two numbers and returns the result. |
subtract | Subtracts the second number from the first and returns the result. |
multiply | Multiplies two numbers and returns the result. |
divide | Divides the first number by the second and returns the result. Handles division by zero. |
exponentiate | Raises the first number to the power of the second number and returns the result. |
factorial | Calculates the factorial of a number and returns the result. Handles negative numbers. |
is_prime | Checks if a number is prime and returns the result. |
square_root | Calculates the square root of a number and returns the result. Handles negative numbers. |
You can use include_tools or exclude_tools to modify the list of tools the agent has access to. Learn more about selecting tools.