From c217e4a58d4fa53ca5df9e9b9d3462b4ac334d24 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Tue, 25 Jun 2024 22:20:50 -0700 Subject: [PATCH] Update intro to same thread example, update conceptual docs to include checkpoint (#827) --- docs/docs/cloud/concepts/index.md | 4 ++++ docs/docs/concepts/low_level.md | 9 ++++++--- .../human_in_the_loop_user_input.ipynb | 2 +- examples/cloud_examples/same-thread.ipynb | 16 ++++++++++------ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/docs/docs/cloud/concepts/index.md b/docs/docs/cloud/concepts/index.md index 267970061..d1b771bdc 100644 --- a/docs/docs/cloud/concepts/index.md +++ b/docs/docs/cloud/concepts/index.md @@ -12,6 +12,10 @@ The LangGraph Cloud API provides several endpoints for creating and managing ass ### Threads A thread contains the accumulated state of a group of runs. If a run is executed on a thread, then the [state](../../../concepts/#persistence) of the underlying graph of the assistant will be persisted to the thread. A thread's current and historical state can be retrieved. To persist state, a thread must be created prior to executing a run. +The state of a thread at a particular point in time is called a checkpoint. + +For more on threads and checkpoints, see this section of the [LangGraph conceptual guide](https://langchain-ai.github.io/langgraph/concepts/low_level/#checkpointer). + The LangGraph Cloud API provides several endpoints for creating and managing threads and thread state. See the API reference for more details. ### Runs diff --git a/docs/docs/concepts/low_level.md b/docs/docs/concepts/low_level.md index 51b02abb6..b1423c238 100644 --- a/docs/docs/concepts/low_level.md +++ b/docs/docs/concepts/low_level.md @@ -272,12 +272,15 @@ See [this guide](/langgraph/how-tos/persistence) for how to use threads. When you use a checkpointer with a graph, you can interact with the state of that graph. This usually done when enabling different human-in-the-loop interaction patterns. -When interacting with the checkpointer state, you must specify [thread identifiers](#threads) +Each time you run the graph, the checkpointer creates several checkpoints every time a +node or set of nodes finishes running. +The most recent checkpoint is the current state of the thread. +When interacting with the checkpointer state, you must specify a [thread identifier](#threads). Each checkpoint has two properties: --**values**: This is the value of the state at this point in time. --**next**: This is a tuple of the nodes to execute next in the graph. +- **values**: This is the value of the state at this point in time. +- **next**: This is a tuple of the nodes to execute next in the graph. ### Get state diff --git a/examples/cloud_examples/human_in_the_loop_user_input.ipynb b/examples/cloud_examples/human_in_the_loop_user_input.ipynb index f11d13e4d..0d70e8db3 100644 --- a/examples/cloud_examples/human_in_the_loop_user_input.ipynb +++ b/examples/cloud_examples/human_in_the_loop_user_input.ipynb @@ -6,7 +6,7 @@ "source": [ "# How to Wait for User Input\n", "\n", - "One of the main human-in-the-loop interaction patterns is waiting for human input. A key use case involves asking the user clarifying questions. One way to accomplish this is simply go to the END node and exit the graph. Then, any user response comes back in as fresh invocation of the graph. This is basically just creating a chatbot architecture.\n", + "One of the main human-in-the-loop interaction patterns is waiting for human input. A key use case involves asking the user clarifying questions. One way to accomplish this is simply go to the `END` node and exit the graph. Then, any user response comes back in as fresh invocation of the graph. This is basically just creating a chatbot architecture.\n", "\n", "The issue with this is it is tough to resume back in a particular point in the graph. Often times the agent is halfway through some process, and just needs a bit of a user input. Although it is possible to design your graph in such a way where you have a `conditional_entry_point` to route user messages back to the right place, that is not super scalable (as it essentially involves having a routing function that can end up almost anywhere).\n", "\n", diff --git a/examples/cloud_examples/same-thread.ipynb b/examples/cloud_examples/same-thread.ipynb index 077ac4417..30410566e 100644 --- a/examples/cloud_examples/same-thread.ipynb +++ b/examples/cloud_examples/same-thread.ipynb @@ -7,9 +7,13 @@ "source": [ "# How to run multiple agents on the same thread\n", "\n", - "In LangGraph API, a thread is not explicitly associated with a particular agent.\n", - "This means that you can run multiple agents on the same thread.\n", - "In this example, we will create two agents and then call them both on the same thread." + "In LangGraph Cloud, a thread is not explicitly associated with a particular agent.\n", + "This means that you can run multiple agents on the same thread, which allows a different\n", + "agent to continue from an initial agent's progress.\n", + "\n", + "In this example, we will create two agents and then call them both on the same thread.\n", + "You'll see that the second agent will respond using information from the [checkpoint](https://langchain-ai.github.io/langgraph/concepts/low_level/#checkpointer-state) generated in the thread\n", + "by the first agent as context." ] }, { @@ -37,7 +41,7 @@ "id": "4f10d346-69e6-44f4-8ff0-ef539ba938df", "metadata": {}, "source": [ - "We can see that these agents are different" + "We can see that these agents are different:" ] }, { @@ -97,7 +101,7 @@ "id": "5e655e61-c2ee-488a-90f6-6189c84841da", "metadata": {}, "source": [ - "We can now run it on the OpenAI assistant first." + "We can now run the OpenAI assistant on the thread first." ] }, { @@ -133,7 +137,7 @@ "id": "c53709e9-ddb2-4429-9042-456eb6c91244", "metadata": {}, "source": [ - "Now, we can run it on a different Anthropic-based assistant." + "Now, we can run it on a second Anthropic-based assistant and see that this second assistant is aware of the initial question, and can answer the question, `and you?`:" ] }, {