-
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
Resume value get reused when resuming parent graph which has subgraph with multiple interrupts #2870
Comments
I can replicate this issue; it seems to not work properly in the subgraph. I added some extra from langgraph.checkpoint.memory import MemorySaver
from langgraph.graph import END, START, MessagesState, StateGraph
from langgraph.types import Command, interrupt
from rich import get_console
def node_1(state: MessagesState) -> None:
print("---node_1---")
result = interrupt("interrupt node 1")
get_console().print(f"{result = }")
def node_2(state: MessagesState) -> None:
print("---node_2---")
result = interrupt("interrupt node 2")
get_console().print(f"{result = }")
sub_graph = (
StateGraph(MessagesState)
.add_node(node_1)
.add_node(node_2)
.add_edge(START, node_1.__name__)
.add_edge(node_1.__name__, node_2.__name__)
.add_edge(node_2.__name__, END)
.compile()
)
sub_graph.name = "sub"
def enter_sub_agent(state: MessagesState) -> None:
print("---enter_sub_agent---")
result = interrupt("interrupt enter_sub_agent")
get_console().print(f"{result = }")
def exit_sub_agent(state: MessagesState) -> None:
print("---exit_sub_agent---")
result = interrupt("interrupt exit_sub_agent")
get_console().print(f"{result = }")
parent_agent = (
StateGraph(MessagesState)
.add_node(enter_sub_agent)
.add_node(sub_graph)
.add_node(exit_sub_agent)
.add_edge(START, enter_sub_agent.__name__)
.add_edge(enter_sub_agent.__name__, sub_graph.get_name())
.add_edge(sub_graph.get_name(), exit_sub_agent.__name__)
.add_edge(exit_sub_agent.__name__, END)
.compile(checkpointer=MemorySaver())
)
config = {"configurable": {"thread_id": "1"}}
for event in parent_agent.stream(
MessagesState(messages=[]), config, stream_mode="updates", subgraphs=True
):
print(event)
print("\n")
def resume(resume_value: str) -> None:
for event in parent_agent.stream(
Command(resume=resume_value), config, stream_mode="updates", subgraphs=True
):
print(event)
print("\n")
resume("Enter sub agent")
resume("Node 1")
resume("Node 2")
# resume("Exit sub agent") |
Encountering the same issue. When executing
|
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
No response
Description
As described in the Example code section. I have
parent_graph -> subgraph (two interrupts)
when invoke parent_graph, the parent_graph stops at the first subgraph interrupt as expected. Then I resume, the expected behavior is the graph should pass the first interrupt and stop at the second interrupt, however, both interrupt passed. The second interrupt returns the value I passed for resuming the first interrupt instead of raising a new interrupt.
System Info
langgraph==0.2.60
The text was updated successfully, but these errors were encountered: