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

    Chat LangChain

    What can I help with?

    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.6

    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, and tool-call chunk blocks a single tool-call-delta with their full args. 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.