Video summary

Persistence in LangGraph | Time Travel in LangGraph | CampusX

Main summary

Key takeaways

Educational

Summary

The video explains persistence in LangGraph: the ability to save and later restore a workflow’s state. The presenter begins with two LangGraph fundamentals:

  • Graphs represent a goal as tasks (nodes) and the order in which they run (edges).
  • State is a dictionary of data that nodes can read and update, such as the messages in a chatbot conversation.

Without persistence, state normally disappears when a workflow finishes. Persistence allows LangGraph to retain state—including intermediate state—so a workflow can be inspected, resumed, or replayed later.

Checkpoints and checkpointers

LangGraph implements persistence through a checkpointer, which records state at checkpoints, generally at each graph superstep. A superstep is a stage of execution in which one or more nodes run, potentially in parallel. This allows LangGraph to save more than just the final result.

The presenter illustrates this with a state list: successive nodes add values, and the accumulated list is saved at each checkpoint.

Threads

A thread ID associates checkpoints with a particular workflow execution or conversation. When a workflow runs with persistence enabled, the same thread ID can later be used to retrieve its state and history. Different thread IDs keep separate executions or chatbot conversations distinct.

Coding example

The main example is a sequential workflow that generates a joke about a topic and then explains it:

  1. Define a state containing the topic, joke, and explanation.
  2. Create two nodes: one generates the joke, and the other explains it.
  3. Connect the nodes in sequence.
  4. Create a checkpointer and pass it when compiling the graph.
  5. Invoke the graph with an initial state and a configuration containing a thread ID.
  6. Retrieve the final state with get_state or checkpoint history with get_state_history.

The demo uses an in-memory checkpointer, MemorySaver. It is useful for learning and demonstrations, but its data disappears when the program ends. Production applications should use an appropriate persistent checkpointer, such as a database-backed option.

Running the workflow with different thread IDs keeps each run’s final and intermediate states separate—for example, a pizza-joke run and a pasta-joke run.

Benefits of persistence

  1. Short-term chatbot memory Saving messages lets a user resume a previous conversation by loading the messages associated with its thread ID.

  2. Fault tolerance If execution is interrupted, LangGraph can resume from saved progress rather than restarting from the beginning. In the demo, the presenter interrupts a workflow during a delayed second step, then resumes it by invoking the graph with None and the same thread ID. The workflow continues from the unfinished step.

  3. Human in the loop (HITL) A workflow can pause after generating a result, such as a LinkedIn post, while waiting for a person to approve it. Persistence records where execution paused so it can resume when the person responds. Unlike a crash, this pause is intentional.

  4. Time travel A user can inspect an earlier checkpoint and rerun the workflow from that point. This is useful for debugging or exploring alternate outcomes. Because LLM output is probabilistic, replaying from a checkpoint may produce a different result.

Time-travel procedure

  1. Retrieve the thread’s checkpoint history.
  2. Find the checkpoint from which execution should continue and copy its checkpoint ID.
  3. Use get_state with the thread ID and checkpoint ID to inspect that checkpoint’s state.
  4. Invoke the graph with None, using the same thread ID and selected checkpoint ID, to replay the subsequent steps.
  5. To explore a changed input, use update_state on a chosen checkpoint—for example, change the topic from pizza to samosa—then invoke from the new checkpoint. Invoking from the original checkpoint would replay using its original state.

The resulting history may contain multiple branches: the original execution, replays, and runs based on updated state.

Speakers and sources featured

  • Nitesh (Nitesh Singh) — presenter and instructor.
  • LangGraph — the framework and concepts discussed.
  • Illustrative references — chatbot conversations such as ChatGPT, a LinkedIn-post workflow, and Google Colab as the environment used for the interruption demo.

Rate this summary

Your feedback will help improve summaries.

Improve this summary

Reprocess with a stronger model when the summary feels incomplete or inaccurate.

Pro

Translate summary in another language

Pro

Ask questions to this video

Chat for follow-up questions, clarifications, and source-backed answers.

Coming soon

Share this summary

Original video