A tool that wraps a user-defined TypeScript function.

This tool automatically generates a function declaration from the function's signature and documentation, making it easy to expose functions to agents.

Type Parameters

  • T extends Record<string, any>

Hierarchy (view full)

Constructors

  • Creates a new FunctionTool wrapping the provided function.

    Type Parameters

    • T extends Record<string, any>

    Parameters

    • func: ((...args: any[]) => any)

      The function to wrap

        • (...args): any
        • Parameters

          • Rest...args: any[]

          Returns any

    • Optionaloptions: {
          name?: string;
          description?: string;
          isLongRunning?: boolean;
          shouldRetryOnFailure?: boolean;
          maxRetryAttempts?: number;
          parameterTypes?: Record<string, string>;
      }

      Optional configuration for the tool

      • Optionalname?: string
      • Optionaldescription?: string
      • OptionalisLongRunning?: boolean
      • OptionalshouldRetryOnFailure?: boolean
      • OptionalmaxRetryAttempts?: number
      • OptionalparameterTypes?: Record<string, string>

    Returns FunctionTool<T>

Properties

name: string

Name of the tool

description: string

Description of the tool

isLongRunning: boolean

Whether the tool is a long running operation, which typically returns a resource id first and finishes the operation later.

shouldRetryOnFailure: boolean

Whether the tool execution should be retried on failure

maxRetryAttempts: number

Maximum retry attempts

baseRetryDelay: number = 1000

Base delay for retry in ms (will be used with exponential backoff)

maxRetryDelay: number = 10000

Maximum delay for retry in ms

logger: Logger = ...

Accessors

Methods

  • Processes the outgoing LLM request for this tool.

    Use cases:

    • Most common use case is adding this tool to the LLM request.
    • Some tools may just preprocess the LLM request before it's sent out.

    Parameters

    Returns Promise<void>