• Create a function tool. Parameters are inferred from the schema; omit parameters for a tool that takes no arguments.

    Type Parameters

    • UserData = unknown
    • Schema extends undefined | ToolInputSchema<any> = undefined
    • Result = unknown

    Parameters

    • __namedParameters: {
          description: string;
          execute: ToolExecuteFunction<ToolArgs<Schema>, UserData, Result>;
          flags?: number;
          name: string;
          onDuplicate?: DuplicateMode;
          parameters?: Schema;
      }
      • description: string

        Natural-language description that tells the model when to use this tool.

      • execute: ToolExecuteFunction<ToolArgs<Schema>, UserData, Result>

        Called when the model invokes the tool. Receives the parsed arguments (an empty object when parameters is omitted) and a RunContext (ctx); the returned value is sent back to the model.

      • Optional flags?: number

        Bitmask of ToolFlags, e.g. ToolFlag.CANCELLABLE to allow the call to be cancelled mid-flight. Defaults to ToolFlag.NONE.

      • name: string

        Unique name the model calls the tool by. Must be non-empty.

      • Optional onDuplicate?: DuplicateMode

        How a concurrent duplicate call of this tool is handled while one is still running: 'allow' | 'reject' | 'replace' | 'confirm'. Defaults to 'allow'.

      • Optional parameters?: Schema

        Input schema for the tool's arguments — either a Zod object schema (args are type-inferred) or a raw JSON Schema. Omit for a tool that takes no arguments.

    Returns FunctionTool<ToolArgs<Schema>, UserData, Result>

  • Create an anonymous (name-less) function tool. Parameters are inferred from the schema; omit parameters for a tool that takes no arguments.

    Type Parameters

    • UserData = unknown
    • Schema extends undefined | ToolInputSchema<any> = undefined
    • Result = unknown

    Parameters

    • __namedParameters: {
          description: string;
          execute: ToolExecuteFunction<ToolArgs<Schema>, UserData, Result>;
          flags?: number;
          name?: undefined;
          onDuplicate?: DuplicateMode;
          parameters?: Schema;
      }
      • description: string

        Natural-language description that tells the model when to use this tool.

      • execute: ToolExecuteFunction<ToolArgs<Schema>, UserData, Result>

        Called when the model invokes the tool. Receives the parsed arguments (an empty object when parameters is omitted) and a RunContext (ctx); the returned value is sent back to the model.

      • Optional flags?: number

        Bitmask of ToolFlags, e.g. ToolFlag.CANCELLABLE to allow the call to be cancelled mid-flight. Defaults to ToolFlag.NONE.

      • Optional name?: undefined

        Omitted in object syntax; the containing object key becomes the tool name.

      • Optional onDuplicate?: DuplicateMode

        How a concurrent duplicate call of this tool is handled while one is still running: 'allow' | 'reject' | 'replace' | 'confirm'. Defaults to 'allow'.

      • Optional parameters?: Schema

        Input schema for the tool's arguments — either a Zod object schema (args are type-inferred) or a raw JSON Schema. Omit for a tool that takes no arguments.

    Returns AnonFunctionTool<ToolArgs<Schema>, UserData, Result>