6.2

Edges, Send, and Command

A plain edge always runs, a conditional edge picks from the state, Send starts one task per item, and Command updates and routes in one return.

You have a list of subjects whose length you learn only at run time, and you want one model call for each subject. After them, one node must choose between two endings and record why. You need three kinds of routing in one graph.

When you finish this section, you can connect nodes with plain and conditional edges. You can also start a variable number of tasks with Send, and route from a node with Command.

The graph

The kit graph of section 6.1 has five nodes. This is the code that connects them:

pythonthe nodes and edges of the joke graphFull log
    graph = StateGraph(Fanout)
    graph.add_node("plan", plan)
    graph.add_node("write_joke", write_joke)
    graph.add_node("pick", pick)
    graph.add_node("publish", publish)
    graph.add_node("retry", retry)
    graph.add_edge(START, "plan")
    graph.add_conditional_edges("plan", fan_out, ["write_joke"])
    graph.add_edge("write_joke", "pick")
    graph.add_edge("publish", END)
    graph.add_edge("retry", END)
    app = graph.compile()

compile checks the graph and returns the object you run. The graph API page says that you must compile a graph before you invoke or stream it. The Mermaid text of the compiled graph shows every edge. A solid arrow --> is a plain edge, and a dotted arrow -.-> is a conditional one:

outputthe edges of the compiled graphFull log
	__start__ --> plan;
	pick -.-> publish;
	pick -.-> retry;
	plan -.-> write_joke;
	write_joke --> pick;
	publish --> __end__;
	retry --> __end__;
The edge lines of the Mermaid text. The node lines and the styles are cut.

No add_edge call leaves pick, but the graph has two edges out of it. They come from the return type of pick, as the next part shows.

Figure 6.2 draws the full Mermaid text from top to bottom.

Fig. 6.2the joke graph as LangGraph draws itstructure
The joke graph as LangGraph draws it The compiled joke graph drawn from its draw_mermaid output, top to bottom. It has 7 nodes and 7 edges. The 3 conditional edges are pick to publish, pick to retry, plan to write_joke. The edge from plan comes from add_conditional_edges with Send. The two edges from pick come from the Command return type of pick, with no add_edge call. GET_GRAPH().DRAW_MERMAID() 4 plain edges, 3 conditional __start__ plan write_joke pick publish retry __end__ Send: one write_joke task for each subject pick returns a Command plain edge conditional edge, chosen at run time
The Mermaid text has three conditional edges, from plan and from pick, and no add_edge call made any of them. Read from __start__ at the top. Solid arrows are add_edge calls. Dashed amber arrows come from Send and from the Command return type.

Figure 6.3 draws the graph and one run through it.

Fig. 6.3the joke graph and one runflow
The joke graph and one run The top is the graph from the capture: __start__ to plan, then three Send arrows from plan to three write_joke tasks for cats, dogs, owls in one step, then plain edges to pick. pick returns a Command with best set to "a joke about cats" and goto publish, so publish runs and then __end__. The retry node, the other target of pick, did not run. The bottom is a table of what each node wrote to the state in each of the 4 steps, read from the updates stream: plan wrote subjects, each write_joke wrote one joke, operator.add joined the three into a list of 3, and pick wrote best. The log key ends with 6 entries. __start__ plan step 1 write_joke cats write_joke dogs write_joke owls Send x 3 pick Command publish ran retry did not run goto publish __end__ WHAT EACH STEP WROTE TO THE STATE step 1 step 2 step 3 step 4 subjects cats, dogs, owls jokes a joke about cats a joke about dogs a joke about owls operator.add: 3 items one list in the state best a joke about cats log plan write_joke(cats) write_joke(dogs) write_joke(owls) pick -> publish publish Three writes to jokes in one step joined into one list. The log key ends with 6 entries. Each teal cell is one value a node returned, read from the updates stream.
Send starts three write_joke tasks in one step, and Command from pick updates best and goes to publish, so retry never runs. Read from __start__ at the left to __end__ at the right. Solid arrows are plain edges, and dashed amber arrows are routes chosen at run time. The grey retry node did not run. The table below shows what each step wrote to the state.

Plain and conditional edges

Plain edge: an edge from one node to another that LangGraph follows every time the first node finishes.

Conditional edge: an edge with a routing function. After the source node runs, the function reads the state and returns the next node, a list of nodes, or END.

The third argument of add_conditional_edges lists the nodes that the function can return. LangGraph uses that list to draw the graph. Section 1.3 showed the conditional edges of an agent: after model, the tool calls in the last message choose tools or __end__.

Send: one task for each item

Send: a value that names a node and the input of one run of it. A routing function that returns a list of them starts one task for each item, in the same step.

fan_out is the routing function after plan. It reads subjects and returns one Send for each subject. Each write_joke task gets its own small dict as input, and it does not see the full state:

pythonthe routing function and the node it startsFull log
    def fan_out(state):
        return [Send("write_joke", {"subject": s}) for s in state["subjects"]]

    def write_joke(arg):
        return {"jokes": [f"a joke about {arg['subject']}"], "log": [f"write_joke({arg['subject']})"]}

The updates stream yields one chunk for each task. The three write_joke chunks come between the chunk of plan and the chunk of pick:

jsonthe three write_joke chunksFull log
  "write_joke": {
    "jokes": [
      "a joke about cats"
    ],
…
  "write_joke": {
    "jokes": [
      "a joke about dogs"
    ],
…
  "write_joke": {
    "jokes": [
      "a joke about owls"
    ],
Three of the six chunks of the updates stream, cut to the jokes key.

The three tasks write jokes in the same step, so the key needs the reducer of section 6.1. The docs page for Send and Command calls this pattern map-reduce.

Import Send from langgraph.types. An import from langgraph.constants still works at the pin, and it warns that the path is deprecated.

Command: update and route in one return

Command: a value that a node returns to update the state and name the next node in one step. Its fields are update, goto, graph, and resume.

pick chooses the first joke in sort order. It returns a Command that sets best, adds a line to log, and goes to publish or retry:

pythona node that returns a CommandFull log
    def pick(state) -> Command[Literal["publish", "retry"]]:
        best = sorted(state["jokes"])[0]
        target = "publish" if "cats" in best else "retry"
        return Command(update={"best": best, "log": [f"pick -> {target}"]}, goto=target)

The Literal in the return type names the two possible targets. LangGraph reads it to draw the two dotted edges out of pick, and the docs say that the annotation is required for that. The run went to publish, and retry did not run. The last two chunks of the stream show it:

jsonthe last two chunks of the runFull log
{
  "pick": {
    "best": "a joke about cats",
    "log": [
      "pick -> publish"
    ]
  }
}

{
  "publish": {
    "log": [
      "publish"
    ]
  }
}

Use a conditional edge when the route depends only on the state. Use Command when the node that computes the update also knows the route, as pick does.

Command has two more uses. With resume, it is the input that answers an interrupt, and section 6.4 shows it. With graph=Command.PARENT, a node inside a subgraph routes to a node of the parent graph. The kit does not run Command.PARENT yet. A capture of it comes in the next edition, with the other open items of section 8.8.

LangChain (Python): langchain, langchain-core, langgraph, deepagents, langsmith 1.5.0 · c2f4036 · 2026-11-11 · Edition 2026.11