From a24aaf99461c2420030a46ea5cd9cec868c25f3f Mon Sep 17 00:00:00 2001 From: Jared Hanson Date: Fri, 6 Dec 2024 11:57:14 -0800 Subject: [PATCH 1/2] Re-throw NodeInterrupt errors from ToolNode for HITL. --- libs/langgraph/src/prebuilt/tool_node.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/langgraph/src/prebuilt/tool_node.ts b/libs/langgraph/src/prebuilt/tool_node.ts index 5c8e21707..81577d1f5 100644 --- a/libs/langgraph/src/prebuilt/tool_node.ts +++ b/libs/langgraph/src/prebuilt/tool_node.ts @@ -9,6 +9,7 @@ import { StructuredToolInterface } from "@langchain/core/tools"; import { RunnableCallable } from "../utils.js"; import { END } from "../graph/graph.js"; import { MessagesAnnotation } from "../graph/messages_annotation.js"; +import { NodeInterrupt } from "../errors.js"; export type ToolNodeOptions = { name?: string; @@ -187,6 +188,12 @@ export class ToolNode extends RunnableCallable { if (!this.handleToolErrors) { throw e; } + if (e.name === NodeInterrupt.unminifiable_name) { + // `NodeInterrupt` errors are a breakpoint to bring a human into the loop. + // As such, they are not recoverable by the agent and shouldn't be fed + // back. Instead, re-throw these errors even when `handleToolErrors = true`. + throw e; + } return new ToolMessage({ content: `Error: ${e.message}\n Please fix your mistakes.`, name: call.name, From fec0af2bca4b3ae0f97489c060748bed25361e68 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Sun, 8 Dec 2024 18:30:37 -0800 Subject: [PATCH 2/2] Update tool_node.ts --- libs/langgraph/src/prebuilt/tool_node.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/langgraph/src/prebuilt/tool_node.ts b/libs/langgraph/src/prebuilt/tool_node.ts index 81577d1f5..9e0bffdd8 100644 --- a/libs/langgraph/src/prebuilt/tool_node.ts +++ b/libs/langgraph/src/prebuilt/tool_node.ts @@ -9,7 +9,7 @@ import { StructuredToolInterface } from "@langchain/core/tools"; import { RunnableCallable } from "../utils.js"; import { END } from "../graph/graph.js"; import { MessagesAnnotation } from "../graph/messages_annotation.js"; -import { NodeInterrupt } from "../errors.js"; +import { isGraphInterrupt } from "../errors.js"; export type ToolNodeOptions = { name?: string; @@ -188,10 +188,10 @@ export class ToolNode extends RunnableCallable { if (!this.handleToolErrors) { throw e; } - if (e.name === NodeInterrupt.unminifiable_name) { + if (isGraphInterrupt(e.name)) { // `NodeInterrupt` errors are a breakpoint to bring a human into the loop. // As such, they are not recoverable by the agent and shouldn't be fed - // back. Instead, re-throw these errors even when `handleToolErrors = true`. + // back. Instead, re-throw these errors even when `handleToolErrors = true`. throw e; } return new ToolMessage({