mirror of
https://github.com/langchain-ai/langgraphjs.git
synced 2026-07-22 00:55:26 -04:00
fix(langgraph): set status for tool messages generated by ToolNode (#1519)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@langchain/langgraph": patch
|
||||
---
|
||||
|
||||
fix(langgraph): set status for tool messages generated by ToolNode
|
||||
@@ -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 ?? "",
|
||||
|
||||
@@ -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.',
|
||||
},
|
||||
]);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user