Subgraphs and Multi-Agent OrchestrationCommand.PARENT handoffs, and building a mini-wave
No narration yet
Module 7, Lesson 225 min

Command.PARENT handoffs, and building a mini-wave

A node inside a subgraph can route in the parent graph by targeting Command.PARENT.

A reviewer subgraph routing the parent
import { Command } from "@langchain/langgraph";

const reviewNode = (state) => {
  if (state.verdict === "reject") {
    return new Command({
      update: { feedback: state.notes },
      goto: "implement",          // a node in the PARENT graph
      graph: Command.PARENT,
    });
  }
  return new Command({ goto: "done", graph: Command.PARENT });
};

That is how a rejection loops back to the implementer: the reviewer subgraph reaches up and routes the parent. Without Command.PARENT, goto only sees nodes inside the same subgraph.

Practice

Try it yourself

Quiz

Why Command.PARENT is required for the loop-back

Why does the reviewer subgraph need Command.PARENT to loop back to the implementer, rather than a plain goto: "implement"?

Recall

A bug subgraph isolation prevents

Answer from the mini-wave rather than in the abstract. A named safety property is only worth anything if you can name what it stops.

Name a specific bug that subgraph state isolation prevents.

Do

Build the mini-wave: supervisor, implementer, reviewer

Build a hand-rolled supervisor dispatching an implementer subgraph to a reviewer subgraph with a bounded fix loop.

Tick every step to confirm you did it.

Check

Reject loop is bounded and state stays isolated

Confirm the fix loop and isolation properties.

You should see

A reviewer rejection loops back to the implementer exactly once before escalating to a human, Command.PARENT handoffs are visible in the transcript, and the implementer's internal state keys never appear in the reviewer's state.