Dynamic fan-out
Map each item in a collection to a separate invocation of the same node.
AI Agents · Const
Send routes execution to a named graph node with custom input state. Returning multiple Send objects from conditional edges enables dynamic fan-out and map-reduce workflows.
Send is a routing packet used from conditional edges to invoke a named graph node with custom input state. The input can differ from the graph’s main state, enabling dynamic fan-out patterns such as parallel map-reduce workflows.
new Send<Node extends string = string, Args = any>(node: Node, args: Args)| Name | Type | Description |
|---|---|---|
node | Node extends string | Name of the node to invoke. |
args | Args | Custom state or arguments passed to the node invocation. |
A Send instance representing a message or packet addressed to a graph node.
import { Annotation, Send, StateGraph } from "@langchain/langgraph";
const State = Annotation.Root({
subjects: Annotation<string[]>(),
jokes: Annotation<string[]>({ reducer: (a, b) => a.concat(b) }),
});
const fanOut = (state: typeof State.State) =>
state.subjects.map(
(subject) => new Send("generate_joke", { subjects: [subject] }),
);
const graph = new StateGraph(State)
.addNode("generate_joke", (state) => ({
jokes: [`Joke about ${state.subjects}`],
}))
.addConditionalEdges("__start__", fanOut)
.addEdge("generate_joke", "__end__")
.compile();
const result = await graph.invoke({ subjects: ["cats", "dogs"] });
console.log(result);Returns one Send object per subject so the same node runs with separate input states.
Map each item in a collection to a separate invocation of the same node.
Run repeated node executions concurrently and collect their outputs with a reducer.
Pass a node a state shape tailored to a branch rather than the graph’s central state.
StateGraphAnnotationSendInterface