Documentation Index
Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
Use this file to discover all available pages before exploring further.
LangGraph 的 StateGraph 收到了来自多个节点对其状态的并发更新,而该状态属性不支持此类操作。
这种情况可能发生在以下场景:你在图中使用了扇出(fanout)或其他并行执行逻辑,并且定义了类似这样的图:
import { StateGraph, StateSchema, START } from "@langchain/langgraph";
import { z } from "zod/v4";
const State = new StateSchema({
someKey: z.string(),
});
const builder = new StateGraph(State)
.addNode("node", (state) => {
return { someKey: "some_string_value" };
})
.addNode("otherNode", (state) => {
return { someKey: "some_string_value" };
})
.addEdge(START, "node")
.addEdge(START, "otherNode");
const graph = builder.compile();
如果上述图中的某个节点返回 { someKey: "some_string_value" },这将用 "some_string_value" 覆盖 someKey 的状态值。
然而,如果在单个步骤中(例如在扇出操作中)有多个节点返回了 someKey 的值,图将抛出此错误,因为无法确定如何更新内部状态。
要解决此问题,你可以定义一个合并多个值的归约器(reducer):
import { StateSchema, ReducedValue } from "@langchain/langgraph";
import { z } from "zod/v4";
const State = new StateSchema({
someKey: new ReducedValue(
z.array(z.string()).default(() => []),
{
inputSchema: z.array(z.string()),
reducer: (existing, update) => existing.concat(update),
}
),
});
这将允许你定义逻辑,以处理从并行执行的多个节点返回的相同键。
故障排除
以下方法可能有助于解决此错误:
- 如果你的图并行执行节点,请确保已为相关的状态键定义了归约器。