Calculator Tools

Solve step-by-step arithmetic with CalculatorTools, filtering functions via include and exclude lists.

calculator_tools.py
"""
Calculator Tools
=============================

Demonstrates calculator tools.
"""

from agno.agent import Agent
from agno.tools.calculator import CalculatorTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


# Example 1: Include specific calculator functions for basic operations
basic_calc_agent = Agent(
    tools=[CalculatorTools(include_tools=["add", "subtract", "multiply", "divide"])],
    markdown=True,
)

# Example 2: Exclude advanced functions for simple use cases
simple_calc_agent = Agent(
    tools=[CalculatorTools(exclude_tools=["factorial", "is_prime", "exponentiate"])],
    markdown=True,
)

# Example 3: Full calculator functionality (default)
agent = Agent(
    tools=[CalculatorTools()],
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    simple_calc_agent.print_response(
        "What is 10*5 then to the power of 2, do it step by step"
    )

The run uses simple_calc_agent, which excludes exponentiate. It can still square 50 by calling multiply(50, 50). To demonstrate the power tool directly, run the prompt on agent, whose toolkit includes it.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as calculator_tools.py, then run:

python calculator_tools.py

Full source: cookbook/91_tools/calculator_tools.py