Public mirror of langchain-ai/langgraph for SSH-based source code analysis
Find a file
Sera f96105368f
fix(langgraph): give add_messages writes and StateGraph input message ids before they are saved (#9772)
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
2026-11-24 15:11:23 -05:00
.github fix(cli): remove discontinued local debugger image (#8543) 2026-11-11 20:43:53 -05:00
docs docs: publish the generated llms.txt instead of a hand-written copy (#8922) 2026-09-14 15:45:19 -04:00
examples feat: add delta-channel-dump recovery script as examples to dump from Postgres for deltaChannel rollback (#8109) 2026-06-17 10:50:30 -07:00
libs fix(langgraph): give add_messages writes and StateGraph input message ids before they are saved (#9772) 2026-11-24 15:11:23 -05:00
.gitignore fix(checkpoint): widen Store put value type to Mapping[str, Any] (#8617) 2026-08-28 08:05:04 -05:00
.markdownlint.json docs: restyle README.md to match langchain repo layout (#7187) 2026-03-15 23:58:21 -04:00
AGENTS.md docs: add "Direction: LangGraph is a runtime" section to AGENTS.md (#9439) 2026-10-26 15:56:56 +02:00
LICENSE libs: add cli, sdk-py, sdk-js and move core langgraph 2024-06-17 20:37:25 -04:00
Makefile ci: add automated uv lock --upgrade workflow (#5307) 2025-07-02 10:10:01 -04:00
README.md docs: update README.md (#7710) 2026-05-05 17:58:37 +02:00

Low-level orchestration framework for building stateful agents.

PyPI - License PyPI - Downloads Version Twitter / X

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

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.