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 Checkpoint
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    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 Checkpoint
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraphpregel_messagesStreamMessagesHandlerV2on_stream_event
    Method●Since v1.1

    on_stream_event

    Copy
    on_stream_event(
      self,
      event: dict[str, Any],
      *,
      run_id: UUID,
    View source on GitHub
    parent_run_id
    :
    UUID
    |
    None
    =
    None
    ,
    tags
    :
    list
    [
    str
    ]
    |
    None
    =
    None
    ,
    **
    kwargs
    :
    Any
    =
    {
    }
    )
    ->
    Any

    Forward a protocol event from stream_v2 as a messages stream part.

    Fires once per MessagesData event (message-start, per-block content-block-*, message-finish). The transformer layer correlates events back to a single ChatModelStream via metadata["run_id"] — attached here so the v1 stream_mode="messages" output (which emits (AIMessageChunk, metadata) via on_llm_new_token) keeps its original metadata shape.

    Lives on the v2 handler rather than the v1 base: content-block events are a v2-only concept, and forwarding them only when the v2 handler is attached keeps the message channel's shape predictable for v1 callers.