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();
调用上面的图会产生如下错误
InvalidUpdateError: Expected node "badNode" to return an object, received number
Troubleshooting URL: https://js.langchain.ac.cn/troubleshooting/errors/INVALID_GRAPH_NODE_RETURN_VALUE
图中的节点必须返回一个包含您在状态中定义的一个或多个键的对象。
故障排除¶
以下方法可能有助于解决此错误
- 如果您的节点中包含复杂的逻辑,请确保所有代码路径都为定义的状态返回适当的对象。