METADATA 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. Metadata-Version: 2.4
  2. Name: langgraph-checkpoint
  3. Version: 3.0.1
  4. Summary: Library with base interfaces for LangGraph checkpoint savers.
  5. Project-URL: Repository, https://www.github.com/langchain-ai/langgraph
  6. License-Expression: MIT
  7. License-File: LICENSE
  8. Requires-Python: >=3.10
  9. Requires-Dist: langchain-core>=0.2.38
  10. Requires-Dist: ormsgpack>=1.12.0
  11. Description-Content-Type: text/markdown
  12. # LangGraph Checkpoint
  13. This library defines the base interface for LangGraph checkpointers. Checkpointers provide a persistence layer for LangGraph. They allow you to interact with and manage the graph's state. When you use a graph with a checkpointer, the checkpointer saves a _checkpoint_ of the graph state at every superstep, enabling several powerful capabilities like human-in-the-loop, "memory" between interactions and more.
  14. ## Key concepts
  15. ### Checkpoint
  16. Checkpoint is a snapshot of the graph state at a given point in time. Checkpoint tuple refers to an object containing checkpoint and the associated config, metadata and pending writes.
  17. ### Thread
  18. Threads enable the checkpointing of multiple different runs, making them essential for multi-tenant chat applications and other scenarios where maintaining separate states is necessary. A thread is a unique ID assigned to a series of checkpoints saved by a checkpointer. When using a checkpointer, you must specify a `thread_id` and optionally `checkpoint_id` when running the graph.
  19. - `thread_id` is simply the ID of a thread. This is always required.
  20. - `checkpoint_id` can optionally be passed. This identifier refers to a specific checkpoint within a thread. This can be used to kick off a run of a graph from some point halfway through a thread.
  21. You must pass these when invoking the graph as part of the configurable part of the config, e.g.
  22. ```python
  23. {"configurable": {"thread_id": "1"}} # valid config
  24. {"configurable": {"thread_id": "1", "checkpoint_id": "0c62ca34-ac19-445d-bbb0-5b4984975b2a"}} # also valid config
  25. ```
  26. ### Serde
  27. `langgraph_checkpoint` also defines protocol for serialization/deserialization (serde) and provides an default implementation (`langgraph.checkpoint.serde.jsonplus.JsonPlusSerializer`) that handles a wide variety of types, including LangChain and LangGraph primitives, datetimes, enums and more.
  28. ### Pending writes
  29. When a graph node fails mid-execution at a given superstep, LangGraph stores pending checkpoint writes from any other nodes that completed successfully at that superstep, so that whenever we resume graph execution from that superstep we don't re-run the successful nodes.
  30. ## Interface
  31. Each checkpointer should conform to `langgraph.checkpoint.base.BaseCheckpointSaver` interface and must implement the following methods:
  32. - `.put` - Store a checkpoint with its configuration and metadata.
  33. - `.put_writes` - Store intermediate writes linked to a checkpoint (i.e. pending writes).
  34. - `.get_tuple` - Fetch a checkpoint tuple using for a given configuration (`thread_id` and `checkpoint_id`).
  35. - `.list` - List checkpoints that match a given configuration and filter criteria.
  36. - `.delete_thread()` - Delete all checkpoints and writes associated with a thread.
  37. - `.get_next_version()` - Generate the next version ID for a channel.
  38. If the checkpointer will be used with asynchronous graph execution (i.e. executing the graph via `.ainvoke`, `.astream`, `.abatch`), checkpointer must implement asynchronous versions of the above methods (`.aput`, `.aput_writes`, `.aget_tuple`, `.alist`). Similarly, the checkpointer must implement `.adelete_thread()` if asynchronous thread cleanup is desired. The base class provides a default implementation of `.get_next_version()` that generates an integer sequence starting from 1, but this method should be overridden for custom versioning schemes.
  39. ## Usage
  40. ```python
  41. from langgraph.checkpoint.memory import InMemorySaver
  42. write_config = {"configurable": {"thread_id": "1", "checkpoint_ns": ""}}
  43. read_config = {"configurable": {"thread_id": "1"}}
  44. checkpointer = InMemorySaver()
  45. checkpoint = {
  46. "v": 4,
  47. "ts": "2024-07-31T20:14:19.804150+00:00",
  48. "id": "1ef4f797-8335-6428-8001-8a1503f9b875",
  49. "channel_values": {
  50. "my_key": "meow",
  51. "node": "node"
  52. },
  53. "channel_versions": {
  54. "__start__": 2,
  55. "my_key": 3,
  56. "start:node": 3,
  57. "node": 3
  58. },
  59. "versions_seen": {
  60. "__input__": {},
  61. "__start__": {
  62. "__start__": 1
  63. },
  64. "node": {
  65. "start:node": 2
  66. }
  67. },
  68. }
  69. # store checkpoint
  70. checkpointer.put(write_config, checkpoint, {}, {})
  71. # load checkpoint
  72. checkpointer.get(read_config)
  73. # list checkpoints
  74. list(checkpointer.list(read_config))
  75. ```