{ "cells": [ { "cell_type": "markdown", "id": "51466c8d-8ce4-4b3d-be4e-18fdbeda5f53", "metadata": {}, "source": [ "# How to use Postgres checkpointer for persistence\n", "\n", "When creating LangGraph agents, you can also set them up so that they persist their state. This allows you to do things like interact with an agent multiple times and have it remember previous interactions.\n", "\n", "This example shows how to use `Postgres` as the backend for persisting checkpoint state using [`langgraph-checkpoint-postgres`](https://github.com/langchain-ai/langgraph/tree/main/libs/checkpoint-postgres) library.\n", "\n", "To start a Postgres database to work with you can do the following:\n", "\n", "```\n", "$ cd libs/langgraph\n", "$ make start-postgres" ] }, { "cell_type": "markdown", "id": "456fa19c-93a5-4750-a410-f2d810b964ad", "metadata": {}, "source": [ "## Setup\n", "\n", "First, let's install the required packages and set our API keys" ] }, { "cell_type": "code", "execution_count": 1, "id": "faadfb1b-cebe-4dcf-82fd-34044c380bc4", "metadata": {}, "outputs": [], "source": [ "%%capture --no-stderr\n", "%pip install -U psycopg psycopg-pool langgraph langgraph-checkpoint-postgres" ] }, { "cell_type": "code", "execution_count": null, "id": "eca9aafb-a155-407a-8036-682a2f1297d7", "metadata": {}, "outputs": [], "source": [ "import getpass\n", "import os\n", "\n", "\n", "def _set_env(var: str):\n", " if not os.environ.get(var):\n", " os.environ[var] = getpass.getpass(f\"{var}: \")\n", "\n", "\n", "_set_env(\"OPENAI_API_KEY\")" ] }, { "cell_type": "markdown", "id": "b394e26c", "metadata": {}, "source": [ "
Set up LangSmith for LangGraph development
\n", "\n", " Sign up for LangSmith to quickly spot issues and improve the performance of your LangGraph projects. LangSmith lets you use trace data to debug, test, and monitor your LLM apps built with LangGraph — read more about how to get started here. \n", "
\n", "