Skip to main content

Function

Tool identifier calculator. calculator safely evaluates arithmetic expressions for the agent, including the four basic operations, percentage conversions, powers and roots, logarithms, and common trigonometric functions. The expression is parsed and reduced to numbers, arithmetic operators, constants, and a function allowlist; it cannot reference variables, access attributes, or run arbitrary Python code. Import path: from veadk.tools.builtin_tools.calculator import calculator

Prerequisites

Environment variables:
  • MODEL_AGENT_API_KEY: API key for the agent’s reasoning model (the calculator tool itself needs no extra credentials and accesses no external services)

Usage

examples/tools/calculator/agent.py
It can also be called directly from plain Python:

Parameters

Supported expression syntax:
  • Operators: +, -, *, /, //, %, **, plus unary signs
  • Constants: pi, e
  • Functions: abs, round, min, max, sqrt, log, log10, exp, sin, cos, tan, floor, ceil
Success returns {"expression": ..., "result": ...}: integer results stay integers and float results are rounded to precision decimal places. An invalid or out-of-limits expression returns {"error": ...}.

Notes

Security and limits:
  • The absolute value of a power exponent must not exceed 100; intermediate and final results must be finite real numbers with an absolute value no greater than 1×10¹⁰⁰, and division by zero returns an error.
  • log is the natural logarithm; functions accept positional arguments only, not keyword arguments.
  • Strings, booleans, complex numbers, name references, attribute access, subscripts, and comprehensions are rejected; the tool neither reads or writes files nor makes network requests.
Last modified on November 24, 2026