> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# INVALID_CONCURRENT_GRAPH_UPDATE

> LangGraph @[StateGraph] 接收到多个节点对同一不支持并发更新的状态属性的并行更新。

LangGraph @\[`StateGraph`] 接收到多个节点对同一不支持并发更新的状态属性的并行更新。

一种可能情况是你在图中使用了[fanout](https://langchain-docs-zh.mintlify.site/langchain/oss/langgraph/use-graph-api.md#map-reduce-和-send-api)或其他并行执行方式，并定义了如下结构：

:::python

```python theme={null}
from typing import TypedDict

from langgraph.graph import START, StateGraph

class State(TypedDict):
    some_key: str  # [!code highlight]

def node(state: State):
    return {"some_key": "some_string_value"}

def other_node(state: State):
    return {"some_key": "some_string_value"}


builder = StateGraph(State)
builder.add_node(node)
builder.add_node(other_node)
builder.add_edge(START, "node")
builder.add_edge(START, "other_node")
graph = builder.compile()
```

:::

:::js

```typescript theme={null}
import { StateGraph, StateSchema, START } from "@langchain/langgraph";
import { z } from "zod/v4";  // [!code highlight]

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();
```

:::

:::python
若上述图中的某个节点返回 `{ "some_key": "some_string_value" }`，这将用 `"some_string_value"` 覆盖 `"some_key"` 的状态值。
然而，如果在同一步骤的例如 fanout 中有多个节点返回 `"some_key"` 的值，图将抛出此错误，因为无法确定如何更新内部状态。
:::

:::js
若上述图中的某个节点返回 `{ someKey: "some_string_value" }`，这将用 `"some_string_value"` 覆盖 `someKey` 的状态值。
然而，如果在同一步骤的例如 fanout 中有多个节点返回 `someKey` 的值，图将抛出此错误，因为无法确定如何更新内部状态。
:::

为解决此问题，可以定义一个聚合多个值的 reducer：

:::python

```python theme={null}
import operator
from typing import Annotated

class State(TypedDict):
    # The operator.add reducer fn makes this append-only  # [!code highlight]
    some_key: Annotated[list, operator.add]  # [!code highlight]
```

:::

:::js

```typescript theme={null}
import { StateSchema, ReducedValue } from "@langchain/langgraph";
import { z } from "zod/v4";

const State = new StateSchema({  // [!code highlight]
  someKey: new ReducedValue(  // [!code highlight]
    z.array(z.string()).default(() => []),  // [!code highlight]
    {
      inputSchema: z.array(z.string()),
      reducer: (existing, update) => existing.concat(update),  // [!code highlight]
    }
  ),
});
```

:::

这将允许你定义处理来自并行执行的多节点返回相同键值的逻辑。

## 故障排除

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

* 若图执行节点并行，请确保已为相关状态键定义了 reducer

***

> 官方原文：[src/oss/langgraph/errors/INVALID\_CONCURRENT\_GRAPH\_UPDATE.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/langgraph/errors/INVALID_CONCURRENT_GRAPH_UPDATE.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.