-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
In the subgraph, when there is a branch point to __end__(or __start__ point to ...), it will lose part of the edges #1676
Comments
import secrets
from langgraph.graph import END, START, MessagesState, StateGraph
from langgraph.graph.state import CompiledStateGraph
def foo(_: MessagesState) -> None:
return
def branch() -> bool:
return secrets.choice([True, False])
def sub() -> CompiledStateGraph:
workflow = StateGraph(MessagesState)
for node in ["A", "B", "M", "Y", "Z"]:
workflow.add_node(node, foo)
workflow.add_conditional_edges(START, branch, {True: "A", False: "B"})
workflow.add_edge("A", "M")
workflow.add_edge("B", "M")
workflow.add_conditional_edges("M", branch, {True: "Y", False: "Z"})
workflow.add_edge("Y", END)
workflow.add_edge("Z", END)
return workflow.compile()
def main() -> CompiledStateGraph:
workflow = StateGraph(MessagesState)
workflow.add_node("main_entry", foo)
workflow.add_node("sub_1", sub())
workflow.add_node("main_exit", foo)
workflow.add_edge(START, "main_entry")
workflow.add_edge("main_entry", "sub_1")
workflow.add_edge("sub_1", "main_exit")
workflow.add_edge("main_exit", END)
return workflow.compile()
if __name__ == "__main__":
sub_graph = sub()
sub_graph.get_graph().draw_mermaid_png(output_file_path="_only_sub.png")
graph = main()
graph.get_graph(xray=1).draw_mermaid_png(output_file_path="_with_sub.png") But in this example, edges didn't disappear; instead, Because in a simple single-line subgraph, import secrets
from langgraph.graph import END, START, MessagesState, StateGraph
from langgraph.graph.state import CompiledStateGraph
def foo(_: MessagesState) -> None:
return
def branch() -> bool:
return secrets.choice([True, False])
def sub() -> CompiledStateGraph:
workflow = StateGraph(MessagesState)
for node in ["A", "B", "C"]:
workflow.add_node(node, foo)
workflow.add_edge(START, "A")
workflow.add_edge("A", "B")
workflow.add_edge("B", "C")
workflow.add_edge("C", END)
return workflow.compile()
def main() -> CompiledStateGraph:
workflow = StateGraph(MessagesState)
workflow.add_node("main_entry", foo)
workflow.add_node("sub_1", sub())
workflow.add_node("main_exit", foo)
workflow.add_edge(START, "main_entry")
workflow.add_edge("main_entry", "sub_1")
workflow.add_edge("sub_1", "main_exit")
workflow.add_edge("main_exit", END)
return workflow.compile()
if __name__ == "__main__":
sub_graph = sub()
sub_graph.get_graph().draw_mermaid_png(output_file_path="_only_sub.png")
graph = main()
graph.get_graph(xray=1).draw_mermaid_png(output_file_path="_with_sub.png") |
But when we try to direct the three edges towards end, everything seems to become normal again. import secrets
from langgraph.graph import END, START, MessagesState, StateGraph
from langgraph.graph.state import CompiledStateGraph
def foo(_: MessagesState) -> None:
return
def branch() -> bool:
return secrets.choice([True, False])
def sub() -> CompiledStateGraph:
workflow = StateGraph(MessagesState)
for node in ["A", "B", "M", "N", "Z"]:
workflow.add_node(node, foo)
workflow.add_conditional_edges(START, branch, {True: "A", False: "B"})
workflow.add_edge("A", "M")
workflow.add_edge("B", "N")
workflow.add_conditional_edges("M", branch, {True: "Z", False: END})
workflow.add_edge("Z", END)
workflow.add_edge("N", END)
return workflow.compile()
def main() -> CompiledStateGraph:
workflow = StateGraph(MessagesState)
workflow.add_node("main_entry", foo)
workflow.add_node("sub_1", sub())
workflow.add_node("main_exit", foo)
workflow.add_edge(START, "main_entry")
workflow.add_edge("main_entry", "sub_1")
workflow.add_edge("sub_1", "main_exit")
workflow.add_edge("main_exit", END)
return workflow.compile()
if __name__ == "__main__":
sub_graph = sub()
sub_graph.get_graph().draw_mermaid_png(output_file_path="_only_sub.png")
graph = main()
graph.get_graph(xray=1).draw_mermaid_png(output_file_path="_with_sub.png") |
Hi! I'm a student at UofT and our team would love to work on this issue. Have there been any more developments/bugs you've noticed? |
I'm not sure if anyone is currently addressing this issue. |
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
Description
When there is an edge pointing from start or towards end, and another edge points to a node, part of the edges will disappear.
System Info
langgraph==0.2.19
langchain-core==0.2.38
The text was updated successfully, but these errors were encountered: