Skip to content

Commit ec6c8bc

Browse files
authored
Merge pull request #61 from langchain-ai/bagatur/node_channel_collision_error
patch: Clarify node<>channel name collision error
2 parents 10ee6f2 + d5dc523 commit ec6c8bc

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

langgraph/graph/state.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Any, Optional, Type
55

66
from langchain_core.runnables import RunnableConfig, RunnableLambda, RunnablePassthrough
7+
from langchain_core.runnables.base import RunnableLike
78

89
from langgraph.channels.base import BaseChannel, InvalidUpdateError
910
from langgraph.channels.binop import BinaryOperatorAggregate
@@ -25,12 +26,17 @@ def __init__(self, schema: Type[Any]) -> None:
2526
if any(isinstance(c, BinaryOperatorAggregate) for c in self.channels.values()):
2627
self.support_multiple_edges = True
2728

29+
def add_node(self, key: str, action: RunnableLike) -> None:
30+
if key in self.channels:
31+
raise ValueError(
32+
f"'{key}' is already being used as a state attribute "
33+
"(a.k.a. a channel), cannot also be used as a node name."
34+
)
35+
return super().add_node(key, action)
36+
2837
def compile(self, checkpointer: Optional[BaseCheckpointSaver] = None) -> Pregel:
2938
self.validate()
3039

31-
if any(key in self.nodes for key in self.channels):
32-
raise ValueError("Cannot use channel names as node names")
33-
3440
state_keys = list(self.channels)
3541
state_keys_read = state_keys[0] if state_keys == ["__root__"] else state_keys
3642
update_state = (

0 commit comments

Comments
 (0)