跳到内容

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

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

故障排除

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

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