Command
Update and go.
Usually, a node updates the state, and a separate edge decides where to go next. Command lets one node do both at once. Return a command, with an update, and a go to.

- Update in the node
- Route in the edge
- Command does both
Triage with Command
The triage node returns a command. Its update saves a priority. Its go to picks the next node. The return type lists the possible targets, so LangGraph can draw the graph. Notice there are no edges out of triage at all. Run it. A large refund goes to the manager, and a small one goes straight through.
from typing import Literal, TypedDict
from langgraph.graph import StateGraph, START
from langgraph.types import Command
class State(TypedDict):
amount: float
priority: str
handled_by: str
def triage(s) -> Command[Literal["manager", "auto"]]:
if s["amount"] > 20:
return Command(update={"priority": "high"}, goto="manager")
return Command(update={"priority": "low"}, goto="auto")
b = StateGraph(State); b.add_node(triage); b.add_edge(START, "triage")
b.add_node("manager", lambda s: {"handled_by": "manager"})
b.add_node("auto", lambda s: {"handled_by": "automatic"})
for amount in [45.0, 8.0]:
print(amount, b.compile().invoke({"amount": amount}))45.0 {'amount': 45.0, 'priority': 'high', 'handled_by': 'manager'}
8.0 {'amount': 8.0, 'priority': 'low', 'handled_by': 'automatic'}Command vs edges
Use conditional edges when routing is simple, and separate from the work. Use command when the node that does the work also knows where to go next. Command is especially handy for agents handing control to each other.
| key | value |
|---|---|
| Edges | routing kept separate |
| Command | work + route together |
| Return type | lists the targets |
| Great for | agent handoffs |
Summary
A command updates the state and chooses the next node, from inside one node. Next, why we might split work across several agents.
Key takeaways- Command(update, goto)
- Literal targets
- No edges needed