From 499fe10ef2e0df2ec34c37d19584f02d64db1ff5 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Tue, 27 Aug 2024 13:34:50 -0700 Subject: [PATCH] Undo addition of Send.id --- .../checkpoint/langgraph/checkpoint/serde/jsonplus.py | 2 +- libs/checkpoint/langgraph/checkpoint/serde/types.py | 1 - libs/langgraph/langgraph/constants.py | 11 ++++------- libs/langgraph/langgraph/pregel/algo.py | 6 +++--- libs/langgraph/langgraph/pregel/loop.py | 1 - 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py b/libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py index e80b9a678..e39a66e76 100644 --- a/libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py +++ b/libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py @@ -109,7 +109,7 @@ class JsonPlusSerializer(SerializerProtocol): return self._encode_constructor_args(obj.__class__, args=[obj.value]) elif isinstance(obj, SendProtocol): return self._encode_constructor_args( - obj.__class__, kwargs={"node": obj.node, "arg": obj.arg, "id": obj.id} + obj.__class__, kwargs={"node": obj.node, "arg": obj.arg} ) elif isinstance(obj, (bytes, bytearray)): return self._encode_constructor_args( diff --git a/libs/checkpoint/langgraph/checkpoint/serde/types.py b/libs/checkpoint/langgraph/checkpoint/serde/types.py index fb0055b51..67f59ae89 100644 --- a/libs/checkpoint/langgraph/checkpoint/serde/types.py +++ b/libs/checkpoint/langgraph/checkpoint/serde/types.py @@ -50,7 +50,6 @@ class SendProtocol(Protocol): # Mirrors langgraph.constants.Send node: str arg: Any - id: str def __hash__(self) -> int: ... diff --git a/libs/langgraph/langgraph/constants.py b/libs/langgraph/langgraph/constants.py index 3b322d391..085316333 100644 --- a/libs/langgraph/langgraph/constants.py +++ b/libs/langgraph/langgraph/constants.py @@ -1,6 +1,5 @@ from dataclasses import dataclass -from typing import Any, Literal, Optional -from uuid import uuid4 +from typing import Any, Literal INPUT = "__input__" CONFIG_KEY_SEND = "__pregel_send" @@ -79,9 +78,8 @@ class Send: node: str arg: Any - id: Optional[str] - def __init__(self, /, node: str, arg: Any, id: Optional[str] = None) -> None: + def __init__(self, /, node: str, arg: Any) -> None: """ Initialize a new instance of the Send class. @@ -92,13 +90,12 @@ class Send: """ self.node = node self.arg = arg - self.id = id or str(uuid4()) def __hash__(self) -> int: - return hash((self.node, self.arg, self.id)) + return hash((self.node, self.arg)) def __repr__(self) -> str: - return f"Send(node={self.node!r}, arg={self.arg!r}, id={self.id!r})" + return f"Send(node={self.node!r}, arg={self.arg!r})" def __eq__(self, value: object) -> bool: return ( diff --git a/libs/langgraph/langgraph/pregel/algo.py b/libs/langgraph/langgraph/pregel/algo.py index 39ca717b6..2f1589573 100644 --- a/libs/langgraph/langgraph/pregel/algo.py +++ b/libs/langgraph/langgraph/pregel/algo.py @@ -291,9 +291,9 @@ def prepare_next_tasks( "langgraph_task_idx": len(tasks), } checkpoint_ns = ( - f"{parent_ns}{CHECKPOINT_NAMESPACE_SEPARATOR}{packet.node}:{packet.id}" + f"{parent_ns}{CHECKPOINT_NAMESPACE_SEPARATOR}{packet.node}" if parent_ns - else f"{packet.node}:{packet.id}" + else packet.node ) task_id = str( uuid5(UUID(checkpoint["id"]), json.dumps((checkpoint_ns, metadata))) @@ -344,7 +344,7 @@ def prepare_next_tasks( CONFIG_KEY_CHECKPOINTER: checkpointer, CONFIG_KEY_RESUMING: is_resuming, "checkpoint_id": checkpoint["id"], - "checkpoint_ns": checkpoint_ns, + "checkpoint_ns": f"{checkpoint_ns}:{task_id}", }, ), triggers, diff --git a/libs/langgraph/langgraph/pregel/loop.py b/libs/langgraph/langgraph/pregel/loop.py index b4e6d4118..509f6eabc 100644 --- a/libs/langgraph/langgraph/pregel/loop.py +++ b/libs/langgraph/langgraph/pregel/loop.py @@ -118,7 +118,6 @@ class PregelLoop: checkpoint_config: RunnableConfig checkpoint_metadata: CheckpointMetadata checkpoint_pending_writes: List[PendingWrite] - # (thread_id, checkpoint_ns -> channel_versions) checkpoint_previous_versions: dict[str, Union[str, float, int]] step: int