The base class for all tools

Hierarchy (view full)

Constructors

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

  • Gets the OpenAPI specification of this tool in the form of a FunctionDeclaration

    NOTE:

    • Required if subclass uses the default implementation of processLlmRequest to add function declaration to LLM request.
    • Otherwise, can return null, e.g. for a built-in GoogleSearch tool.

    Returns FunctionDeclaration

    The FunctionDeclaration of this tool, or null if it doesn't need to be added to LlmRequest.config.

  • Validates the arguments against the schema in the function declaration

    Parameters

    • args: Record<string, any>

      Arguments to validate

    Returns boolean

    True if arguments are valid

  • Runs the tool with the given arguments and context

    NOTE:

    • Required if this tool needs to run at the client side.
    • Otherwise, can be skipped, e.g. for a built-in GoogleSearch tool.

    Parameters

    Returns Promise<any>

    The result of running the tool

  • 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>

  • Executes the tool with error handling and retries

    Parameters

    • args: Record<string, any>

      Arguments for the tool

    • context: ToolContext

      Tool execution context

    Returns Promise<any>

    Result of the tool execution or error information