From e1ea8c953800c256b403ca156ea4eee8dd62be4b Mon Sep 17 00:00:00 2001 From: Arjun Natarajan Date: Mon, 12 May 2025 16:55:03 -0400 Subject: [PATCH] pr feedback --- docs/docs/cloud/how-tos/create_threads.md | 234 ----------------- .../{view_threads.md => use_threads.md} | 239 +++++++++++++++++- docs/mkdocs.yml | 3 +- 3 files changed, 233 insertions(+), 243 deletions(-) delete mode 100644 docs/docs/cloud/how-tos/create_threads.md rename docs/docs/cloud/how-tos/{view_threads.md => use_threads.md} (54%) diff --git a/docs/docs/cloud/how-tos/create_threads.md b/docs/docs/cloud/how-tos/create_threads.md deleted file mode 100644 index 5363f4384..000000000 --- a/docs/docs/cloud/how-tos/create_threads.md +++ /dev/null @@ -1,234 +0,0 @@ -# How to create a thread - -!!! info "Prerequisites" - - - [Threads Overview](../concepts/threads.md) - -To run your graph and the state persisted, you must first create a thread. In this guide, we will show how to create a thread. - -## Creating a thread - -### Empty thread - -To create a new thread, use the [LangGraph SDK](../../concepts/sdk.md) `create` method. See the [Python](../reference/sdk/python_sdk_ref.md#langgraph_sdk.client.ThreadsClient.create) and [JS](../reference/sdk/js_ts_sdk_ref.md#create_3) SDK reference docs for more information. - - -=== "Python" - - ```python - from langgraph_sdk import get_client - - client = get_client(url=) - thread = await client.threads.create() - - print(thread) - ``` - -=== "Javascript" - - ```js - import { Client } from "@langchain/langgraph-sdk"; - - const client = new Client({ apiUrl: }); - const thread = await client.threads.create(); - - console.log(thread); - ``` - -=== "CURL" - - ```bash - curl --request POST \ - --url /threads \ - --header 'Content-Type: application/json' \ - --data '{}' - ``` - -Output: - - { - "thread_id": "123e4567-e89b-12d3-a456-426614174000", - "created_at": "2025-05-12T14:04:08.268Z", - "updated_at": "2025-05-12T14:04:08.268Z", - "metadata": {}, - "status": "idle", - "values": {} - } - -### Copy thread - -Alternatively, if you already have a thread in your application whose state you wish to copy, you can use the `copy` method. This will create an independent thread whose history is identical to the original thread at the time of the operation. See the [Python](../reference/sdk/python_sdk_ref.md#langgraph_sdk.client.ThreadsClient.copy) and [JS](../reference/sdk/js_ts_sdk_ref.md#copy) SDK reference docs for more information. - -=== "Python" - - ```python - copied_thread = await client.threads.copy() - ``` - -=== "Javascript" - - ```js - const copiedThread = await client.threads.copy(); - ``` - -=== "CURL" - - ```bash - curl --request POST --url /threads//copy \ - --header 'Content-Type: application/json' - ``` - -### Prepopulated State - - -Finally, you can create a thread with an arbitrary pre-defined state by providing a list of `supersteps` into the `create` method. The `supersteps` describe a list of a sequence of state updates. For example: - -=== "Python" - - ```python - from langgraph_sdk import get_client - - client = get_client(url=) - thread = await client.threads.create( - graph_id="agent", - supersteps=[ - { - updates: [ - { - values: {}, - as_node: '__input__', - }, - ], - }, - { - updates: [ - { - values: { - messages: [ - { - type: 'human', - content: 'hello', - }, - ], - }, - as_node: '__start__', - }, - ], - }, - { - updates: [ - { - values: { - messages: [ - { - content: 'Hello! How can I assist you today?', - type: 'ai', - }, - ], - }, - as_node: 'call_model', - }, - ], - }, - ]) - - print(thread) - ``` - -=== "Javascript" - - ```js - import { Client } from "@langchain/langgraph-sdk"; - - const client = new Client({ apiUrl: }); - const thread = await client.threads.create({ - graphId: 'agent', - supersteps: [ - { - updates: [ - { - values: {}, - asNode: '__input__', - }, - ], - }, - { - updates: [ - { - values: { - messages: [ - { - type: 'human', - content: 'hello', - }, - ], - }, - asNode: '__start__', - }, - ], - }, - { - updates: [ - { - values: { - messages: [ - { - content: 'Hello! How can I assist you today?', - type: 'ai', - }, - ], - }, - asNode: 'call_model', - }, - ], - }, - ], - }); - - console.log(thread); - ``` - -=== "CURL" - - ```bash - curl --request POST \ - --url /threads \ - --header 'Content-Type: application/json' \ - --data '{"metadata":{"graph_id":"agent"},"supersteps":[{"updates":[{"values":{},"as_node":"__input__"}]},{"updates":[{"values":{"messages":[{"type":"human","content":"hello"}]},"as_node":"__start__"}]},{"updates":[{"values":{"messages":[{"content":"Hello\u0021 How can I assist you today?","type":"ai"}]},"as_node":"call_model"}]}]}' - ``` - -Output: - - { - "thread_id": "f15d70a1-27d4-4793-a897-de5609920b7d", - "created_at": "2025-05-12T15:37:08.935038+00:00", - "updated_at": "2025-05-12T15:37:08.935046+00:00", - "metadata": {"graph_id": "agent"}, - "status": "idle", - "config": {}, - "values": { - "messages": [ - { - "content": "hello", - "additional_kwargs": {}, - "response_metadata": {}, - "type": "human", - "name": null, - "id": "8701f3be-959c-4b7c-852f-c2160699b4ab", - "example": false - }, - { - "content": "Hello! How can I assist you today?", - "additional_kwargs": {}, - "response_metadata": {}, - "type": "ai", - "name": null, - "id": "4d8ea561-7ca1-409a-99f7-6b67af3e1aa3", - "example": false, - "tool_calls": [], - "invalid_tool_calls": [], - "usage_metadata": null - } - ] - } - } diff --git a/docs/docs/cloud/how-tos/view_threads.md b/docs/docs/cloud/how-tos/use_threads.md similarity index 54% rename from docs/docs/cloud/how-tos/view_threads.md rename to docs/docs/cloud/how-tos/use_threads.md index c338c3dc7..ebe97d4d3 100644 --- a/docs/docs/cloud/how-tos/view_threads.md +++ b/docs/docs/cloud/how-tos/use_threads.md @@ -1,13 +1,239 @@ -# How to view and inspect Threads +# How to use threads !!! info "Prerequisites" - [Threads Overview](../concepts/threads.md) - - [How to create threads](./create_threads.md) -This guide shows how to view threads in a LangGraph Platform application and inspect their state. +In this guide, we will show how to create, view, and inspect threads. -## List Threads +## Create a thread + +To run your graph and the state persisted, you must first create a thread. + +### Empty thread + +To create a new thread, use the [LangGraph SDK](../../concepts/sdk.md) `create` method. See the [Python](../reference/sdk/python_sdk_ref.md#langgraph_sdk.client.ThreadsClient.create) and [JS](../reference/sdk/js_ts_sdk_ref.md#create_3) SDK reference docs for more information. + +=== "Python" + + ```python + from langgraph_sdk import get_client + + client = get_client(url=) + thread = await client.threads.create() + + print(thread) + ``` + +=== "Javascript" + + ```js + import { Client } from "@langchain/langgraph-sdk"; + + const client = new Client({ apiUrl: }); + const thread = await client.threads.create(); + + console.log(thread); + ``` + +=== "CURL" + + ```bash + curl --request POST \ + --url /threads \ + --header 'Content-Type: application/json' \ + --data '{}' + ``` + +Output: + + { + "thread_id": "123e4567-e89b-12d3-a456-426614174000", + "created_at": "2025-05-12T14:04:08.268Z", + "updated_at": "2025-05-12T14:04:08.268Z", + "metadata": {}, + "status": "idle", + "values": {} + } + +### Copy thread + +Alternatively, if you already have a thread in your application whose state you wish to copy, you can use the `copy` method. This will create an independent thread whose history is identical to the original thread at the time of the operation. See the [Python](../reference/sdk/python_sdk_ref.md#langgraph_sdk.client.ThreadsClient.copy) and [JS](../reference/sdk/js_ts_sdk_ref.md#copy) SDK reference docs for more information. + +=== "Python" + + ```python + copied_thread = await client.threads.copy() + ``` + +=== "Javascript" + + ```js + const copiedThread = await client.threads.copy(); + ``` + +=== "CURL" + + ```bash + curl --request POST --url /threads//copy \ + --header 'Content-Type: application/json' + ``` + +### Prepopulated State + +Finally, you can create a thread with an arbitrary pre-defined state by providing a list of `supersteps` into the `create` method. The `supersteps` describe a list of a sequence of state updates. For example: + +=== "Python" + + ```python + from langgraph_sdk import get_client + + client = get_client(url=) + thread = await client.threads.create( + graph_id="agent", + supersteps=[ + { + updates: [ + { + values: {}, + as_node: '__input__', + }, + ], + }, + { + updates: [ + { + values: { + messages: [ + { + type: 'human', + content: 'hello', + }, + ], + }, + as_node: '__start__', + }, + ], + }, + { + updates: [ + { + values: { + messages: [ + { + content: 'Hello! How can I assist you today?', + type: 'ai', + }, + ], + }, + as_node: 'call_model', + }, + ], + }, + ]) + + print(thread) + ``` + +=== "Javascript" + + ```js + import { Client } from "@langchain/langgraph-sdk"; + + const client = new Client({ apiUrl: }); + const thread = await client.threads.create({ + graphId: 'agent', + supersteps: [ + { + updates: [ + { + values: {}, + asNode: '__input__', + }, + ], + }, + { + updates: [ + { + values: { + messages: [ + { + type: 'human', + content: 'hello', + }, + ], + }, + asNode: '__start__', + }, + ], + }, + { + updates: [ + { + values: { + messages: [ + { + content: 'Hello! How can I assist you today?', + type: 'ai', + }, + ], + }, + asNode: 'call_model', + }, + ], + }, + ], + }); + + console.log(thread); + ``` + +=== "CURL" + + ```bash + curl --request POST \ + --url /threads \ + --header 'Content-Type: application/json' \ + --data '{"metadata":{"graph_id":"agent"},"supersteps":[{"updates":[{"values":{},"as_node":"__input__"}]},{"updates":[{"values":{"messages":[{"type":"human","content":"hello"}]},"as_node":"__start__"}]},{"updates":[{"values":{"messages":[{"content":"Hello\u0021 How can I assist you today?","type":"ai"}]},"as_node":"call_model"}]}]}' + ``` + +Output: + + { + "thread_id": "f15d70a1-27d4-4793-a897-de5609920b7d", + "created_at": "2025-05-12T15:37:08.935038+00:00", + "updated_at": "2025-05-12T15:37:08.935046+00:00", + "metadata": {"graph_id": "agent"}, + "status": "idle", + "config": {}, + "values": { + "messages": [ + { + "content": "hello", + "additional_kwargs": {}, + "response_metadata": {}, + "type": "human", + "name": null, + "id": "8701f3be-959c-4b7c-852f-c2160699b4ab", + "example": false + }, + { + "content": "Hello! How can I assist you today?", + "additional_kwargs": {}, + "response_metadata": {}, + "type": "ai", + "name": null, + "id": "4d8ea561-7ca1-409a-99f7-6b67af3e1aa3", + "example": false, + "tool_calls": [], + "invalid_tool_calls": [], + "usage_metadata": null + } + ] + } + } + +## List threads ### LangGraph SDK @@ -101,7 +327,7 @@ Inside your deployment, select the "Threads" tab. This will load a table of all To filter by thread status, select a status in the top bar. To sort by a supported property, click on the arrow icon for the desired column. -## Inspect specific threads +## Inspect threads ### LangGraph SDK @@ -144,7 +370,6 @@ Output: To view the current state of a given thread, use the `get_state` method: - === "Python" ```python @@ -263,4 +488,4 @@ You can also view threads in a deployment via the LangGraph Platform UI. Inside your deployment, select the "Threads" tab. This will load a table of all of the threads in your deployment. -Select a thread to inspect its current state. To view it's full history and for further debugging, open the thread in [LangGraph Studio](../../concepts//langgraph_studio.md). \ No newline at end of file +Select a thread to inspect its current state. To view it's full history and for further debugging, open the thread in [LangGraph Studio](../../concepts//langgraph_studio.md). diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index a4a6839aa..657e49612 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -197,8 +197,7 @@ nav: - cloud/how-tos/assistant_versioning.md - Threads: - Overview: cloud/concepts/threads.md - - cloud/how-tos/create_threads.md - - cloud/how-tos/view_threads.md + - cloud/how-tos/use_threads.md - Runs: - Overview: cloud/concepts/runs.md - cloud/how-tos/background_run.md