mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-10 03:37:51 +02:00
revert(langgraph): restore logic to surface interrupts for stream_mod… (#6141)
### Description Revert change in #5201 that prevented the surfacing of interrupts when `stream_mode="values"`. [Comment highlighting affected lines](https://github.com/langchain-ai/langgraph/pull/5201#discussion_r2344884841) Resolves #5409 ### Test Add test to verify interrupts are properly surfaced when `stream_mode="values"` (`test_interrupt_stream_mode_values`)
This commit is contained in:
@@ -904,7 +904,11 @@ class PregelLoop:
|
||||
)
|
||||
}
|
||||
]
|
||||
self._emit("updates", lambda: iter(interrupts))
|
||||
stream_modes = self.stream.modes if self.stream else []
|
||||
if "updates" in stream_modes:
|
||||
self._emit("updates", lambda: iter(interrupts))
|
||||
elif "values" in stream_modes:
|
||||
self._emit("values", lambda: iter(interrupts))
|
||||
elif writes[0][0] != ERROR:
|
||||
self._emit(
|
||||
"updates",
|
||||
|
||||
@@ -8430,3 +8430,22 @@ def test_null_resume_disallowed_with_multiple_interrupts(
|
||||
"text_1": "resume for prompt: original text 1",
|
||||
"text_2": "resume for prompt: original text 2",
|
||||
}
|
||||
|
||||
|
||||
def test_interrupt_stream_mode_values():
|
||||
"""Test that interrupts are surfaced when steam_mode='values'"""
|
||||
|
||||
class State(TypedDict):
|
||||
human_input: str
|
||||
|
||||
def human_input_node(state: State) -> Command:
|
||||
human_input = interrupt("interrupt")
|
||||
return Command(update={"human_input": human_input})
|
||||
|
||||
builder = StateGraph(State)
|
||||
builder.add_node(human_input_node)
|
||||
builder.add_edge(START, "human_input_node")
|
||||
app = builder.compile()
|
||||
|
||||
result = [*app.stream(State(), stream_mode="values")]
|
||||
assert "__interrupt__" in result[-1]
|
||||
|
||||
Reference in New Issue
Block a user