From 3b2d5f02e118e23892446e53d89eb4e675564d93 Mon Sep 17 00:00:00 2001 From: Isaac Francisco <78627776+isahers1@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:56:43 -0700 Subject: [PATCH] [docs]: cloud how to for checking thread status (#1346) * draft * nit * harrison comments * spelling --- .../docs/cloud/how-tos/check_thread_status.md | 203 ++++++++++++++++++ docs/docs/cloud/how-tos/index.md | 1 + docs/mkdocs.yml | 1 + 3 files changed, 205 insertions(+) create mode 100644 docs/docs/cloud/how-tos/check_thread_status.md diff --git a/docs/docs/cloud/how-tos/check_thread_status.md b/docs/docs/cloud/how-tos/check_thread_status.md new file mode 100644 index 000000000..cb97b4ba1 --- /dev/null +++ b/docs/docs/cloud/how-tos/check_thread_status.md @@ -0,0 +1,203 @@ +# Check the Status of your Threads + +## Setup + +To start, we can setup our client with whatever URL you are hosting your graph from: + +### SDK initialization + +First, we need to setup our client so that we can communicate with our hosted graph: + +=== "Python" + + ```python + from langgraph_sdk import get_client + client = get_client(url="") + assistant_id = "agent" + thread = await client.threads.create() + ``` + +=== "Javascript" + + ```js + import { Client } from "@langchain/langgraph-sdk"; + + const client = new Client({ apiUrl:"" }); + const assistantId = agent; + const thread = await client.threads.create(); + ``` + +=== "CURL" + + ```bash + curl --request POST \ + --url /threads \ + --header 'Content-Type: application/json' \ + --data '{ + "metadata": {} + }' + ``` + +## Find idle threads + +We can use the following commands to find threads that are idle, which means that all runs executed on the thread have finished running: + +=== "Python" + + ```python + print(await client.threads.search(status="idle",limit=1)) + ``` + +=== "Javascript" + + ```js + console.log(await client.threads.search({status: "idle",limit:1})); + ``` + +=== "CURL" + + ```bash + curl --request POST \ + --url /threads/search \ + --header 'Content-Type: application/json' \ + --data '{"status": "idle", "limit": 1}' + ``` + +Output: + + [{'thread_id': 'cacf79bb-4248-4d01-aabc-938dbd60ed2c', + 'created_at': '2024-08-14T17:36:38.921660+00:00', + 'updated_at': '2024-08-14T17:36:38.921660+00:00', + 'metadata': {'graph_id': 'agent'}, + 'status': 'idle', + 'config': {'configurable': {}}}] + + +## Find interrupted threads + +We can use the following commands to find threads that have been interrupted in the middle of a run, which could either mean an error occurred before the run finished or a human-in-the-loop breakpoint was reached and the run is waiting to continue: + +=== "Python" + + ```python + print(await client.threads.search(status="interrupted",limit=1)) + ``` + +=== "Javascript" + + ```js + console.log(await client.threads.search({status: "interrupted",limit:1})); + ``` + +=== "CURL" + + ```bash + curl --request POST \ + --url /threads/search \ + --header 'Content-Type: application/json' \ + --data '{"status": "interrupted", "limit": 1}' + ``` + +Output: + + [{'thread_id': '0d282b22-bbd5-4d95-9c61-04dcc2e302a5', + 'created_at': '2024-08-14T17:41:50.235455+00:00', + 'updated_at': '2024-08-14T17:41:50.235455+00:00', + 'metadata': {'graph_id': 'agent'}, + 'status': 'interrupted', + 'config': {'configurable': {}}}] + +## Find busy threads + +We can use the following commands to find threads that are busy, meaning they are currently handling the execution of a run: + +=== "Python" + + ```python + print(await client.threads.search(status="busy",limit=1)) + ``` + +=== "Javascript" + + ```js + console.log(await client.threads.search({status: "busy",limit: 1})); + ``` + +=== "CURL" + + ```bash + curl --request POST \ + --url /threads/search \ + --header 'Content-Type: application/json' \ + --data '{"status": "busy", "limit": 1}' + ``` + +Output: + + [{'thread_id': '0d282b22-bbd5-4d95-9c61-04dcc2e302a5', + 'created_at': '2024-08-14T17:41:50.235455+00:00', + 'updated_at': '2024-08-14T17:41:50.235455+00:00', + 'metadata': {'graph_id': 'agent'}, + 'status': 'busy', + 'config': {'configurable': {}}}] + +## Find specific threads + +You may also want to check the status of specific threads, which you can do in a few ways: + +### Find by ID + +You can use the `get` function to find the status of a specific thread, as long as you have the ID saved + +=== "Python" + + ```python + print((await client.threads.get())['status']) + ``` + +=== "Javascript" + + ```js + console.log((await client.threads.get()).status); + ``` + +=== "CURL" + + ```bash + curl --request GET \ + --url /threads/ \ + --header 'Content-Type: application/json' | jq -r '.status' + ``` + +Output: + + 'idle' + +### Find by metadata + +The search endpoint for threads also allows you to filter on metadata, which can be helpful if you use metadata to tag threads in order to keep them organized: + +=== "Python" + + ```python + print((await client.threads.search(metadata={"foo":"bar"},limit=1))[0]['status']) + ``` + +=== "Javascript" + + ```js + console.log((await client.threads.search({metadata: {"foo":"bar"},limit: 1}))[0].status); + ``` + +=== "CURL" + + ```bash + curl --request POST \ + --url /threads/search \ + --header 'Content-Type: application/json' \ + --data '{"metadata": {"foo":"bar"}, "limit": 1}' | jq -r '.[0].status' + ``` + +Output: + + 'idle' \ No newline at end of file diff --git a/docs/docs/cloud/how-tos/index.md b/docs/docs/cloud/how-tos/index.md index 80b6ccaa5..59db860da 100644 --- a/docs/docs/cloud/how-tos/index.md +++ b/docs/docs/cloud/how-tos/index.md @@ -73,3 +73,4 @@ Other guides that may prove helpful! - [How to configure agents](cloud_examples/configuration_cloud.ipynb) - [How to convert LangGraph calls to LangGraph cloud calls](cloud_examples/langgraph_to_langgraph_cloud.ipynb) - [How to integrate webhooks](cloud_examples/webhooks.ipynb) +- [How to check status of your threads](./check_thread_status.md) \ No newline at end of file diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index e3159e32b..7daf741f7 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -231,6 +231,7 @@ nav: - Configure Agents: "cloud/how-tos/cloud_examples/configuration_cloud.ipynb" - Convert LangGraph calls to LangGraph Cloud calls: "cloud/how-tos/cloud_examples/langgraph_to_langgraph_cloud.ipynb" - Integrate Webhooks: 'cloud/how-tos/cloud_examples/webhooks.ipynb' + - Check Status of Threads: "cloud/how-tos/check_thread_status.md" - Conceptual Guides: - API Concepts: "cloud/concepts/api.md" - Cloud Concepts: "cloud/concepts/cloud.md"