import { z } from "zod"; import { CallbackManagerForToolRun } from "../callbacks/manager.js"; import { BaseLangChain } from "../language_models/base.js"; import { type RunnableConfig } from "../runnables/config.js"; import type { RunnableFunc } from "../runnables/base.js"; import { ToolCall, ToolMessage } from "../messages/tool.js"; import { ToolInputParsingException } from "./utils.js"; import type { StructuredToolCallInput, ToolInputSchemaBase, ToolReturnType, ResponseFormat, ToolInputSchemaInputType, ToolInputSchemaOutputType, ToolParams, ToolRunnableConfig, StructuredToolInterface, DynamicToolInput, DynamicStructuredToolInput, ZodObjectAny, StringInputToolSchema, ToolInterface, ToolOutputType } from "./types.js"; import { type JSONSchema } from "../utils/json_schema.js"; export type { BaseDynamicToolInput, ContentAndArtifact, DynamicToolInput, DynamicStructuredToolInput, ResponseFormat, StructuredToolCallInput, StructuredToolInterface, StructuredToolParams, ToolInterface, ToolParams, ToolReturnType, ToolRunnableConfig, ToolInputSchemaBase as ToolSchemaBase, } from "./types.js"; export { isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams, } from "./types.js"; export { ToolInputParsingException }; /** * Base class for Tools that accept input of any shape defined by a Zod schema. */ export declare abstract class StructuredTool, SchemaInputT = ToolInputSchemaInputType, ToolOutputT = ToolOutputType> extends BaseLangChain, ToolOutputT | ToolMessage> implements StructuredToolInterface { abstract name: string; abstract description: string; abstract schema: SchemaT; /** * Whether to return the tool's output directly. * * Setting this to true means that after the tool is called, * an agent should stop looping. */ returnDirect: boolean; verboseParsingErrors: boolean; get lc_namespace(): string[]; /** * The tool response format. * * If "content" then the output of the tool is interpreted as the contents of a * ToolMessage. If "content_and_artifact" then the output is expected to be a * two-tuple corresponding to the (content, artifact) of a ToolMessage. * * @default "content" */ responseFormat?: ResponseFormat; constructor(fields?: ToolParams); protected abstract _call(arg: SchemaOutputT, runManager?: CallbackManagerForToolRun, parentConfig?: ToolRunnableConfig): Promise; /** * Invokes the tool with the provided input and configuration. * @param input The input for the tool. * @param config Optional configuration for the tool. * @returns A Promise that resolves with the tool's output. */ invoke, TConfig extends ToolRunnableConfig | undefined>(input: TInput, config?: TConfig): Promise>; /** * @deprecated 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. * @param arg The input argument for the tool. * @param configArg Optional configuration or callbacks for the tool. * @param tags Optional tags for the tool. * @returns A Promise that resolves with a string. */ call, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig, /** @deprecated */ tags?: string[]): Promise>; } /** * Base class for Tools that accept input as a string. */ export declare abstract class Tool extends StructuredTool, ToolInputSchemaInputType, ToolOutputT> implements ToolInterface, ToolOutputT> { schema: z.ZodEffects; }, "strip", z.ZodTypeAny, { input?: string | undefined; }, { input?: string | undefined; }>, string | undefined, { input?: string | undefined; }>; constructor(fields?: ToolParams); /** * @deprecated Use .invoke() instead. Will be removed in 0.3.0. * * Calls the tool with the provided argument and callbacks. It handles * string inputs specifically. * @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema. * @param callbacks Optional callbacks for the tool. * @returns A Promise that resolves with a string. */ call | ToolCall, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, callbacks?: TConfig): Promise, TConfig, ToolOutputT>>; } /** * A tool that can be created dynamically from a function, name, and description. */ export declare class DynamicTool extends Tool { static lc_name(): string; name: string; description: string; func: DynamicToolInput["func"]; constructor(fields: DynamicToolInput); /** * @deprecated Use .invoke() instead. Will be removed in 0.3.0. */ call | ToolCall, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig): Promise, TConfig, ToolOutputT>>; /** @ignore */ _call(input: string, // DynamicTool's _call specifically expects a string after schema transformation runManager?: CallbackManagerForToolRun, parentConfig?: ToolRunnableConfig): Promise; } /** * A tool that can be created dynamically from a function, name, and * description, designed to work with structured data. It extends the * StructuredTool class and overrides the _call method to execute the * provided function when the tool is called. * * Schema can be passed as Zod or JSON schema. The tool will not validate * input if JSON schema is passed. */ export declare class DynamicStructuredTool, SchemaInputT = ToolInputSchemaInputType, ToolOutputT = ToolOutputType> extends StructuredTool { static lc_name(): string; name: string; description: string; func: DynamicStructuredToolInput["func"]; schema: SchemaT; constructor(fields: DynamicStructuredToolInput); /** * @deprecated Use .invoke() instead. Will be removed in 0.3.0. */ call, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig, /** @deprecated */ tags?: string[]): Promise, TConfig, ToolOutputT>>; protected _call(arg: Parameters["func"]>[0], runManager?: CallbackManagerForToolRun, parentConfig?: RunnableConfig): Promise; } /** * Abstract base class for toolkits in LangChain. Toolkits are collections * of tools that agents can use. Subclasses must implement the `tools` * property to provide the specific tools for the toolkit. */ export declare abstract class BaseToolkit { abstract tools: StructuredToolInterface[]; getTools(): StructuredToolInterface[]; } /** * Parameters for the tool function. * Schema can be provided as Zod or JSON schema. * Both schema types will be validated. * @template {ToolInputSchemaBase} RunInput The input schema for the tool. */ interface ToolWrapperParams extends ToolParams { /** * The name of the tool. If using with an LLM, this * will be passed as the tool name. */ name: string; /** * The description of the tool. * @default `${fields.name} tool` */ description?: string; /** * The input schema for the tool. If using an LLM, this * will be passed as the tool schema to generate arguments * for. */ schema?: RunInput; /** * The tool response format. * * If "content" then the output of the tool is interpreted as the contents of a * ToolMessage. If "content_and_artifact" then the output is expected to be a * two-tuple corresponding to the (content, artifact) of a ToolMessage. * * @default "content" */ responseFormat?: ResponseFormat; /** * Whether to return the tool's output directly. * * Setting this to true means that after the tool is called, * an agent should stop looping. */ returnDirect?: boolean; } /** * Creates a new StructuredTool instance with the provided function, name, description, and schema. * * Schema can be provided as Zod or JSON schema, and both will be validated. * * @function * @template {ToolInputSchemaBase} SchemaT The input schema for the tool. * @template {ToolReturnType} ToolOutputT The output type of the tool. * * @param {RunnableFunc, ToolOutputT>} func - The function to invoke when the tool is called. * @param {ToolWrapperParams} fields - An object containing the following properties: * @param {string} fields.name The name of the tool. * @param {string | undefined} fields.description The description of the tool. Defaults to either the description on the Zod schema, or `${fields.name} tool`. * @param {ZodObjectAny | z.ZodString | undefined} fields.schema The Zod schema defining the input for the tool. If undefined, it will default to a Zod string schema. * * @returns {DynamicStructuredTool} A new StructuredTool instance. */ export declare function tool(func: RunnableFunc : string, ToolOutputT, ToolRunnableConfig>, fields: ToolWrapperParams): DynamicTool; export declare function tool, SchemaInputT = z.input, ToolOutputT = ToolOutputType>(func: RunnableFunc, fields: ToolWrapperParams): DynamicStructuredTool; export declare function tool, SchemaInputT = ToolInputSchemaInputType, ToolOutputT = ToolOutputType>(func: RunnableFunc["func"]>[0], ToolOutputT, ToolRunnableConfig>, fields: ToolWrapperParams): DynamicStructuredTool;