From e497d14db01ddde77f691755ebad8227453dc05c Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Sat, 13 Jan 2024 15:58:25 -0800 Subject: [PATCH] Fixes --- langgraph/graph/state.py | 3 ++- langgraph/pregel/__init__.py | 7 +++++-- langgraph/pregel/write.py | 12 +++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/langgraph/graph/state.py b/langgraph/graph/state.py index c3f58edb6..3b708478a 100644 --- a/langgraph/graph/state.py +++ b/langgraph/graph/state.py @@ -83,7 +83,8 @@ def _coerce_state(schema: Type[Any], input: dict[str, Any]) -> dict[str, Any]: def _update_state(input: dict[str, Any], config: RunnableConfig): - ChannelWrite.do_write(config, **input) + if input is not None: + ChannelWrite.do_write(config, **input) return input diff --git a/langgraph/pregel/__init__.py b/langgraph/pregel/__init__.py index 46baeb6d4..c37a0e74c 100644 --- a/langgraph/pregel/__init__.py +++ b/langgraph/pregel/__init__.py @@ -563,7 +563,10 @@ def _read_channel( try: return channels[chan].get() except EmptyChannelError: - return None + if catch: + return None + else: + raise def _apply_writes( @@ -604,7 +607,7 @@ def _apply_writes_from_view( checkpoint: Checkpoint, channels: Mapping[str, BaseChannel], values: dict[str, Any] ) -> None: for chan, value in values.items(): - if value == channels[chan].get(): + if value == _read_channel(channels, chan): continue assert isinstance(channels[chan], LastValue), ( diff --git a/langgraph/pregel/write.py b/langgraph/pregel/write.py index 2063f5018..e44b3e3db 100644 --- a/langgraph/pregel/write.py +++ b/langgraph/pregel/write.py @@ -51,6 +51,11 @@ class ChannelWrite(RunnablePassthrough): values = [ (chan, r.invoke(input, config) if r else input) for chan, r in self.channels ] + values = [ + write + for write, chan in zip(values, self.channels) + if chan[1] is None or write[1] is not None + ] self.do_write(config, **dict(values)) @@ -59,10 +64,15 @@ class ChannelWrite(RunnablePassthrough): (chan, await r.ainvoke(input, config) if r else input) for chan, r in self.channels ] + values = [ + write + for write, chan in zip(values, self.channels) + if chan[1] is None or write[1] is not None + ] self.do_write(config, **dict(values)) @staticmethod def do_write(config: RunnableConfig, **values: Any) -> None: write: TYPE_SEND = config["configurable"][CONFIG_KEY_SEND] - write([(chan, val) for chan, val in values.items() if val is not None]) + write([(chan, val) for chan, val in values.items()])