From 0bc81301ba6e41a3fd8bbc2ce770634be1d2bafe Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Sat, 25 Jan 2025 00:59:28 -0800 Subject: [PATCH] feat(core): Allow passing returnDirect in tool wrapper params (#7594) --- langchain-core/src/tools/index.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/langchain-core/src/tools/index.ts b/langchain-core/src/tools/index.ts index 121833938663..13a738ac0ba5 100644 --- a/langchain-core/src/tools/index.ts +++ b/langchain-core/src/tools/index.ts @@ -115,6 +115,12 @@ export interface StructuredToolInterface */ description: string; + /** + * 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; } @@ -133,9 +139,14 @@ export abstract class StructuredTool< abstract schema: T | z.ZodEffects; + /** + * 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 = false; - // TODO: Make default in 0.3 verboseParsingErrors = false; get lc_namespace() { @@ -347,6 +358,12 @@ export abstract class Tool extends StructuredTool { export interface BaseDynamicToolInput extends ToolParams { name: string; description: string; + /** + * 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; } @@ -540,6 +557,13 @@ interface ToolWrapperParams< * @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; } /**