From 64636ee978e86e2407967c09b7de0c3f49e8c3fd Mon Sep 17 00:00:00 2001 From: Isaac Francisco <78627776+isahers1@users.noreply.github.com> Date: Thu, 15 Aug 2024 11:25:53 -0700 Subject: [PATCH] [docs]: add auth and small changes (#1356) * wip * m * nit --- docs/docs/cloud/deployment/test_locally.md | 83 +++++++++++++++++++ .../docs/cloud/how-tos/check_thread_status.md | 9 +- docs/docs/cloud/how-tos/enqueue_concurrent.md | 4 +- .../how-tos/human_in_the_loop_breakpoint.md | 9 +- .../how-tos/human_in_the_loop_edit_state.md | 9 +- .../human_in_the_loop_review_tool_calls.md | 4 +- .../how-tos/human_in_the_loop_time_travel.md | 9 +- .../how-tos/human_in_the_loop_user_input.md | 9 +- .../cloud/how-tos/interrupt_concurrent.md | 4 +- docs/docs/cloud/how-tos/reject_concurrent.md | 4 +- .../docs/cloud/how-tos/rollback_concurrent.md | 4 +- docs/docs/cloud/how-tos/stream_debug.md | 4 +- docs/docs/cloud/how-tos/stream_events.md | 9 +- docs/docs/cloud/how-tos/stream_messages.md | 9 +- docs/docs/cloud/how-tos/stream_multiple.md | 9 +- docs/docs/cloud/how-tos/stream_updates.md | 9 +- docs/docs/cloud/how-tos/stream_values.md | 9 +- 17 files changed, 125 insertions(+), 72 deletions(-) diff --git a/docs/docs/cloud/deployment/test_locally.md b/docs/docs/cloud/deployment/test_locally.md index d25ecfc79..a5a06624a 100644 --- a/docs/docs/cloud/deployment/test_locally.md +++ b/docs/docs/cloud/deployment/test_locally.md @@ -38,6 +38,46 @@ Ready! We can now interact with the API server using the LangGraph SDK. First, we need to start our client, select our assistant (in this case a graph we called "agent", make sure to select the proper assistant you wish to test). +You can either initialize by passing authentication or by setting an environment variable. + +#### Initialize with authentication + +=== "Python" + + ```python + from langgraph_sdk import get_client + + # only pass the url argument to get_client() if you changed the default port when calling langgraph up + client = get_client(url=,api_key=) + assistant_id = "agent" + thread = await client.threads.create() + ``` + +=== "Javascript" + + ```js + import { Client } from "@langchain/langgraph-sdk"; + + // only set the apiUrl if you changed the default port when calling langgraph up + const client = new Client({ apiUrl: , apiKey: }); + const assistantId = "agent" + const thread = await client.threads.create(); + ``` + +=== "CURL" + + ```bash + curl --request POST \ + --url /threads \ + --header 'Content-Type: application/json' + --header 'x-api-key: ' + ``` + + +#### Initialize with environment variables + +If you have a `LANGCHAIN_API_KEY` set in your environment, you do not need to explicitly pass authentication to the client + === "Python" ```python @@ -60,6 +100,14 @@ We can now interact with the API server using the LangGraph SDK. First, we need const thread = await client.threads.create(); ``` +=== "CURL" + + ```bash + curl --request POST \ + --url /threads \ + --header 'Content-Type: application/json' + ``` + Now we can invoke our graph to ensure it is working. Make sure to change the input to match the proper schema for your graph. === "Python" @@ -96,4 +144,39 @@ Now we can invoke our graph to ensure it is working. Make sure to change the inp } ``` + === "CURL" + + ```bash + curl --request POST \ + --url /threads//runs/stream \ + --header 'Content-Type: application/json' \ + --data "{ + \"assistant_id\": \"agent\", + \"input\": {\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in sf\"}]}, + \"stream_mode\": [ + \"events\" + ] + }" | \ + sed 's/\r$//' | \ + awk ' + /^event:/ { + if (data_content != "") { + print data_content "\n" + } + sub(/^event: /, "Receiving event of type: ", $0) + printf "%s...\n", $0 + data_content = "" + } + /^data:/ { + sub(/^data: /, "", $0) + data_content = $0 + } + END { + if (data_content != "") { + print data_content "\n" + } + } + ' + ``` + If your graph works correctly, you should see your graph output displayed in the console. Of course, there are many more ways you might need to test your graph, for a full list of commands you can send with the SDK, see the [Python](https://langchain-ai.github.io/langgraph/cloud/reference/sdk/python_sdk_ref/) and [JS/TS](https://langchain-ai.github.io/langgraph/cloud/reference/sdk/js_ts_sdk_ref/) references. \ No newline at end of file diff --git a/docs/docs/cloud/how-tos/check_thread_status.md b/docs/docs/cloud/how-tos/check_thread_status.md index cb97b4ba1..655b918c1 100644 --- a/docs/docs/cloud/how-tos/check_thread_status.md +++ b/docs/docs/cloud/how-tos/check_thread_status.md @@ -12,7 +12,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) assistant_id = "agent" thread = await client.threads.create() ``` @@ -22,7 +22,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); const assistantId = agent; const thread = await client.threads.create(); ``` @@ -32,10 +32,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```bash curl --request POST \ --url /threads \ - --header 'Content-Type: application/json' \ - --data '{ - "metadata": {} - }' + --header 'Content-Type: application/json' ``` ## Find idle threads diff --git a/docs/docs/cloud/how-tos/enqueue_concurrent.md b/docs/docs/cloud/how-tos/enqueue_concurrent.md index 391550ee1..17c4ea0f5 100644 --- a/docs/docs/cloud/how-tos/enqueue_concurrent.md +++ b/docs/docs/cloud/how-tos/enqueue_concurrent.md @@ -31,7 +31,7 @@ Then, let's import our required packages and instantiate our client, assistant, from langchain_core.messages import convert_to_messages from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) assistant_id = "agent" thread = await client.threads.create() ``` @@ -42,7 +42,7 @@ Then, let's import our required packages and instantiate our client, assistant, import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); const assistantId = "agent"; const thread = await client.threads.create(); ``` diff --git a/docs/docs/cloud/how-tos/human_in_the_loop_breakpoint.md b/docs/docs/cloud/how-tos/human_in_the_loop_breakpoint.md index 180547b54..56c1931e2 100644 --- a/docs/docs/cloud/how-tos/human_in_the_loop_breakpoint.md +++ b/docs/docs/cloud/how-tos/human_in_the_loop_breakpoint.md @@ -21,7 +21,7 @@ In this how-to we use a simple ReAct style hosted graph (you can see the full co ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) assistant_id = "agent" thread = await client.threads.create() ``` @@ -31,7 +31,7 @@ In this how-to we use a simple ReAct style hosted graph (you can see the full co ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); const assistantId = "agent" const thread = await client.threads.create(); ``` @@ -41,10 +41,7 @@ In this how-to we use a simple ReAct style hosted graph (you can see the full co ```bash curl --request POST \ --url /threads \ - --header 'Content-Type: application/json' \ - --data '{ - "metadata": {} - }' + --header 'Content-Type: application/json' ``` ## Adding a breakpoint diff --git a/docs/docs/cloud/how-tos/human_in_the_loop_edit_state.md b/docs/docs/cloud/how-tos/human_in_the_loop_edit_state.md index e9871c2ff..668d826a8 100644 --- a/docs/docs/cloud/how-tos/human_in_the_loop_edit_state.md +++ b/docs/docs/cloud/how-tos/human_in_the_loop_edit_state.md @@ -17,7 +17,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) assistant_id = "agent" thread = await client.threads.create() ``` @@ -27,7 +27,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); const assistantId = "agent"; const thread = await client.threads.create(); ``` @@ -37,10 +37,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```bash curl --request POST \ --url /threads \ - --header 'Content-Type: application/json' \ - --data '{ - "metadata": {} - }' + --header 'Content-Type: application/json' ``` ## Editing state diff --git a/docs/docs/cloud/how-tos/human_in_the_loop_review_tool_calls.md b/docs/docs/cloud/how-tos/human_in_the_loop_review_tool_calls.md index c730e9e01..e9a698181 100644 --- a/docs/docs/cloud/how-tos/human_in_the_loop_review_tool_calls.md +++ b/docs/docs/cloud/how-tos/human_in_the_loop_review_tool_calls.md @@ -28,7 +28,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) assistant_id = "agent" thread = await client.threads.create() ``` @@ -38,7 +38,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); const assistantId = "agent"; const thread = await client.threads.create(); ``` diff --git a/docs/docs/cloud/how-tos/human_in_the_loop_time_travel.md b/docs/docs/cloud/how-tos/human_in_the_loop_time_travel.md index 36c8fe941..aac3ee566 100644 --- a/docs/docs/cloud/how-tos/human_in_the_loop_time_travel.md +++ b/docs/docs/cloud/how-tos/human_in_the_loop_time_travel.md @@ -14,7 +14,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) assistant_id = "agent" thread = await client.threads.create() ``` @@ -24,7 +24,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); const assistantId = agent; const thread = await client.threads.create(); ``` @@ -34,10 +34,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```bash curl --request POST \ --url /threads \ - --header 'Content-Type: application/json' \ - --data '{ - "metadata": {} - }' + --header 'Content-Type: application/json' ``` ## Replay a state diff --git a/docs/docs/cloud/how-tos/human_in_the_loop_user_input.md b/docs/docs/cloud/how-tos/human_in_the_loop_user_input.md index 068a0bb00..9b9d1392e 100644 --- a/docs/docs/cloud/how-tos/human_in_the_loop_user_input.md +++ b/docs/docs/cloud/how-tos/human_in_the_loop_user_input.md @@ -24,7 +24,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) assistant_id = "agent" thread = await client.threads.create() ``` @@ -34,7 +34,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); const assistantId = "agent"; const thread = await client.threads.create(); ``` @@ -44,10 +44,7 @@ First, we need to setup our client so that we can communicate with our hosted gr ```bash curl --request POST \ --url /threads \ - --header 'Content-Type: application/json' \ - --data '{ - "metadata": {} - }' + --header 'Content-Type: application/json' ``` ## Waiting for user input diff --git a/docs/docs/cloud/how-tos/interrupt_concurrent.md b/docs/docs/cloud/how-tos/interrupt_concurrent.md index 7c2792b45..d58df875b 100644 --- a/docs/docs/cloud/how-tos/interrupt_concurrent.md +++ b/docs/docs/cloud/how-tos/interrupt_concurrent.md @@ -29,7 +29,7 @@ Now, let's import our required packages and instantiate our client, assistant, a from langchain_core.messages import convert_to_messages from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) assistant_id = "agent" thread = await client.threads.create() ``` @@ -39,7 +39,7 @@ Now, let's import our required packages and instantiate our client, assistant, a ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); const assistantId = "agent"; const thread = await client.threads.create(); ``` diff --git a/docs/docs/cloud/how-tos/reject_concurrent.md b/docs/docs/cloud/how-tos/reject_concurrent.md index 1f69541fe..22d0ae30c 100644 --- a/docs/docs/cloud/how-tos/reject_concurrent.md +++ b/docs/docs/cloud/how-tos/reject_concurrent.md @@ -28,7 +28,7 @@ Now, let's import our required packages and instantiate our client, assistant, a from langchain_core.messages import convert_to_messages from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) assistant_id = "agent" thread = await client.threads.create() ``` @@ -38,7 +38,7 @@ Now, let's import our required packages and instantiate our client, assistant, a ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); const assistantId = "agent"; const thread = await client.threads.create(); ``` diff --git a/docs/docs/cloud/how-tos/rollback_concurrent.md b/docs/docs/cloud/how-tos/rollback_concurrent.md index 0e8f39aad..6fa34eb95 100644 --- a/docs/docs/cloud/how-tos/rollback_concurrent.md +++ b/docs/docs/cloud/how-tos/rollback_concurrent.md @@ -30,7 +30,7 @@ Now, let's import our required packages and instantiate our client, assistant, a from langchain_core.messages import convert_to_messages from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) assistant_id = "agent" thread = await client.threads.create() ``` @@ -40,7 +40,7 @@ Now, let's import our required packages and instantiate our client, assistant, a ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); const assistantId = "agent"; const thread = await client.threads.create(); ``` diff --git a/docs/docs/cloud/how-tos/stream_debug.md b/docs/docs/cloud/how-tos/stream_debug.md index 78c2e34b9..e580286ca 100644 --- a/docs/docs/cloud/how-tos/stream_debug.md +++ b/docs/docs/cloud/how-tos/stream_debug.md @@ -9,7 +9,7 @@ First let's set up our client and thread: ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) # create thread thread = await client.threads.create() print(thread) @@ -20,7 +20,7 @@ First let's set up our client and thread: ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); // create thread const thread = await client.threads.create(); console.log(thread) diff --git a/docs/docs/cloud/how-tos/stream_events.md b/docs/docs/cloud/how-tos/stream_events.md index fc02e3fff..3b0c58177 100644 --- a/docs/docs/cloud/how-tos/stream_events.md +++ b/docs/docs/cloud/how-tos/stream_events.md @@ -6,7 +6,7 @@ This guide covers how to stream events from your graph (`stream_mode="events"`). ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) # create thread thread = await client.threads.create() print(thread) @@ -17,7 +17,7 @@ This guide covers how to stream events from your graph (`stream_mode="events"`). ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); // create thread const thread = await client.threads.create(); console.log(thread) @@ -28,10 +28,7 @@ This guide covers how to stream events from your graph (`stream_mode="events"`). ```bash curl --request POST \ --url /threads \ - --header 'Content-Type: application/json' \ - --data '{ - "metadata": {} - }' + --header 'Content-Type: application/json' ``` Output: diff --git a/docs/docs/cloud/how-tos/stream_messages.md b/docs/docs/cloud/how-tos/stream_messages.md index cdcf004e2..c25f2ccdd 100644 --- a/docs/docs/cloud/how-tos/stream_messages.md +++ b/docs/docs/cloud/how-tos/stream_messages.md @@ -41,7 +41,7 @@ First let's set up our client and thread: ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) # create thread thread = await client.threads.create() print(thread) @@ -52,7 +52,7 @@ First let's set up our client and thread: ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); // create thread const thread = await client.threads.create(); console.log(thread) @@ -63,10 +63,7 @@ First let's set up our client and thread: ```bash curl --request POST \ --url /threads \ - --header 'Content-Type: application/json' \ - --data '{ - "metadata": {} - }' + --header 'Content-Type: application/json' ``` Output: diff --git a/docs/docs/cloud/how-tos/stream_multiple.md b/docs/docs/cloud/how-tos/stream_multiple.md index d2d349099..2f03fb550 100644 --- a/docs/docs/cloud/how-tos/stream_multiple.md +++ b/docs/docs/cloud/how-tos/stream_multiple.md @@ -9,7 +9,7 @@ First let's set up our client and thread: ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) # create thread thread = await client.threads.create() print(thread) @@ -20,7 +20,7 @@ First let's set up our client and thread: ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); // create thread const thread = await client.threads.create(); console.log(thread) @@ -31,10 +31,7 @@ First let's set up our client and thread: ```bash curl --request POST \ --url /threads \ - --header 'Content-Type: application/json' \ - --data '{ - "metadata": {} - }' + --header 'Content-Type: application/json' ``` Output: diff --git a/docs/docs/cloud/how-tos/stream_updates.md b/docs/docs/cloud/how-tos/stream_updates.md index 7b3d4730c..38edc3381 100644 --- a/docs/docs/cloud/how-tos/stream_updates.md +++ b/docs/docs/cloud/how-tos/stream_updates.md @@ -16,7 +16,7 @@ First let's set up our client and thread: ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) # create thread thread = await client.threads.create() print(thread) @@ -27,7 +27,7 @@ First let's set up our client and thread: ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl:"" }); + const client = new Client({ apiUrl: }); // create thread const thread = await client.threads.create(); console.log(thread) @@ -38,10 +38,7 @@ First let's set up our client and thread: ```bash curl --request POST \ --url /threads \ - --header 'Content-Type: application/json' \ - --data '{ - "metadata": {} - }' + --header 'Content-Type: application/json' ``` Output: diff --git a/docs/docs/cloud/how-tos/stream_values.md b/docs/docs/cloud/how-tos/stream_values.md index 34282bd71..bb2c237eb 100644 --- a/docs/docs/cloud/how-tos/stream_values.md +++ b/docs/docs/cloud/how-tos/stream_values.md @@ -16,7 +16,7 @@ First let's set up our client and thread: ```python from langgraph_sdk import get_client - client = get_client(url="") + client = get_client(url=) # create thread thread = await client.threads.create() print(thread) @@ -27,7 +27,7 @@ First let's set up our client and thread: ```js import { Client } from "@langchain/langgraph-sdk"; - const client = new Client({ apiUrl: "" }); + const client = new Client({ apiUrl: }); // create thread const thread = await client.threads.create(); console.log(thread) @@ -38,10 +38,7 @@ First let's set up our client and thread: ```bash curl --request POST \ --url /threads \ - --header 'Content-Type: application/json' \ - --data '{ - "metadata": {} - }' + --header 'Content-Type: application/json' ``` Output: