diff --git a/libs/langgraph/langgraph/pregel/read.py b/libs/langgraph/langgraph/pregel/read.py index 6fb2f72cb..7eb2a530c 100644 --- a/libs/langgraph/langgraph/pregel/read.py +++ b/libs/langgraph/langgraph/pregel/read.py @@ -192,6 +192,10 @@ class PregelNode(Runnable): def copy(self, update: dict[str, Any]) -> PregelNode: attrs = {**self.__dict__, **update} + # Drop the cached properties + attrs.pop("flat_writers", None) + attrs.pop("node", None) + attrs.pop("input_cache_key", None) return PregelNode(**attrs) @cached_property diff --git a/libs/langgraph/pyproject.toml b/libs/langgraph/pyproject.toml index 6ac7a0957..42000a586 100644 --- a/libs/langgraph/pyproject.toml +++ b/libs/langgraph/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langgraph" -version = "0.3.33" +version = "0.3.34" description = "Building stateful, multi-actor applications with LLMs" authors = [] license = "MIT" diff --git a/libs/langgraph/tests/test_pregel.py b/libs/langgraph/tests/test_pregel.py index 480d9dd33..941985ae4 100644 --- a/libs/langgraph/tests/test_pregel.py +++ b/libs/langgraph/tests/test_pregel.py @@ -7878,6 +7878,30 @@ def test_bulk_state_updates( ) +def test_pregel_node_copy() -> None: + class State(TypedDict): + foo: str + + def agent(state: State) -> State: + return {"foo": "agent"} + + def tool(state: State) -> State: + return {"foo": "tool"} + + graph = ( + StateGraph(State) + .add_node("agent", agent) + .add_node("tool", tool) + .add_edge(START, "agent") + .add_edge("agent", "tool") + .compile() + ) + + graph.invoke({"foo": "input"}, {"configurable": {"thread_id": "1"}}) + graph.copy() + graph.nodes["agent"].copy({}) + + @pytest.mark.parametrize("checkpointer_name", REGULAR_CHECKPOINTERS_SYNC) def test_update_as_input( request: pytest.FixtureRequest, checkpointer_name: str