fix(langgraph): set status for tool messages generated by ToolNode (#1519)

This commit is contained in:
David Duong
2025-08-11 12:42:25 +02:00
committed by GitHub
parent b23adc0a7c
commit 4e854b2f37
3 changed files with 27 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@langchain/langgraph": patch
---
fix(langgraph): set status for tool messages generated by ToolNode
+2
View File
@@ -186,6 +186,7 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
}
return new ToolMessage({
status: "success",
name: tool.name,
content: typeof output === "string" ? output : JSON.stringify(output),
tool_call_id: call.id!,
@@ -202,6 +203,7 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
}
return new ToolMessage({
status: "error",
content: `Error: ${e.message}\n Please fix your mistakes.`,
name: call.name,
tool_call_id: call.id ?? "",
+20
View File
@@ -525,6 +525,7 @@ describe.each([["v1" as const], ["v2" as const]])(
}),
new _AnyIdToolMessage({
name: "search_api",
status: "success",
content: "result for foo",
tool_call_id: "tool_abcd123",
}),
@@ -1040,6 +1041,7 @@ describe.each([["v1" as const], ["v2" as const]])(
],
}),
new _AnyIdToolMessage({
status: "success",
name: "search_api",
content: "result for foo",
tool_call_id: "tool_abcd123",
@@ -2589,6 +2591,24 @@ describe.each([["v1" as const], ["v2" as const]])(
],
});
});
it("should handle tool errors", async () => {
const toolNode = new ToolNode([new SearchAPI()]);
const res = await toolNode.invoke([
new AIMessage({
content: "",
tool_calls: [{ name: "badtool", args: {}, id: "testid" }],
}),
]);
expect(res).toMatchObject([
{
status: "error",
content:
'Error: Tool "badtool" not found.\n Please fix your mistakes.',
},
]);
});
}
);