calculator_tools.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export your OpenAI API key
4
Run the example
Save the code above as
calculator_tools.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Solve step-by-step arithmetic with CalculatorTools, filtering functions via include and exclude lists.
"""
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"
)
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U agno openai
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
Run the example
calculator_tools.py, then run:python calculator_tools.py
Was this page helpful?