-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: Add support for multiple interrupts per node #2636
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
|
||
from langgraph.channels.base import BaseChannel | ||
from langgraph.checkpoint.base import ( | ||
WRITES_IDX_MAP, | ||
BaseCheckpointSaver, | ||
ChannelVersions, | ||
Checkpoint, | ||
|
@@ -263,8 +264,28 @@ def put_writes(self, task_id: str, writes: Sequence[tuple[str, Any]]) -> None: | |
"""Put writes for a task, to be read by the next tick.""" | ||
if not writes: | ||
return | ||
# deduplicate writes to special channels, last write wins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ooc: why do we know we don't have to deduplicate if one of the writes is to a regular channel? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regular channels can't be written to more than once (writes after the first are ignored) |
||
if all(w[0] in WRITES_IDX_MAP for w in writes): | ||
writes = list({w[0]: w for w in writes}.values()) | ||
# save writes | ||
self.checkpoint_pending_writes.extend((task_id, k, v) for k, v in writes) | ||
for c, v in writes: | ||
if ( | ||
c in WRITES_IDX_MAP | ||
and ( | ||
idx := next( | ||
( | ||
i | ||
for i, w in enumerate(self.checkpoint_pending_writes) | ||
if w[0] == task_id and w[1] == c | ||
), | ||
None, | ||
) | ||
) | ||
is not None | ||
): | ||
self.checkpoint_pending_writes[idx] = (task_id, c, v) | ||
else: | ||
self.checkpoint_pending_writes.append((task_id, c, v)) | ||
if self.checkpointer_put_writes is not None: | ||
self.submit( | ||
self.checkpointer_put_writes, | ||
|
@@ -536,7 +557,7 @@ def _first(self, *, input_keys: Union[str, Sequence[str]]) -> None: | |
elif isinstance(self.input, Command): | ||
writes: defaultdict[str, list[tuple[str, Any]]] = defaultdict(list) | ||
# group writes by task ID | ||
for tid, c, v in map_command(self.input): | ||
for tid, c, v in map_command(self.input, self.checkpoint_pending_writes): | ||
writes[tid].append((c, v)) | ||
if not writes: | ||
raise EmptyInputError("Received empty Command input") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is CONFIG_KEY_RESUME_VALUE used anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, removed now