Skip to main content

Calculator Agent

A mathematical calculator agent with various calculation tools using the OpenAI API.

Features

The calculator agent provides 8 specialized mathematical tools:

Basic Arithmetic

  • add_numbers - Addition of two numbers
  • subtract_numbers - Subtraction
  • multiply_numbers - Multiplication
  • divide_numbers - Division (with zero-check)

Financial Calculations

  • calculate_compound_interest - Compound interest calculator with customizable compounding periods

Geometric Calculations

  • calculate_circle_area - Circle area from radius
  • calculate_triangle_area - Triangle area from base and height

Unit Conversions

  • convert_temperature - Temperature conversion between Celsius, Fahrenheit, and Kelvin

Setup

1. Install Dependencies

This installs:
  • openai-agents - OpenAI Agents SDK with all dependencies

2. Set OpenAI API Key

Get your API key from: https://platform.openai.com/api-keys

3. Deploy with Orpheus

Usage

Example Queries

Try these calculation requests:

Testing with Orpheus

Once deployed, invoke the agent:

Configuration

Agent settings from agent.yaml:

Tool Details

add_numbers(a, b)

subtract_numbers(a, b)

multiply_numbers(a, b)

divide_numbers(a, b)

calculate_compound_interest(principal, rate, time, compounds_per_year=1)

calculate_circle_area(radius)

calculate_triangle_area(base, height)

convert_temperature(temperature, from_unit, to_unit)

Error Handling

The agent handles errors gracefully:
  • Missing query: Returns error with usage instructions
  • Division by zero: Tool returns error message
  • Invalid values: Tools validate inputs (negative radius, etc.)
  • API failures: Handler catches exceptions and returns error dict

File Structure

Troubleshooting

Agent fails with “OPENAI_API_KEY not found”

Set the environment variable before starting the server:

Timeout errors

Increase timeout in agent.yaml if calculations take longer than 60s:

Import errors

Run setup.sh to install dependencies:

Next Steps

  1. Deploy the agent: orpheus deploy .
  2. Test with example queries above
  3. Try more complex calculations and tool combinations

Source Code