The Calculator tool provides basic arithmetic computation capabilities for AI agents that need to perform mathematical calculations accurately.
AI agents can use this tool when they need to:
- Perform basic arithmetic operations
- Calculate complex expressions with proper order of operations
- Ensure mathematical accuracy in their computations
- Handle both integer and decimal number calculations
{
"name": "calculator",
"arguments": {
"expression": "2 + 3"
}
}Response:
{
"expression": "2 + 3",
"result": 5
}- Addition:
+ - Subtraction:
- - Multiplication:
* - Division:
/ - Modulo:
% - Exponentiation:
^ - Parentheses:
()for grouping
The calculator follows standard mathematical order of operations (PEMDAS/BODMAS):
- Parentheses/Brackets first
- Exponents (right to left)
- Multiplication and Division (left to right)
- Addition and Subtraction (left to right)
{
"name": "calculator",
"arguments": {
"expression": "2 + 3 * 4"
}
}Returns 14 (not 20) because multiplication is performed before addition.
{
"name": "calculator",
"arguments": {
"expression": "((10 + 5) * 2 - 3) / 9"
}
}Response:
{
"expression": "((10 + 5) * 2 - 3) / 9",
"result": 3
}{
"name": "calculator",
"arguments": {
"expression": "3.14 * 2.5"
}
}Response:
{
"expression": "3.14 * 2.5",
"result": 7.85
}{
"name": "calculator",
"arguments": {
"expression": "-5 + 10"
}
}Response:
{
"expression": "-5 + 10",
"result": 5
}{
"name": "calculator",
"arguments": {
"expression": "2^53 - 1"
}
}Response:
{
"expression": "2^53 - 1",
"result": 9007199254740991
}Note: Exponentiation is right-associative, so 2^3^2 equals 2^(3^2) = 512, not (2^3)^2 = 64.
You must provide either expression or expressions parameter (not both).
- Type: string
- Description: Single mathematical expression to evaluate
- Example:
"2 + 3 * 4"
- Type: array of strings
- Description: Multiple mathematical expressions to evaluate in one call
- Example:
["2 + 3", "10 * 5", "(15 - 3) / 4"]
Each expression can contain:
- Numbers (integers and decimals)
- Basic arithmetic operators (
+,-,*,/,%,^) - Parentheses for grouping
- Unary operators (
+,-) - Whitespace (ignored)
{
"name": "calculator",
"arguments": {
"expression": "25 / 5"
}
}{
"name": "calculator",
"arguments": {
"expression": "150 * 0.20"
}
}{
"name": "calculator",
"arguments": {
"expression": "(1200 - 200) * 0.15 + 50"
}
}{
"name": "calculator",
"arguments": {
"expressions": [
"2 + 3",
"10 * 5",
"(15 - 3) / 4",
"2.5 + 1.5"
]
}
}Response:
{
"results": [
{
"expression": "2 + 3",
"result": 5
},
{
"expression": "10 * 5",
"result": 50
},
{
"expression": "(15 - 3) / 4",
"result": 3
},
{
"expression": "2.5 + 1.5",
"result": 4
}
]
}{
"name": "calculator",
"arguments": {
"expressions": [
"1000 * 0.08",
"1500 * 0.15",
"2000 * 0.12"
]
}
}The calculator provides clear error messages for invalid expressions:
{
"name": "calculator",
"arguments": {
"expression": "10 / 0"
}
}Error: "division by zero"
{
"name": "calculator",
"arguments": {
"expression": "2 + * 3"
}
}Error: "unexpected character '*'"
{
"name": "calculator",
"arguments": {
"expression": "(2 + 3"
}
}Error: "expected closing parenthesis"
- No support for scientific notation (e.g.,
1e6) - No support for functions (e.g.,
sqrt,sin,cos,log) - No support for variables or constants (e.g.,
π,e) - No support for bitwise operations
- Decimal precision limited by floating-point representation