This commit is contained in:
Nuno Campos
2024-01-13 15:58:25 -08:00
parent d68faa6d06
commit e497d14db0
3 changed files with 18 additions and 4 deletions
+2 -1
View File
@@ -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
+5 -2
View File
@@ -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), (
+11 -1
View File
@@ -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()])