Skip to main content

Documentation Index

Fetch the complete documentation index at: https://nvd-54.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

LangGraph StateGraph 从多个节点接收到对不支持并发更新的状态属性的并发更新。 发生这种情况的一种方式是,如果你在图中使用扇出或其他并行执行,并且定义了如下图:
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 的值,图将抛出此错误,因为如何更新内部状态存在不确定性。 要解决此问题,你可以定义一个组合多个值的归约器:
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),
    }
  ),
});
这将允许你定义处理从并行执行的多个节点返回的相同键的逻辑。

故障排除

以下可能有助于解决此错误:
  • 如果你的图并行执行节点,请确保你已为相关状态键定义了归约器。