How to make multiple branches execute in parallel with conditional branches #386

Closed
opened 2026-02-20 17:39:51 -05:00 by yindo · 1 comment
Owner

Originally created by @fuyuku on GitHub (Jan 7, 2025).

          @gbaian10 for the first part of your question:

Q1: When the start_key in add_edge is a list, the end_key can't be end.

this is fixed this in https://github.com/langchain-ai/langgraph/pull/1478

Q2: When the input is a list, you must add the node before adding an edge.

This is a good point, but we discussed internally and decided to keep this as is for an extra layer of validation


for the remainder of this discussion / questions / examples you listed:

graph_builder.add_edge(["A", "B"], END)

^ This will triggers C after both A and B have completed

graph_builder.add_edge("A", END)
graph_builder.add_edge("B", END)

^ This will trigger C after either A or B have completed

In the last example you provided you can verify this by changing the edges to

builder.add_edge(["b", "c"], "e")
builder.add_edge(["c", "d"], "e")

The reason why the previous code snippet with builder.add_edge(["b", "c", "d"], "e") didn't work is because you need all of the nodes (b, c and d) to complete which they can't in that case.

Closing the issue as the library is working as intended -- thank you for the questions and thoughtful discussion.

Originally posted by @vbarda in https://github.com/langchain-ai/langgraph/issues/1462#issuecomment-2313052133


The reason why the previous code snippet with builder.add_edge(["b", "c", "d"], "e") didn't work is because you need all of the nodes (b, c and d) to complete which they can't in that case.

What should be done to make the branch execute in parallel when encountering this situation.

How can b or c be executed in parallel with d when b and c belong to different conditional branches.

Originally created by @fuyuku on GitHub (Jan 7, 2025). @gbaian10 for the first part of your question: > Q1: When the start_key in add_edge is a list, the end_key can't be __end__. this is fixed this in https://github.com/langchain-ai/langgraph/pull/1478 > Q2: When the input is a list, you must add the node before adding an edge. This is a good point, but we discussed internally and decided to keep this as is for an extra layer of validation --- for the remainder of this discussion / questions / examples you listed: ```python graph_builder.add_edge(["A", "B"], END) ``` ^ This will triggers C after _both_ A and B have completed ```python graph_builder.add_edge("A", END) graph_builder.add_edge("B", END) ``` ^ This will trigger C after either A or B have completed In the last example you provided you can verify this by changing the edges to ```python builder.add_edge(["b", "c"], "e") builder.add_edge(["c", "d"], "e") ``` The reason why the previous code snippet with builder.add_edge(["b", "c", "d"], "e") didn't work is because you need all of the nodes (`b`, `c` and `d`) to complete which they can't in that case. Closing the issue as the library is working as intended -- thank you for the questions and thoughtful discussion. _Originally posted by @vbarda in https://github.com/langchain-ai/langgraph/issues/1462#issuecomment-2313052133_ --- > The reason why the previous code snippet with builder.add_edge(["b", "c", "d"], "e") didn't work is because you need all of the nodes (`b`, `c` and `d`) to complete which they can't in that case. What should be done to make the branch execute in parallel when encountering this situation. How can b or c be executed in parallel with d when b and c belong to different conditional branches.
yindo closed this issue 2026-02-20 17:39:52 -05:00
Author
Owner

@vbarda commented on GitHub (Jan 8, 2025):

Could you please provide an example graph and say more about what you're trying to achieve? Also, will turn this into a discussion since there is no explicit issue

@vbarda commented on GitHub (Jan 8, 2025): Could you please provide an example graph and say more about what you're trying to achieve? Also, will turn this into a discussion since there is no explicit issue
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#386