From a885b1ca532bb66c92acc063ae7ac797f4c66576 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Mon, 13 May 2024 17:28:06 -0700 Subject: [PATCH] Small fixes while migrating JS --- langgraph/channels/base.py | 4 +++- langgraph/graph/graph.py | 7 ++++--- langgraph/graph/state.py | 2 +- langgraph/pregel/__init__.py | 6 ------ 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/langgraph/channels/base.py b/langgraph/channels/base.py index 7dd63e9bb..ae6869b41 100644 --- a/langgraph/channels/base.py +++ b/langgraph/channels/base.py @@ -114,7 +114,9 @@ def create_checkpoint( ) -> Checkpoint: """Create a checkpoint for the given channels.""" ts = datetime.now(timezone.utc).isoformat() - assert ts > checkpoint["ts"], "Timestamps must be monotonically increasing" + assert ( + ts > checkpoint["ts"] + ), f"Timestamps must be monotonically increasing, got {ts} <= {checkpoint['ts']}" values: dict[str, Any] = {} for k, v in channels.items(): try: diff --git a/langgraph/graph/graph.py b/langgraph/graph/graph.py index 818bc4de4..44f3a29f3 100644 --- a/langgraph/graph/graph.py +++ b/langgraph/graph/graph.py @@ -242,12 +242,13 @@ class Graph: # assemble sources all_sources = {src for src, _ in self._all_edges} for start, branches in self.branches.items(): + all_sources.add(start) for cond, branch in branches.items(): - all_sources.add(start) if branch.then is not None: if branch.ends is not None: for end in branch.ends.values(): - all_sources.add(end) + if end != END: + all_sources.add(end) else: for node in self.nodes: if node != start and node != branch.then: @@ -257,7 +258,7 @@ class Graph: if node not in all_sources: raise ValueError(f"Node '{node}' is a dead-end") for source in all_sources: - if node not in self.nodes and node != START: + if node not in self.nodes and source != START: raise ValueError(f"Found edge starting at unknown node '{source}'") # assemble targets diff --git a/langgraph/graph/state.py b/langgraph/graph/state.py index 9d121159d..1b2a4622f 100644 --- a/langgraph/graph/state.py +++ b/langgraph/graph/state.py @@ -269,7 +269,7 @@ class CompiledStateGraph(CompiledGraph): elif end != END: # subscribe to start channel self.nodes[end].triggers.append(starts) - else: + elif end != END: channel_name = f"join:{'+'.join(starts)}:{end}" # register channel self.channels[channel_name] = NamedBarrierValue(str, set(starts)) diff --git a/langgraph/pregel/__init__.py b/langgraph/pregel/__init__.py index 597f617d5..9549c2bad 100644 --- a/langgraph/pregel/__init__.py +++ b/langgraph/pregel/__init__.py @@ -108,12 +108,6 @@ WriteValue = Union[ ] -def _coerce_write_value(value: WriteValue) -> Runnable[Input, Output]: - if not isinstance(value, Runnable) and not callable(value): - return coerce_to_runnable(lambda _: value) - return coerce_to_runnable(value) - - class Channel: @overload @classmethod