{ "cells": [ { "cell_type": "markdown", "id": "90616e9e", "metadata": {}, "source": [ "# How to view and update past graph state\n", "\n", "Once you start [checkpointing](./persistence.ipynb) your graphs, you can easily\n", "**get** or **update** the state of the agent at any point in time. This permits\n", "a few things:\n", "\n", "1. You can surface a state during an interrupt to a user to let them accept an\n", " action.\n", "2. You can **rewind** the graph to reproduce or avoid issues.\n", "3. You can **modify** the state to embed your agent into a larger system, or to\n", " let the user better control its actions.\n", "\n", "The key methods used for this functionality are:\n", "\n", "- [getState](/langgraphjs/reference/classes/langgraph_pregel.Pregel.html#getState):\n", " fetch the values from the target config\n", "- [updateState](/langgraphjs/reference/classes/langgraph_pregel.Pregel.html#updateState):\n", " apply the given values to the target state\n", "\n", "**Note:** this requires passing in a checkpointer.\n", "\n", "\n", "\n", "This works for\n", "[StateGraph](/langgraphjs/reference/classes/langgraph.StateGraph.html)\n", "and all its subclasses, such as\n", "[MessageGraph](/langgraphjs/reference/classes/langgraph.MessageGraph.html).\n", "\n", "Below is an example.\n", "\n", "
Note
\n", "\n",
" In this how-to, we will create our agent from scratch to be transparent (but verbose). You can accomplish similar functionality using the createReactAgent(model, tools=tool, checkpointer=checkpointer)
(API doc) constructor. This may be more appropriate if you are used to LangChain's AgentExecutor class.\n",
"
Note
\n", "\n", " These model requirements are not general requirements for using LangGraph - they are just requirements for this one example.\n", "
\n", "