Final node doesn't wait all other incoming nodes #140

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

Originally created by @BuslovGart on GitHub (Jul 8, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

import asyncio
from typing import Annotated

from typing_extensions import TypedDict

from langgraph.graph.message import add_messages
from langgraph.graph import END, StateGraph, START

class State(TypedDict):
    messages: Annotated[list, add_messages]


async def call_node(state: State):
    print("call_node")
    return state

async def call_node_2(state: State):
    print("call_node 2 start")
    await asyncio.sleep(5)
    print("call_node 2 finish")
    return state

async def call_node_2_2(state: State):
    print("call_node 2_2 start")
    await asyncio.sleep(3)
    print("call_node 2_2 finish")
    return state

# Define a new graph
workflow = StateGraph(State)

# Define the two nodes we will cycle between
workflow.add_node("agent", lambda x: print('agent'))
workflow.add_node("agent_2", call_node_2)
workflow.add_node("agent_2_1", lambda x: print('agent_2_1'))
workflow.add_node("agent_2_2", call_node_2_2)
workflow.add_node("agent_2_3", lambda x: print('agent_2_3'))
workflow.add_node("agent_3", lambda x: print('agent_3'))
workflow.add_node("agent_4", lambda x: print('agent_4'))

# Set the entrypoint as `agent`
# This means that this node is the first one called
workflow.add_edge(START, "agent")

# We now add a conditional edge
workflow.add_conditional_edges(
    "agent",
    lambda x: ["agent_2", "agent_3"],
    {
        "agent_2": "agent_2",
        "agent_3": "agent_3",
    },
)

# We now add a conditional edge
workflow.add_conditional_edges(
    "agent_2_1",
    lambda x: "True",
    {
        "True": "agent_2_2",
        "False": "agent_2_3",
    },
)
workflow.add_edge("agent_2", "agent_2_1")
workflow.add_edge("agent_3", "agent_4")
workflow.add_edge("agent_2_2", "agent_4")
workflow.add_edge("agent_2_3", "agent_4")
workflow.add_edge("agent_4", END)

app = workflow.compile()

async def main():
    inputs = {"messages": []}
    print(app.get_graph().draw_ascii())
    await app.ainvoke(inputs)
    
asyncio.run(main())

Error Message and Stack Trace (if applicable)

No response

Description

Hello, guys
Please, help me out with this problem
I've upgraded to latest langgraph

Look at the image
When there's agent_2`` and agent_3-agent_4waits until both of them finish and then continues BUT when I addagent_2_1condition - it ruins.agent_4must wait foragent_2_2andagent_3, but in fact it allows agent_3to finish, thenagent_4calls, after this finishesagent_2_2and AGAINagent_4 calls`

The order of calling is this:

agent
call_node 2 start
agent_3
call_node 2 finish
agent_2_1
agent_4
call_node 2_2 start
call_node 2_2 finish
agent_4

This problem is present both in older versions of langgraph and in newest

System Info

langgraph == 0.1.5 OR (try on older version) == 0.0.48

Originally created by @BuslovGart on GitHub (Jul 8, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the [LangGraph](https://langchain-ai.github.io/langgraph/)/LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangGraph/LangChain rather than my code. - [X] I am sure this is better as an issue [rather than a GitHub discussion](https://github.com/langchain-ai/langgraph/discussions/new/choose), since this is a LangGraph bug and not a design question. ### Example Code ```python import asyncio from typing import Annotated from typing_extensions import TypedDict from langgraph.graph.message import add_messages from langgraph.graph import END, StateGraph, START class State(TypedDict): messages: Annotated[list, add_messages] async def call_node(state: State): print("call_node") return state async def call_node_2(state: State): print("call_node 2 start") await asyncio.sleep(5) print("call_node 2 finish") return state async def call_node_2_2(state: State): print("call_node 2_2 start") await asyncio.sleep(3) print("call_node 2_2 finish") return state # Define a new graph workflow = StateGraph(State) # Define the two nodes we will cycle between workflow.add_node("agent", lambda x: print('agent')) workflow.add_node("agent_2", call_node_2) workflow.add_node("agent_2_1", lambda x: print('agent_2_1')) workflow.add_node("agent_2_2", call_node_2_2) workflow.add_node("agent_2_3", lambda x: print('agent_2_3')) workflow.add_node("agent_3", lambda x: print('agent_3')) workflow.add_node("agent_4", lambda x: print('agent_4')) # Set the entrypoint as `agent` # This means that this node is the first one called workflow.add_edge(START, "agent") # We now add a conditional edge workflow.add_conditional_edges( "agent", lambda x: ["agent_2", "agent_3"], { "agent_2": "agent_2", "agent_3": "agent_3", }, ) # We now add a conditional edge workflow.add_conditional_edges( "agent_2_1", lambda x: "True", { "True": "agent_2_2", "False": "agent_2_3", }, ) workflow.add_edge("agent_2", "agent_2_1") workflow.add_edge("agent_3", "agent_4") workflow.add_edge("agent_2_2", "agent_4") workflow.add_edge("agent_2_3", "agent_4") workflow.add_edge("agent_4", END) app = workflow.compile() async def main(): inputs = {"messages": []} print(app.get_graph().draw_ascii()) await app.ainvoke(inputs) asyncio.run(main()) ``` ### Error Message and Stack Trace (if applicable) _No response_ ### Description Hello, guys Please, help me out with this problem I've upgraded to latest langgraph Look at the image When there's `agent_2`` and `agent_3` - `agent_4` waits until both of them finish and then continues BUT when I add `agent_2_1` condition - it ruins. `agent_4` must wait for `agent_2_2` and `agent_3`, but in fact it allows `agent_3` to finish, then `agent_4` calls, after this finishes `agent_2_2` and AGAIN `agent_4 calls` The order of calling is this: ``` agent call_node 2 start agent_3 call_node 2 finish agent_2_1 agent_4 call_node 2_2 start call_node 2_2 finish agent_4 ``` This problem is present both in older versions of langgraph and in newest ### System Info langgraph == 0.1.5 OR (try on older version) == 0.0.48
yindo closed this issue 2026-02-20 17:28:52 -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#140