Even after conditional edge, child nodes are called in parallel

Hello Everyone,

I am very new to Langgraph. I am trying to run a program but I am nnot getting the expected result.

Here is my graph and the code

graph = StateGraph(Person)
graph.add_node("node_1", node_1)
graph.add_node("node_2", node_2)
graph.add_node("node_3", node_3)
graph.add_node("node_4", node_4)
graph.add_node("node_5", node_5)
graph.add_node("node_6", node_6)

graph.add_edge(START,"node_1")
graph.add_conditional_edges("node_1", condition_node1)
graph.add_edge("node_2",END)
graph.add_edge("node_3", "node_4")
graph.add_edge("node_3", "node_5")
graph.add_edge("node_3", "node_6")
graph.add_conditional_edges("node_3", condition_node3)
graph.add_edge("node_4",END)
graph.add_edge("node_5", END)
graph.add_edge("node_6", END)

compiled_graph = graph.compile()
print(compiled_graph.get_graph().draw_mermaid())

result = compiled_graph.invoke({"name":"Hi I am Burhan", "age":5, "city":"LON", "gametype":"men"})

Based on the below output, it looks like node4, node5 and node6 all are executed in parallel although based on the condition only node4 should be executed. Below are the print statements from each of the python functions.

Output

node_1
node_3
node4
node5
node_6

Looking forward to guidance.

Thanks,

Jainesh

Hey Jainesh,

the problem is in the following lines:

graph.add_edge("node_3", "node_4")
graph.add_edge("node_3", "node_5")
graph.add_edge("node_3", "node_6")
graph.add_conditional_edges("node_3", condition_node3)
graph.add_edge("node_4",END)
graph.add_edge("node_5", END)
graph.add_edge("node_6", END)

After node_3 you always enter node_4, node_5 and node_6 in parallel as they are all connected via an edge to node_3. Afterwards, you have an extra conditional edge to all 3 nodes, which explains the decision of node 4. If you delete the first quoted 3 lines you should get your desired results.

Best regards.