mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-24 00:22:25 +02:00
chore: simplify invoke interrupt collection
The loop already merges __interrupt__ into the values dict in output_writes(), so invoke/ainvoke don't need to subscribe to both "updates" and "values" stream modes. Simplify to just use stream_mode="values" and read interrupts directly from the values payload. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
901ab6b3f8
commit
37ea45d065
@@ -3095,9 +3095,7 @@ class Pregel(
|
||||
input,
|
||||
config,
|
||||
context=context,
|
||||
stream_mode=["updates", "values"]
|
||||
if stream_mode == "values"
|
||||
else stream_mode,
|
||||
stream_mode="values" if stream_mode == "values" else stream_mode,
|
||||
print_mode=print_mode,
|
||||
output_keys=output_keys,
|
||||
interrupt_before=interrupt_before,
|
||||
@@ -3106,20 +3104,9 @@ class Pregel(
|
||||
**kwargs,
|
||||
):
|
||||
if stream_mode == "values":
|
||||
if len(chunk) == 2:
|
||||
mode, payload = cast(tuple[StreamMode, Any], chunk)
|
||||
else:
|
||||
_, mode, payload = cast(
|
||||
tuple[tuple[str, ...], StreamMode, Any], chunk
|
||||
)
|
||||
if (
|
||||
mode == "updates"
|
||||
and isinstance(payload, dict)
|
||||
and (ints := payload.get(INTERRUPT)) is not None
|
||||
):
|
||||
latest = chunk
|
||||
if isinstance(chunk, dict) and (ints := chunk.get(INTERRUPT)) is not None:
|
||||
interrupts.extend(ints)
|
||||
elif mode == "values":
|
||||
latest = payload
|
||||
else:
|
||||
chunks.append(chunk)
|
||||
|
||||
@@ -3185,9 +3172,7 @@ class Pregel(
|
||||
input,
|
||||
config,
|
||||
context=context,
|
||||
stream_mode=["updates", "values"]
|
||||
if stream_mode == "values"
|
||||
else stream_mode,
|
||||
stream_mode="values" if stream_mode == "values" else stream_mode,
|
||||
print_mode=print_mode,
|
||||
output_keys=output_keys,
|
||||
interrupt_before=interrupt_before,
|
||||
@@ -3196,20 +3181,9 @@ class Pregel(
|
||||
**kwargs,
|
||||
):
|
||||
if stream_mode == "values":
|
||||
if len(chunk) == 2:
|
||||
mode, payload = cast(tuple[StreamMode, Any], chunk)
|
||||
else:
|
||||
_, mode, payload = cast(
|
||||
tuple[tuple[str, ...], StreamMode, Any], chunk
|
||||
)
|
||||
if (
|
||||
mode == "updates"
|
||||
and isinstance(payload, dict)
|
||||
and (ints := payload.get(INTERRUPT)) is not None
|
||||
):
|
||||
latest = chunk
|
||||
if isinstance(chunk, dict) and (ints := chunk.get(INTERRUPT)) is not None:
|
||||
interrupts.extend(ints)
|
||||
elif mode == "values":
|
||||
latest = payload
|
||||
else:
|
||||
chunks.append(chunk)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user