langchain.js
    Preparing search index...

    Interface ToolInterface<SchemaT, SchemaInputT, ToolOutputT>

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

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

    Type Parameters

    • SchemaT = 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 Summary)

    Implemented by

    Index

    Properties

    description: string

    A description of the tool.

    lc_namespace: string[]
    lc_serializable: boolean
    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.

    Accessors

    • get lc_id(): string[]

      Returns string[]

    Methods

    • Type Parameters

      Parameters

      • arg: TArg

        The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.

      • Optionalcallbacks: TConfig

        Optional callbacks for the tool.

      Returns Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>

      A Promise that resolves with a string.

      Use .invoke() instead. Will be removed in 0.3.0.

      Calls the tool with the provided argument and callbacks. It handles string inputs specifically.

    • Parameters

      • Optionalsuffix: string

      Returns string