LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
  • Stream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemote
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServerStream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraphindexSend
Classā—Since v0.3

Send

Copy
class Send

Used in Docs

  • Build a multi-source knowledge base with routing
  • Graph API overview
  • Use the graph API
  • Workflows and agents

Constructors

Properties

Methods

View source on GitHub

Example

constructor
constructor
property
args: Args
property
lg_name: string
property
node: Node
method
toJSON→ __type

A message or packet to send to a specific node in the graph.

The Send class is used within a StateGraph's conditional edges to dynamically invoke a node with a custom state at the next step.

Importantly, the sent state can differ from the core graph's state, allowing for flexible and dynamic workflow management.

One such example is a "map-reduce" workflow where your graph invokes the same node multiple times in parallel with different states, before aggregating the results back into the main graph's state.

Copy
import { Annotation, Send, StateGraph } from "@langchain/langgraph";

const ChainState = Annotation.Root({
  subjects: Annotation<string[]>,
  jokes: Annotation<string[]>({
    reducer: (a, b) => a.concat(b),
  }),
});

const continueToJokes = async (state: typeof ChainState.State) => {
  return state.subjects.map((subject) => {
    return new Send("generate_joke", { subjects: [subject] });
  });
};

const graph = new StateGraph(ChainState)
  .addNode("generate_joke", (state) => ({
    jokes: [`Joke about ${state.subjects}`],
  }))
  .addConditionalEdges("__start__", continueToJokes)
  .addEdge("generate_joke", "__end__")
  .compile();

const res = await graph.invoke({ subjects: ["cats", "dogs"] });
console.log(res);

// Invoking with two subjects results in a generated joke for each
// { subjects: ["cats", "dogs"], jokes: [`Joke about cats`, `Joke about dogs`] }