Change the `id` field from `default=None` to
`default_factory=lambda: str(uuid.uuid4())` so every message receives a
stable, unique id from birth rather than being id-less until a reducer
or `add_messages` assigns one.
## Motivation
LangGraph's `DeltaChannel` stores pending writes (the raw message
objects) as serialized blobs **before** `update()` is called. Any id
assigned inside the reducer (e.g. a random UUID in
`_messages_delta_reducer`) only exists in the in-memory channel state;
it never reaches the stored write. On checkpoint replay the same
id-less message gets a fresh random UUID, so an eviction/update Command
that references the runtime-assigned id cannot match the replayed
message — both the original and the update land in state as separate
messages.
The root fix is here: if messages already carry a stable id when they
are first constructed (before any serialization boundary), the stored
write and any subsequent Command that updates that message by id will
always agree on the id, making `DeltaChannel` replay fully correct.
## Breaking change
`HumanMessage(content="x") == HumanMessage(content="x")` is now
`False` because auto-assigned UUIDs differ. Previously both had
`id=None` and compared equal. Code that relies on content-based message
equality must be updated (compare `.content` / `.model_dump(exclude={'id'})`
directly, or set an explicit shared `id`).
129 unit tests in langchain-core fail; all are due to this equality
change. Options the team can consider:
- Fix tests to use explicit ids or field-level comparisons
- Override `BaseMessage.__eq__` to exclude `id` (preserves backward
compat for equality; DeltaChannel dedup uses id-keyed dict, not ==)
- Introduce a `__eq__` that only uses `id` when both sides have a
non-None id, otherwise falls back to content comparison
Explicitly passing `id=None` still produces a message with `id=None`
(default_factory is not invoked for explicitly-supplied values).
🦜🍎️ LangChain Core
Looking for the JS/TS version? Check out LangChain.js.
To help you ship LangChain apps to production faster, check out LangSmith. LangSmith is a unified developer platform for building, testing, and monitoring LLM applications.
Quick Install
pip install langchain-core
🤔 What is this?
LangChain Core contains the base abstractions that power the LangChain ecosystem.
These abstractions are designed to be as modular and simple as possible.
The benefit of having these abstractions is that any provider can implement the required interface and then easily be used in the rest of the LangChain ecosystem.
⛰️ Why build on top of LangChain Core?
The LangChain ecosystem is built on top of langchain-core. Some of the benefits:
- Modularity: We've designed Core around abstractions that are independent of each other, and not tied to any specific model provider.
- Stability: We are committed to a stable versioning scheme, and will communicate any breaking changes with advance notice and version bumps.
- Battle-tested: Core components have the largest install base in the LLM ecosystem, and are used in production by many companies.
📖 Documentation
For full documentation, see the API reference. For conceptual guides, tutorials, and examples on using LangChain, see the LangChain Docs. You can also chat with the docs using Chat LangChain.
📕 Releases & Versioning
See our Releases and Versioning policies.
💁 Contributing
As an open-source project in a rapidly developing field, we are extremely open to contributions, whether it be in the form of a new feature, improved infrastructure, or better documentation.
For detailed information on how to contribute, see the Contributing Guide.