Skip to main content
一个 LangGraph StateGraph 从节点接收到了非对象返回类型。以下是一个示例:
import * as z from "zod";
import { StateGraph } from "@langchain/langgraph";

const State = z.object({
  someKey: z.string(),
});

const badNode = (state: z.infer<typeof State>) => {
  // Should return an object with a value for "someKey", not an array
  return ["whoops"];
};

const builder = new StateGraph(State).addNode("badNode", badNode);
// ...

const graph = builder.compile();
调用上述图将导致如下错误:
await graph.invoke({ someKey: "someval" });
InvalidUpdateError: Expected object, got ['whoops']
For troubleshooting, visit: https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/INVALID_GRAPH_NODE_RETURN_VALUE
您的图中的节点必须返回一个包含您状态中定义的一个或多个键的对象。

故障排除

以下可能有助于解决此错误:
  • 如果您的节点中包含复杂逻辑,请确保所有代码路径都返回您定义状态中适当的对象。