[PR #2393] lib: Add interrupt() function #2674

Closed
opened 2026-02-20 17:47:23 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/2393

State: closed
Merged: Yes


  • This works similarly to the input() function from stdlib
  • calling it in a node interrupts execution
  • invoking the graph with Command(resume=...) will set ... as the return value of interrupt() so that the node can access the "answer" to the "question"
  • This PR also starts the work to control the graph on invoke/stream with Command() input, to be continued in a future PR
    class State(TypedDict):
        my_key: Annotated[str, operator.add]
        market: str

    async def tool_two_node(s: State) -> State:
        if s["market"] == "DE":
            answer = interrupt("Just because...")
        else:
            answer = " all good"
        return {"my_key": answer}

    tool_two_graph = StateGraph(State)
    tool_two_graph.add_node("tool_two", tool_two_node)
    tool_two_graph.add_edge(START, "tool_two")
    tool_two = tool_two_graph.compile()

        tool_two = tool_two_graph.compile(checkpointer=checkpointer)

        # flow: interrupt -> resume with answer
        thread2 = {"configurable": {"thread_id": "2"}}
        # stop when about to enter node
        assert [
            c
            async for c in tool_two.astream(
                {"my_key": "value ⛰️", "market": "DE"}, thread2
            )
        ] == [
            {"__interrupt__": [Interrupt(value="Just because...", when="during")]},
        ]
        # resume with answer
        assert [
            c async for c in tool_two.astream(Command(resume=" my answer"), thread2)
        ] == [
            {"tool_two": {"my_key": " my answer"}},
        ]
**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/2393 **State:** closed **Merged:** Yes --- - This works similarly to the input() function from stdlib - calling it in a node interrupts execution - invoking the graph with Command(resume=...) will set ... as the return value of interrupt() so that the node can access the "answer" to the "question" - This PR also starts the work to control the graph on invoke/stream with Command() input, to be continued in a future PR ```py class State(TypedDict): my_key: Annotated[str, operator.add] market: str async def tool_two_node(s: State) -> State: if s["market"] == "DE": answer = interrupt("Just because...") else: answer = " all good" return {"my_key": answer} tool_two_graph = StateGraph(State) tool_two_graph.add_node("tool_two", tool_two_node) tool_two_graph.add_edge(START, "tool_two") tool_two = tool_two_graph.compile() tool_two = tool_two_graph.compile(checkpointer=checkpointer) # flow: interrupt -> resume with answer thread2 = {"configurable": {"thread_id": "2"}} # stop when about to enter node assert [ c async for c in tool_two.astream( {"my_key": "value ⛰️", "market": "DE"}, thread2 ) ] == [ {"__interrupt__": [Interrupt(value="Just because...", when="during")]}, ] # resume with answer assert [ c async for c in tool_two.astream(Command(resume=" my answer"), thread2) ] == [ {"tool_two": {"my_key": " my answer"}}, ] ```
yindo added the pull-request label 2026-02-20 17:47:23 -05:00
yindo closed this issue 2026-02-20 17:47:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#2674