ART Framework API Docs
    Preparing search index...

    Class CalculatorTool

    An ART Framework tool that safely evaluates mathematical expressions using the mathjs library. It supports basic arithmetic, variables via a scope, complex numbers, and a predefined list of safe functions.

    This tool is designed to be used within the ART framework's ToolSystem. It provides a safe way to perform mathematical calculations by leveraging the mathjs library. The tool validates the input expression to ensure it's a single, valid mathematical expression before evaluation.

    Implements

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    schema: ToolSchema = ...

    The schema definition for the CalculatorTool, conforming to the ToolSchema interface. It defines the tool's name, description, input parameters (expression and optional scope), and provides examples for the LLM.

    toolName: "calculator"

    The unique name identifier for this tool.

    Methods

    • Executes the calculator tool by evaluating the provided mathematical expression. It uses a restricted scope including only allowed mathjs functions and any variables passed in the input.scope. Handles basic number and complex number results.

      Parameters

      • input: any

        An object containing the expression (string) and optional scope (object). Must match inputSchema.

      • context: ExecutionContext

        The execution context containing threadId, traceId, etc.

      Returns Promise<ToolResult>

      A promise resolving to a ToolResult object. On success, status is 'success' and output is { result: number | string }. On failure, status is 'error' and error contains the error message.