LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-corelanguage_models_compat_bridgemessage_to_events
    Functionā—Since v1.3

    message_to_events

    Copy
    message_to_events(
      msg: BaseMessage,
      *,
      message_id: str | None = None
    ) -> Iterator
    View source on GitHub
    [
    MessagesData
    ]

    Parameters

    NameTypeDescription
    msg*BaseMessage
    message_idstr | None
    Default:None

    Replay a finalized message as a synthetic event lifecycle.

    For a message returned whole (from a graph node, checkpoint, or cache), produce the same message-start / per-block / message-finish event stream a live call would produce. Consumers downstream see a uniform event shape regardless of source.

    Text and reasoning blocks emit a single content-block-delta with the full accumulated content. Already-finalized blocks (tool_call, server_tool_call, image, etc.) skip the delta and rely on the content-block-finish event alone.

    The finalized message — typically an AIMessage.

    Optional stable message ID; falls back to msg.id.