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
    Pythonlanggraphgraphuiui_message_reducer
    Function●Since v0.3

    ui_message_reducer

    Merge two lists of UI messages, supporting removing UI messages.

    This function combines two lists of UI messages, handling both regular UI messages and remove-ui messages. When a remove-ui message is encountered, it removes any UI message with the matching ID from the current state.

    Copy
    ui_message_reducer(
      left: list[AnyUIMessage] | AnyUIMessage,
      right: list[AnyUIMessage] | AnyUIMessage
    ) -> list[AnyUIMessage]

    Example:

    messages = ui_message_reducer(
        [{"type": "ui", "id": "1", "name": "Chat", "props": {}}],
        {"type": "remove-ui", "id": "1"},
    )

    Parameters

    NameTypeDescription
    left*list[AnyUIMessage] | AnyUIMessage

    First list of UI messages or single UI message.

    right*list[AnyUIMessage] | AnyUIMessage

    Second list of UI messages or single UI message.

    View source on GitHub