- Understand reasoning: Analyze the steps that led to a successful result.
- Debug mistakes: Identify where and why errors occurred.
- Explore alternatives: Test different paths to uncover better solutions.
- Run the graph with initial inputs using
invokeorstreammethods. - Identify a checkpoint in an existing thread: Use the
getStateHistorymethod to retrieve the execution history for a specificthread_idand locate the desiredcheckpoint_id. Alternatively, set a breakpoint before the node(s) where you want execution to pause. You can then find the most recent checkpoint recorded up to that breakpoint. - Update the graph state (optional): Use the
updateStatemethod to modify the graph’s state at the checkpoint and resume execution from alternative state. - Resume execution from the checkpoint: Use the
invokeorstreammethods with an input ofnulland a configuration containing the appropriatethread_idandcheckpoint_id.
In a workflow
This example builds a simple LangGraph workflow that generates a joke topic and writes a joke using an LLM. It demonstrates how to run the graph, retrieve past execution checkpoints, optionally modify the state, and resume execution from a chosen checkpoint to explore alternate outcomes.Setup
To build this workflow in this example you need to set up the Anthropic LLM and install the required dependencies:- Install dependencies
- Initialize the LLM:
- Implement the workflow The implementation of the workflow is a simple graph with two nodes, one for generating a joke topic, another for writing the joke itself and a state to storing the intermediate values.
1. Run the graph
To start the workflow,invoke is called without any inputs. Note the thread_id to track this execution and retrieve its checkpoints later.
2. Identify a checkpoint
To continue from a previous point in the graphs run, useget_state_history to retrieve all the states and select the one where you want to resume execution.
3. Update the state (optional)
updateState will create a new checkpoint. The new checkpoint will be associated with the same thread, but a new checkpoint ID.
4. Resume execution from the checkpoint
For resumings execution from the selected checkpoint, callinvoke with the config that points to the new checkpoint.