Skip to main content
The CalculatorTool provides basic arithmetic operations for agents, enabling precise numerical calculations.

Class Signature

Methods

The calculator provides four basic arithmetic operations, all decorated with @capability to make them available to agents.

add

Add two numbers together.
a
float
required
The first number.
b
float
required
The second number.
Returns: String representation of the sum.

subtract

Subtract the second number from the first.
a
float
required
The first number.
b
float
required
The second number to subtract.
Returns: String representation of the difference.

multiply

Multiply two numbers.
a
float
required
The first number.
b
float
required
The second number.
Returns: String representation of the product.

divide

Divide the first number by the second.
a
float
required
The numerator.
b
float
required
The denominator (divisor).
Returns: String representation of the quotient, or “Error: Division by zero” if b is 0.

Usage Example

With Agentor Agent

Multi-Step Calculations

The agent can chain multiple operations together:

Combined with Other Tools

Error Handling

The tool handles division by zero gracefully:

Return Type

All methods return string representations of numbers to ensure compatibility with LLM agents and avoid floating-point precision issues in downstream processing.

Precision

The calculator uses Python’s float type, which provides:
  • Approximately 15-17 decimal digits of precision
  • Support for very large and very small numbers
  • Standard floating-point arithmetic behavior
For applications requiring arbitrary precision, consider implementing a custom tool using Python’s decimal module.

Best Practices

  1. Use for Accuracy: Prefer calculator tool over LLM arithmetic for precise calculations
  2. Chain Operations: Break complex formulas into multiple steps
  3. Validate Results: Have the agent explain calculations when needed
  4. Combine Tools: Use with web search for real-time data calculations
Source: /home/daytona/workspace/source/src/agentor/tools/calculator.py:4
Last modified on May 5, 2026