From d5dc5239c1ca6e67770162088f46b6107d7f0a85 Mon Sep 17 00:00:00 2001 From: Bagatur Date: Tue, 23 Jan 2024 12:04:36 -0800 Subject: [PATCH] patch: Clarify node<>channel name collision error --- langgraph/graph/state.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/langgraph/graph/state.py b/langgraph/graph/state.py index fc99ed3fe..20fccde54 100644 --- a/langgraph/graph/state.py +++ b/langgraph/graph/state.py @@ -4,6 +4,7 @@ from inspect import signature from typing import Any, Optional, Type from langchain_core.runnables import RunnableConfig, RunnableLambda, RunnablePassthrough +from langchain_core.runnables.base import RunnableLike from langgraph.channels.base import BaseChannel, InvalidUpdateError from langgraph.channels.binop import BinaryOperatorAggregate @@ -25,12 +26,17 @@ class StateGraph(Graph): if any(isinstance(c, BinaryOperatorAggregate) for c in self.channels.values()): self.support_multiple_edges = True + def add_node(self, key: str, action: RunnableLike) -> None: + if key in self.channels: + raise ValueError( + f"'{key}' is already being used as a state attribute " + "(a.k.a. a channel), cannot also be used as a node name." + ) + return super().add_node(key, action) + def compile(self, checkpointer: Optional[BaseCheckpointSaver] = None) -> Pregel: self.validate() - if any(key in self.nodes for key in self.channels): - raise ValueError("Cannot use channel names as node names") - state_keys = list(self.channels) state_keys_read = state_keys[0] if state_keys == ["__root__"] else state_keys update_state = (