Lewati ke konten utama

Calculator Tools

Perfect10 Registry now includes powerful Calculator Tools that enable AI agents to perform accurate mathematical calculations. This feature enhances agents' capabilities for financial analysis, statistical computations, scientific calculations, and data processing.

Overview

Calculator Tools provide agents with the ability to:

  • Perform complex mathematical operations with high precision
  • Handle financial calculations and statistical analysis
  • Execute scientific computations and data transformations
  • Ensure security through built-in validation

Available Mathematical Operations

Basic Arithmetic

  • Addition: +
  • Subtraction: -
  • Multiplication: *
  • Division: /
  • Power: ** or ^
  • Parentheses: () for grouping

Trigonometric Functions

  • Sine: sin(x)
  • Cosine: cos(x)
  • Tangent: tan(x)
  • Arc Sine: asin(x)
  • Arc Cosine: acos(x)
  • Arc Tangent: atan(x)

Hyperbolic Functions

  • Hyperbolic Sine: sinh(x)
  • Hyperbolic Cosine: cosh(x)
  • Hyperbolic Tangent: tanh(x)
  • Inverse Hyperbolic Sine: asinh(x)
  • Inverse Hyperbolic Cosine: acosh(x)
  • Inverse Hyperbolic Tangent: atanh(x)

Logarithmic Functions

  • Natural Logarithm: ln(x) or log(x)
  • Base-10 Logarithm: log10(x)

Power and Root Functions

  • Square Root: sqrt(x)
  • Power: pow(x, y)
  • Exponential: exp(x)

Mathematical Constants

  • Pi (π): pi
  • Euler's Number (e): e

Advanced Functions

  • Absolute Value: abs(x)
  • Floor: floor(x)
  • Ceiling: ceil(x)
  • Round: round(x)
  • Factorial: factorial(x)
  • Greatest Common Divisor: gcd(x, y)
  • Least Common Multiple: lcm(x, y)

Usage Examples

Financial Calculations

Compound Interest

User: "Calculate compound interest for $10,000 at 8% for 5 years"
Agent: Uses calculator with expression: "10000 * (1 + 0.08)^5"
Result: $14,693.28

Discount Calculations

User: "What's the final price after 15% discount on $200?"
Agent: Uses calculator with expression: "200 * (1 - 0.15)"
Result: $170.00

Tax Calculations

User: "Calculate 10% tax on $500 purchase"
Agent: Uses calculator with expression: "500 * 0.10"
Result: $50.00

Statistical Analysis

Averages

User: "Calculate the average of scores: 85, 92, 78, 88, 95"
Agent: Uses calculator with expression: "(85 + 92 + 78 + 88 + 95) / 5"
Result: 87.6

Sums and Aggregations

User: "What's the total sales for the week: Mon=$1200, Tue=$1500, Wed=$1800, Thu=$1400, Fri=$2000?"
Agent: Uses calculator with expression: "1200 + 1500 + 1800 + 1400 + 2000"
Result: 7900

Scientific Calculations

Trigonometric Calculations

User: "What's the sine of 30 degrees?"
Agent: Uses calculator with expression: "sin(30 * pi / 180)"
Result: 0.5

Area Calculations

User: "Calculate the area of a circle with radius 5"
Agent: Uses calculator with expression: "pi * 5^2"
Result: 78.54

Logarithmic Calculations

User: "What's the natural log of 100?"
Agent: Uses calculator with expression: "ln(100)"
Result: 4.605

Data Processing

Percentage Changes

User: "Calculate percentage increase from 80 to 120"
Agent: Uses calculator with expression: "((120 - 80) / 80) * 100"
Result: 50%

Ratio Calculations

User: "What's the ratio of 15 to 25?"
Agent: Uses calculator with expression: "15 / 25"
Result: 0.6

Security Features

Expression Validation

  • All mathematical expressions are validated for safety
  • Prevents execution of malicious code
  • Blocks access to system functions and file operations
  • Validates mathematical syntax before evaluation

Safe Evaluation Environment

  • Restricted mathematical functions only
  • No access to Python built-ins or system calls
  • Isolated execution environment
  • Comprehensive error handling

Best Practices

Writing Expressions

  1. Use Parentheses for clarity in complex expressions
  2. Group Related Operations to avoid confusion
  3. Use Scientific Notation for very large or small numbers
  4. Validate Input before submitting complex calculations

Error Handling

  • Check for division by zero
  • Validate input ranges for functions
  • Handle invalid mathematical operations
  • Provide clear error messages

Integration with Agents

Automatic Tool Selection

  • Agents automatically detect mathematical queries
  • Calculator tool is invoked when needed
  • Results are formatted for easy understanding
  • Context is maintained throughout calculations

Multi-step Calculations

  • Agents can perform complex multi-step calculations
  • Intermediate results are stored and used
  • Final results are presented clearly
  • Calculation steps are explained when requested

Troubleshooting

Common Issues

Invalid Expression

Error: Invalid mathematical expression syntax

Solution: Check parentheses matching and operator usage

Division by Zero

Error: Division by zero

Solution: Ensure denominators are not zero

Function Domain Error

Error: Invalid mathematical operation

Solution: Check input ranges for mathematical functions

Performance Tips

  • Use efficient expressions for large calculations
  • Break complex calculations into smaller steps
  • Cache frequently used values
  • Validate inputs before calculation

API Reference

Tool Definition

{
"name": "calculator",
"description": "Perform mathematical calculations with high precision",
"parameters": {
"type": "object",
"properties": {
"expression": {
"type": "string",
"description": "Mathematical expression to evaluate"
}
},
"required": ["expression"]
}
}

Response Format

Result: [calculated_value]

Error Format

Error: [error_message]

Conclusion

Calculator Tools significantly enhance the capabilities of AI agents in Perfect10 Registry, enabling them to perform accurate mathematical calculations across various domains. Whether for financial analysis, scientific computing, or data processing, agents can now provide precise mathematical results with confidence.