跳到内容

INVALID_GRAPH_NODE_RETURN_VALUE

LangGraph 的 StateGraph 从一个节点接收到非对象返回类型。这是一个例子

const StateAnnotation = Annotation.Root({
  someKey: Annotation<string>,
});

const graph = new StateGraph(StateAnnotation)
  .addNode("badNode", async (state) => {
    // Should return an empty object, one with a value for "someKey", or undefined
    return ["whoops!"];
  })
  ...
  .compile();

调用上面的图将会导致如下错误

await graph.invoke({ someKey: "someval" });
InvalidUpdateError: Expected node "badNode" to return an object, received number

Troubleshooting URL: https://js.langchain.ac.cn/troubleshooting/errors/INVALID_GRAPH_NODE_RETURN_VALUE

图中的节点必须返回一个包含在你的状态中定义的一个或多个键的对象。

故障排除

以下方法可能有助于解决此错误

  • 如果你的节点中有复杂的逻辑,请确保所有代码路径都为定义的状态返回适当的对象。