LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
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
LangGraph SDK
ClientAuthReactLoggingReact UiServer
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/langgraphwebSend
Class●Since v0.3

Send

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
class Send

Used in Docs

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

Example

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`] }

Constructors

constructor
constructor

Properties

property
args: Args
property
lg_name: string
property
node: Node

Methods

method
toJSON→ __type
View source on GitHub