diff --git a/langchain-core/src/tools.ts b/langchain-core/src/tools.ts index eeedab18ecd8..84b5311eac39 100644 --- a/langchain-core/src/tools.ts +++ b/langchain-core/src/tools.ts @@ -150,7 +150,7 @@ export abstract class Tool extends StructuredTool { */ call( arg: string | undefined | z.input, - callbacks?: Callbacks + callbacks?: Callbacks | RunnableConfig ): Promise { return super.call( typeof arg === "string" || !arg ? { input: arg } : arg, diff --git a/libs/langchain-community/src/tools/dynamic.ts b/libs/langchain-community/src/tools/dynamic.ts index eac8b7593534..007540a2e084 100644 --- a/libs/langchain-community/src/tools/dynamic.ts +++ b/libs/langchain-community/src/tools/dynamic.ts @@ -1,6 +1,11 @@ import { z } from "zod"; -import { CallbackManagerForToolRun } from "@langchain/core/callbacks/manager"; +import { + CallbackManagerForToolRun, + Callbacks, + parseCallbackConfigArg, +} from "@langchain/core/callbacks/manager"; import { StructuredTool, Tool, type ToolParams } from "@langchain/core/tools"; +import { RunnableConfig } from "@langchain/core/runnables"; export interface BaseDynamicToolInput extends ToolParams { name: string; @@ -54,6 +59,17 @@ export class DynamicTool extends Tool { this.returnDirect = fields.returnDirect ?? this.returnDirect; } + async call( + arg: string | undefined | z.input, + configArg?: RunnableConfig | Callbacks + ): Promise { + const config = parseCallbackConfigArg(configArg); + if (config.runName === undefined) { + config.runName = this.name; + } + return super.call(arg, config); + } + /** @ignore */ async _call( input: string, @@ -94,6 +110,19 @@ export class DynamicStructuredTool< this.schema = fields.schema; } + async call( + arg: z.output, + configArg?: RunnableConfig | Callbacks, + /** @deprecated */ + tags?: string[] + ): Promise { + const config = parseCallbackConfigArg(configArg); + if (config.runName === undefined) { + config.runName = this.name; + } + return super.call(arg, config, tags); + } + protected _call( arg: z.output, runManager?: CallbackManagerForToolRun