Copy with cached property (#4399)

This commit is contained in:
William FH
2025-04-24 07:16:37 -07:00
committed by GitHub
parent 17bc55028e
commit 6263c2f710
3 changed files with 29 additions and 1 deletions
+4
View File
@@ -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
+1 -1
View File
@@ -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"
+24
View File
@@ -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