This is the code at a high level. I am using LangGraph with a router node that uses `Command` to route execution to `END`, `planner`, `tools`, or invoke a subgraph from main graph
# ===============================
# Router Node
# ===============================
async def router_node(state: MainGraphState) -> Command[Literal["tools", "planner", "__end__"]]:
print("-" * 30 + "ENTERING ROUTER NODE " + "-" * 30)
messages = state["messages"]
last_message = messages[-1]
if len(last_message.tool_calls) == 0:
print("✅ No tool calls detected, finishing execution.")
return Command(goto=END)
# Current implementation handles only one tool call per message
tool_call = last_message.tool_calls[0]
if tool_call["name"] == "subgraph_dispatch":
tool_name = tool_call["args"]["subgraph_name"]
tool_query = tool_call["args"]["query"]
print(f"🔍 Routing to subgraph based on tool call: {tool_name} with query: {tool_query}\n")
if tool_name == SubgraphName.SEARCH.value:
result = await search_subgraph.ainvoke({"local_messages": [HumanMessage(content=tool_query)]})
response = result["local_messages"][-1].content
return Command(update={"messages": [ToolMessage(content=response,tool_call_id=tool_call["id"])]}, goto="planner")
else:
return Command(update={"messages": [ToolMessage(content="Subgraph not found")]}, goto="planner")
else:
return Command(goto="tools")
As shown in the video, In langSmith Studio’s Interact, the flow appears to return from the subgraph’s end to the main graph’s planner or ToolNode or end.
Due to this, when the AI agent does not make a tool call to subgraph, the execution appears to get stuck in the Interact and Trace views. However, the terminal running langgraph dev shows the expected behavior: the execution enters the “no tool calls” branch, exits the router node and terminates successfully.

