langchain.js
    Preparing search index...

    Interface StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT>

    Interface that defines the shape of a LangChain structured tool.

    A structured tool is a tool that uses a schema to define the structure of the arguments that the LLM generates as part of its ToolCall.

    interface StructuredToolInterface<
        SchemaT = ToolSchemaBase,
        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,
            configArg?: TConfig,
            tags?: string[],
        ): Promise<ToolReturnType<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 = ToolSchemaBase

      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.

      • OptionalconfigArg: TConfig

        Optional configuration or callbacks for the tool.

      • Optionaltags: string[]

        Optional tags for the tool.

      Returns Promise<ToolReturnType<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, configuration, and tags. It parses the input according to the schema, handles any errors, and manages callbacks.

    • Parameters

      • Optionalsuffix: string

      Returns string