LangGraph/Advanced
Advanced10 min

Command API

Edgeless graphs where nodes dynamically choose the next node. Command(goto=, update=). Building flexible agent flows without static edges.

Quick Reference

  • Command(goto='node_name'): route to a specific node from inside the current node
  • Command(update={'key': value}): update state and route in a single return statement
  • Command(goto=['a', 'b']): fan out to multiple nodes simultaneously from within a node
  • Edgeless graphs: build entire flows using only Command returns — no add_edge() or add_conditional_edges() needed
  • Command replaces conditional edges when routing logic is tightly coupled with node computation

Command Basics

Route + update state in one return
Command = routing + state update, atomic

Command combines state mutation and routing into a single atomic operation. Instead of updating state in the node and then routing with a separate conditional edge function, Command does both in one return statement. The state update and the routing decision happen together -- there is no intermediate state where one happened but not the other.

Without Command, you would split this into two pieces: the node returns {'analysis': result} and a separate routing function reads state['analysis']['needs_review'] to pick the next node. Command collapses this into a single return, keeping the routing logic co-located with the computation that produces the data. This is especially useful when the routing decision is a direct consequence of what the node just computed.