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
图中的节点必须返回一个对象,该对象包含您的状态中定义的一个或多个键。
故障排除¶
以下建议可能有助于解决此错误:
- 如果您的节点中有复杂的逻辑,请确保所有代码路径都为您的已定义状态返回适当的对象。