LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Graphs
    • Functional API
    • Pregel
    • Checkpointing
    • Storage
    • Caching
    • Types
    • Runtime
    • Config
    • Errors
    • Constants
    • Channels
    • Agents
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewGraphsFunctional APIPregelCheckpointingStorageCachingTypesRuntimeConfigErrorsConstantsChannelsAgents
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    PythonlanggraphtypesSend
    Class●Since v0.2

    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
    Send(
        self,
        ,
        node: str,
        arg: Any,
    )
    from typing import Annotated
    from langgraph.types import Send
    from langgraph.graph import END, START
    from langgraph.graph import StateGraph
    import operator
    
    class OverallState(TypedDict):
        subjects: list[str]
        jokes: Annotated[list[str], operator.add]
    
    def continue_to_jokes(state: OverallState):
        return [Send("generate_joke", {"subject": s}) for s in state["subjects"]]
    
    builder = StateGraph(OverallState)
    builder.add_node("generate_joke", lambda state: {"jokes": [f"Joke about {state['subject']}"]})
    builder.add_conditional_edges(START, continue_to_jokes)
    builder.add_edge("generate_joke", END)
    graph = builder.compile()
    
    # Invoking with two subjects results in a generated joke for each
    graph.invoke({"subjects": ["cats", "dogs"]})
    # {'subjects': ['cats', 'dogs'], 'jokes': ['Joke about cats', 'Joke about dogs']}

    Used in Docs

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

    Parameters

    NameTypeDescription
    node*str

    The name of the target node to send the message to.

    arg*Any

    The state or message to send to the target node.

    Constructors

    constructor
    __init__
    NameType
    nodestr
    argAny

    Attributes

    attribute
    node: str
    attribute
    arg: Any
    View source on GitHub