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
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    โŒ˜I

    Chat LangChain

    What can I help with?

    Enter to sendยทShift+Enter new line

    Menu

    OverviewGraphsFunctional APIPregelCheckpointingStorageCachingTypesRuntimeConfigErrorsConstantsChannelsAgents
    LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraphpregel_messagesensure_message_ids
    Functionโ—Since v1.2

    ensure_message_ids

    Copy
    ensure_message_ids(
      channels: Mapping[str, Any],
      writes: Sequence[tuple[str
    View source on GitHub
    ,
    Any
    ]
    ]
    )
    ->
    None

    Give the messages written to DeltaChannels stable ids.

    A DeltaChannel replays its saved writes on every read, and its reducer may not assign missing ids (_messages_delta_reducer doesn't), so a message saved without an id comes back without one, or with a new one on every read, and nothing can target it by id, for example RemoveMessage.

    In a channel whose reducer is _messages_delta_reducer, every message-like it accepts (a message, a dict, a string, a (role, content) tuple; alone, in a list or in an Overwrite) becomes a message with an id. Other DeltaChannels may hold other data, so there only message objects get ids, plus message dicts outside an Overwrite: one in a list becomes a message. Anything that can't become a message is left as it is, so it fails where it always has: a message dict in a list raises here, anything else when the reducer reads it. An empty id counts as missing.

    A write that changes is replaced in writes: lists and dicts the caller passed in are never changed, only the ids of message objects.