{ "cells": [ { "cell_type": "markdown", "id": "7240d5b5-9dac-4070-8a9e-2350fb01e0be", "metadata": {}, "source": [ "# How to share state between threads\n", "\n", "By default, state in a graph is scoped to that thread.\n", "LangGraph also allows you to specify a \"scope\" for a given key/value pair that exists between threads. This can be useful for storing information that is shared between threads. For instance, you may want to store information about a user's preferences expressed in one thread, and then use that information in another thread.\n", "\n", "In this notebook we will go through an example of how to construct and use such a graph." ] }, { "cell_type": "markdown", "id": "c4c550b5-1954-496b-8b9d-800361af17dc", "metadata": {}, "source": [ "## Create graph\n", "\n", "In this example we will create a graph that will let us store information about a user's preferences. We will do so by defining a state key that will be scoped to a user_id, and allowing the model to populate this field as it deems fit (by providing the model with a tool to save information about the user).\n", "\n", " \n", "
Typing shared state keys
\n", "\n", " Shared state channels (keys) MUST be dictionaries (see `info` channel in the AgentState example below)\n", "
\n", "