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.The first number.
The second number.
subtract
Subtract the second number from the first.The first number.
The second number to subtract.
multiply
Multiply two numbers.The first number.
The second number.
divide
Divide the first number by the second.The numerator.
The denominator (divisor).
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’sfloat type, which provides:
- Approximately 15-17 decimal digits of precision
- Support for very large and very small numbers
- Standard floating-point arithmetic behavior
decimal module.
Best Practices
- Use for Accuracy: Prefer calculator tool over LLM arithmetic for precise calculations
- Chain Operations: Break complex formulas into multiple steps
- Validate Results: Have the agent explain calculations when needed
- Combine Tools: Use with web search for real-time data calculations
/home/daytona/workspace/source/src/agentor/tools/calculator.py:4