Interface StructuredToolInterface<SchemaT, SchemaInputT>

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, SchemaInputT> {
    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<any[]>;
    batch(inputs: StructuredToolCallInput<SchemaT, SchemaInputT>[], options?: Partial<RunnableConfig<Record<string, any>>> | Partial<RunnableConfig<Record<string, any>>>[], batchOptions?: RunnableBatchOptions & {
        returnExceptions: true;
    }): Promise<any[]>;
    batch(inputs: StructuredToolCallInput<SchemaT, SchemaInputT>[], options?: Partial<RunnableConfig<Record<string, any>>> | Partial<RunnableConfig<Record<string, any>>>[], batchOptions?: RunnableBatchOptions): Promise<any[]>;
    call(arg: StructuredToolCallInput<SchemaT, SchemaInputT>, configArg?: Callbacks | RunnableConfig<Record<string, any>>, tags?: string[]): Promise<any>;
    getName(suffix?: string): string;
    invoke(input: StructuredToolCallInput<SchemaT, SchemaInputT>, options?: Partial<RunnableConfig<Record<string, any>>>): Promise<any>;
    stream(input: StructuredToolCallInput<SchemaT, SchemaInputT>, options?: Partial<RunnableConfig<Record<string, any>>>): Promise<IterableReadableStreamInterface<any>>;
    transform(generator: AsyncGenerator<StructuredToolCallInput<SchemaT, SchemaInputT>, any, unknown>, options: Partial<RunnableConfig<Record<string, any>>>): AsyncGenerator<any, any, unknown>;
}

Type Parameters

  • SchemaT extends ToolSchemaBase = ZodObjectAny | z.ZodEffects<ZodObjectAny> | JSONSchema

    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.

Hierarchy (view full)

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

  • Parameters

    Returns Promise<any>

    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.

""