Servers reading checkpoints key messages by id, so messages need ids before saving. On `add_messages` channels and `StateGraph` input only the reducer assigns them: `updates` shows `id=None`, `Overwrite` saves none, and replays mint new ones. Fixes #9757. ## Changes - `add_messages` writes, `Overwrite` and `format=` partials included, get ids before saving; only `None` counts as missing. - `StateGraph` input gets ids by channel, saved with the input checkpoint (uuid4, not run-derived). Input is copied; only message fields change. - DeltaChannels: `id=""` message objects get ids; in an `Overwrite`, a pair stays one message, and on `_messages_delta_reducer` channels a lone one becomes a list. ## Reviewer notes - Message dicts in `updates`, history and saved writes gain an `"id"`; two langgraph-api exact-match tests break. - Strings, `(role, content)` tuples and JSON pair lists can't carry an id, so become messages there, and in an `Overwrite`'s state. - JS needs the same change; langgraphjs#3412 covers input. ## Where message ids are set Before: the reducer mints the id after the write is saved. ```mermaid sequenceDiagram participant W as Node return or client input participant C as Checkpoint (saved write, input) participant S as updates and history participant R as add_messages W->>C: role/content dict, no id W->>S: no id C->>R: apply saved write R-->>C: state gets id A Note over C,R: Replay, fork or resume applies the write again: id B ``` After: the id is set before the write is saved. ```mermaid sequenceDiagram participant W as Node return or client input participant E as ensure_message_ids participant C as Checkpoint (saved write, input) participant S as updates and history participant R as add_messages W->>E: role/content dict E->>C: same dict + id A E->>S: same dict + id A C->>R: apply saved write R-->>C: state keeps id A Note over C,R: Replay, fork or resume applies the write again: still id A ``` | Written | Saved and streamed as | |---|---| | Message dict | Same dict, plus `"id"` | | Message object | Same object, `id` set | | String, `(role, content)`, `["user", "hi"]` | Message object | | `Overwrite` in any form | Same form, items get ids | ## Test Plan - [x] `updates` ids equal saved ids for dict, tuple and string node outputs - [x] `Overwrite` ids stable across `get_state` and a fork - [x] Replay from the first checkpoint keeps input ids (sync, async, exit; dict, Pydantic, dataclass and root-channel input) - [x] `add_messages` keeps `id=""`; a DeltaChannel message with `id=""` gets an id - [x] Dict input keeps its keys and order; dataclass input (frozen too) isn't re-initialized - [x] Saved ids match applied ids after resume, `Command.update`, `update_state` and async runs, on every checkpointer - [x] In an `Overwrite`, a pair stays one message and a lone message survives the next write (#9757 repro) - [x] langchain v1 and deepagents unit tests unchanged |
||
|---|---|---|
| .github | ||
| docs | ||
| examples | ||
| libs | ||
| .gitignore | ||
| .markdownlint.json | ||
| AGENTS.md | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
Low-level orchestration framework for building stateful agents.
Trusted by companies shaping the future of agents – including Klarna, Replit, Elastic, and more – LangGraph is a low-level orchestration framework for building, managing, and deploying long-running, stateful agents.
pip install -U langgraph
Tip
If you're looking to quickly build agents, check out Deep Agents — a higher-level package built on LangGraph for agents that can plan, use subagents, and leverage file systems for complex tasks.
For an equivalent JS/TS library, check out LangGraph.js and the JS docs.
Why use LangGraph?
LangGraph provides low-level supporting infrastructure for any long-running, stateful workflow or agent:
- Durable execution — Build agents that persist through failures and can run for extended periods, automatically resuming from exactly where they left off.
- Human-in-the-loop — Seamlessly incorporate human oversight by inspecting and modifying agent state at any point during execution.
- Comprehensive memory — Create truly stateful agents with both short-term working memory for ongoing reasoning and long-term persistent memory across sessions.
- Debugging with LangSmith — Gain deep visibility into complex agent behavior with visualization tools that trace execution paths, capture state transitions, and provide detailed runtime metrics.
- Production-ready deployment — Deploy sophisticated agent systems confidently with scalable infrastructure designed to handle the unique challenges of stateful, long-running workflows.
Tip
For developing, debugging, and deploying AI agents and LLM applications, see LangSmith.
LangGraph ecosystem
While LangGraph can be used standalone, it also integrates seamlessly with any LangChain product, giving developers a full suite of tools for building agents.
To improve your LLM application development, pair LangGraph with:
- Deep Agents – Build agents that can plan, use subagents, and leverage file systems for complex tasks.
- LangChain – Provides integrations and composable components to streamline LLM application development.
- LangSmith – Helpful for agent evals and observability. Debug poor-performing LLM app runs, evaluate agent trajectories, gain visibility in production, and improve performance over time.
- LangSmith Deployment – Deploy and scale agents effortlessly with a purpose-built deployment platform for long-running, stateful workflows. Discover, reuse, configure, and share agents across teams – and iterate quickly with visual prototyping in LangSmith Studio.
Documentation
- docs.langchain.com – Comprehensive documentation, including conceptual overviews and guides
- reference.langchain.com/python/langgraph – API reference docs for LangGraph packages
- LangGraph Quickstart – Get started building with LangGraph
- Chat LangChain – Chat with the LangChain documentation and get answers to your questions
Discussions: Visit the LangChain Forum to connect with the community and share all of your technical questions, ideas, and feedback.
Additional resources
- Guides – Quick, actionable code snippets for topics such as streaming, adding memory & persistence, and design patterns (e.g. branching, subgraphs, etc.).
- LangChain Academy – Learn the basics of LangGraph in our free, structured course.
- Case studies – Hear how industry leaders use LangGraph to ship AI applications at scale.
- Contributing Guide – Learn how to contribute to LangChain projects and find good first issues.
- Code of Conduct – Our community guidelines and standards for participation.
Acknowledgements
LangGraph is inspired by Pregel and Apache Beam. The public interface draws inspiration from NetworkX. LangGraph is built by LangChain Inc, the creators of LangChain, but can be used without LangChain.