{ "cells": [ { "cell_type": "markdown", "id": "47ed5db3-bda5-49e1-bf75-23e08c9a3af0", "metadata": {}, "source": [ "# How to pass private state\n", "\n", "Oftentimes, you may want nodes to be able to pass state to each other that should NOT be part of the main schema of the graph. This is often useful because there may be information that is not needed as input/output (and therefore doesn't really make sense to have in the main schema) but is ABSOLUTELY needed as part of the intermediate working logic.\n", "\n", "Let's take a look at an example below. In this example, we will create a RAG pipeline that:\n", "1. Takes in a user question\n", "2. Uses an LLM to generate a search query\n", "3. Retrieves documents for that generated query\n", "4. Generates a final answer based on those documents\n", "\n", "We will have a separate node for each step. We will only have the `question` and `answer` on the overall state. However, we will need separate states for the `search_query` and the `documents` - we will pass these as private state keys.\n", "\n", "Let's look at an example!\n", "\n", "## Setup\n", "\n", "First, let's install the required packages" ] }, { "cell_type": "code", "execution_count": null, "id": "32d79ebd", "metadata": {}, "outputs": [], "source": [ "%%capture --no-stderr\n", "%pip install -U langgraph" ] }, { "cell_type": "markdown", "id": "e30836ce", "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", "