Interface ToolInterface<SchemaT, SchemaInputT, ToolOutputT>

A special interface for tools that accept a string input, usually defined with the Tool class.

interface ToolInterface<SchemaT, SchemaInputT, ToolOutputT> {
    description: string;
    name: string;
    returnDirect: boolean;
    schema: SchemaT;
    batch(inputs: StructuredToolCallInput<SchemaT, SchemaInputT>[], options?: Partial<RunnableConfig<Record<string, any>>> | Partial<RunnableConfig<Record<string, any>>>[], batchOptions?: RunnableBatchOptions & {
        returnExceptions?: false;
    }): Promise<(ToolMessage | ToolOutputT)[]>;
    batch(inputs: StructuredToolCallInput<SchemaT, SchemaInputT>[], options?: Partial<RunnableConfig<Record<string, any>>> | Partial<RunnableConfig<Record<string, any>>>[], batchOptions?: RunnableBatchOptions & {
        returnExceptions: true;
    }): Promise<(Error | ToolMessage | ToolOutputT)[]>;
    batch(inputs: StructuredToolCallInput<SchemaT, SchemaInputT>[], options?: Partial<RunnableConfig<Record<string, any>>> | Partial<RunnableConfig<Record<string, any>>>[], batchOptions?: RunnableBatchOptions): Promise<(Error | ToolMessage | ToolOutputT)[]>;
    call<TArg, TConfig>(arg: TArg, callbacks?: TConfig): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;
    getName(suffix?: string): string;
    invoke<TArg, TConfig>(arg: TArg, configArg?: TConfig): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;
    stream(input: StructuredToolCallInput<SchemaT, SchemaInputT>, options?: Partial<RunnableConfig<Record<string, any>>>): Promise<IterableReadableStreamInterface<ToolMessage | ToolOutputT>>;
    transform(generator: AsyncGenerator<StructuredToolCallInput<SchemaT, SchemaInputT>, any, unknown>, options: Partial<RunnableConfig<Record<string, any>>>): AsyncGenerator<ToolMessage | ToolOutputT, any, unknown>;
}

Type Parameters

  • SchemaT extends StringInputToolSchema = StringInputToolSchema

    The type of the tool input schema. Usually you don't need to specify this.

  • SchemaInputT = ToolInputSchemaInputType<SchemaT>

    The TypeScript type representing the structure of the tool arguments generated by the LLM. Useful for type checking tool handler functions when using JSONSchema.

  • ToolOutputT = ToolOutputType

Hierarchy (view full)

Implemented by

Properties

description: string

A description of the tool.

name: string

The name of the tool.

returnDirect: boolean

Whether to return the tool's output directly.

Setting this to true means that after the tool is called, an agent should stop looping.

schema: SchemaT

A Zod schema representing the parameters of the tool.

Methods