Tool function return Command with goto variable cause parallel running

hi @padanes

The parallel run happens because both routes are being scheduled:

  • Your tool returns a Command(goto="SOP_executor", ...), which dynamically routes to SOP_executor.

  • You also have a static edge workflow.add_edge("tools", "supervisor"). Static edges are written every time the tools node finishes, so the graph also schedules supervisor again. Result: SOP_executor and supervisor run in parallel on the next step.

Two changes should fix this:

  1. Do not keep an unconditional edge from tools to supervisor when you want a handoff.
  • Remove workflow.add_edge("tools", "supervisor"). The goto="SOP_executor" will take control and send execution there, so supervisor will not be scheduled again.
  • If you also want the normal “tool → supervisor” loop for other tools, wrap the ToolNode to default back to supervisor only when the tool returns a regular ToolMessage (not a Command):
from langgraph.types import Command
from langchain_core.messages import ToolMessage

def wrap_tool_call(request, execute):
    result = execute(request)
    if isinstance(result, ToolMessage):
        return Command(
            update={"messages": [result]},
            goto="supervisor",
            graph=Command.PARENT,
        )
    return result

workflow.add_node("tools", ToolNode(tools, wrap_tool_call=wrap_tool_call))
# Note: keep the tools->supervisor static edge removed.
  1. OPTIONAL: When returning a Command from a tool (inside a subgraph), target the parent graph explicitly.
return Command(
    goto="SOP_executor",
    update={**runtime.state, "messages": runtime.state["messages"] + [tool_message]},
    graph=Command.PARENT,  # important when running from within a subgraph
)

Why this is expected in LangGraph

  • A Command.goto adds dynamic routing; it does not implicitly disable existing static edges. With both in place, both branches are scheduled.

  • Returning graph=Command.PARENT from a tool is the documented way to navigate in the parent graph from within a tool execution inside a subgraph.