Merge branch 'main' into vb/add-sync-client

This commit is contained in:
vbarda
2024-09-23 16:56:12 -04:00
625 changed files with 69275 additions and 57511 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
# API Concepts
This page describes the high-level concepts of the LangGraph Cloud API. The conceptual guide of LangGraph (Python library) is [here](../../concepts/index.md).
This page describes the high-level concepts of the LangGraph Cloud API. The conceptual guide of LangGraph (Python library) is [here](../../concepts/high_level.md).
## Data Models
@@ -14,7 +14,7 @@ The LangGraph Cloud API provides several endpoints for creating and managing ass
#### Configuring Assistants
You can save custom assistants from the same graph to set different default prompts, models, and other configurations without changing a line of code in your graph. This allows you the ability to quickly test out different configurations without having to rewrite your graph every time, and also give users the flexibility to select different configurations when using your LangGraph application. See <a href="https://langchain-ai.github.io/langgraph/cloud/how-tos/cloud_examples/configuration_cloud/">this</a> how-to for information on how to configure a deployed graph.
You can save custom assistants from the same graph to set different default prompts, models, and other configurations without changing a line of code in your graph. This allows you the ability to quickly test out different configurations without having to rewrite your graph every time, and also give users the flexibility to select different configurations when using your LangGraph application. See [this how-to](../how-tos/configuration_cloud.md) for information on how to configure a deployed graph.
### Threads
@@ -22,7 +22,7 @@ A thread contains the accumulated state of a group of runs. If a run is executed
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](../../concepts/low_level.md#checkpointer).
For more on threads and checkpoints, see this section of the [LangGraph conceptual guide](../../concepts/low_level.md#persistence).
The LangGraph Cloud API provides several endpoints for creating and managing threads and thread state. See the [API reference](../reference/api/api_ref.html#tag/threadscreate) for more details.
+7 -7
View File
@@ -5,10 +5,10 @@ A LangGraph application must be configured with a [LangGraph API configuration f
This walkthrough is based on [this repository](https://github.com/langchain-ai/langgraph-example), which you can play around with to learn more about how to setup your LangGraph application for deployment.
!!! tip "Setup with pyproject.toml"
If you prefer using poetry for dependency management, check out [this how-to guide](./setup_pyproject.md) on using `pyproject.toml` for LangGraph Cloud.
If you prefer using poetry for dependency management, check out [this how-to guide](./setup_pyproject.md) on using `pyproject.toml` for LangGraph Cloud.
!!! tip "Setup with a Monorepo"
If you are interested in deploying a graph located inside a monorepo, take a look at [this](https://github.com/langchain-ai/langgraph-example-monorepo) repository for an example of how to do so.
If you are interested in deploying a graph located inside a monorepo, take a look at [this](https://github.com/langchain-ai/langgraph-example-monorepo) repository for an example of how to do so.
The final repo structure will look something like this:
@@ -36,9 +36,9 @@ Dependencies can optionally be specified in one of the following files: `pyproje
The dependencies below will be included in the image, you can also use them in your code, as long as with a compatible version range:
```
langgraph>=0.2.7,<0.3.0
langgraph-checkpoint>=1.0.4
langchain-core>=0.2.27,<0.3.0
langgraph>=0.2.18,<0.3.0
langgraph-checkpoint>=1.0.9
langchain-core>=0.2.38,<0.4.0
langsmith>=0.1.63
orjson>=3.9.7
httpx>=0.25.0
@@ -129,7 +129,7 @@ graph = workflow.compile()
```
!!! warning "Assign `CompiledGraph` to Variable"
The build process for LangGraph Cloud requires that the `CompiledGraph` object be assigned to a variable at the top-level of a Python module (alternatively, you can provide [a function that creates a graph](./graph_rebuild.md)).
The build process for LangGraph Cloud requires that the `CompiledGraph` object be assigned to a variable at the top-level of a Python module (alternatively, you can provide [a function that creates a graph](./graph_rebuild.md)).
Example file directory:
@@ -166,7 +166,7 @@ Example `langgraph.json` file:
Note that the variable name of the `CompiledGraph` appears at the end of the value of each subkey in the top-level `graphs` key (i.e. `:<variable_name>`).
!!! warning "Configuration Location"
The LangGraph API configuration file must be placed in a directory that is at the same level or higher than the Python files that contain compiled graphs and associated dependencies.
The LangGraph API configuration file must be placed in a directory that is at the same level or higher than the Python files that contain compiled graphs and associated dependencies.
Example file directory:
@@ -5,7 +5,7 @@ A LangGraph application must be configured with a [LangGraph API configuration f
This walkthrough is based on [this repository](https://github.com/langchain-ai/langgraph-example-pyproject), which you can play around with to learn more about how to setup your LangGraph application for deployment.
!!! tip "Setup with requirements.txt"
If you prefer using `requirements.txt` for dependency management, check out [this how-to guide](./setup.md).
If you prefer using `requirements.txt` for dependency management, check out [this how-to guide](./setup.md).
!!! tip "Setup with a Monorepo"
If you are interested in deploying a graph located inside a monorepo, take a look at [this](https://github.com/langchain-ai/langgraph-example-monorepo) repository for an example of how to do so.
@@ -36,9 +36,9 @@ Dependencies can optionally be specified in one of the following files: `pyproje
The dependencies below will be included in the image, you can also use them in your code, as long as with a compatible version range:
```
langgraph>=0.2.7,<0.3.0
langgraph-checkpoint>=1.0.4
langchain-core>=0.2.27,<0.3.0
langgraph>=0.2.18,<0.3.0
langgraph-checkpoint>=1.0.9
langchain-core>=0.2.38,<0.4.0
langsmith>=0.1.63
orjson>=3.9.7
httpx>=0.25.0
@@ -49,8 +49,8 @@ uvloop>=0.18.0
httptools>=0.5.0
jsonschema-rs>=0.16.3
croniter>=1.0.1
structlog>=24.4.0
redis>=5.0.8,<6.0.0
structlog>=23.1.0
redis>=5.0.0,<6.0.0
```
Example `pyproject.toml` file:
+2 -2
View File
@@ -117,7 +117,7 @@ Now we can invoke our graph to ensure it is working. Make sure to change the inp
=== "Python"
```python
input = {"messages": [{"role": "human", "content": "what's the weather in sf"}]}
input = {"messages": [{"role": "user", "content": "what's the weather in sf"}]}
async for chunk in client.runs.stream(
thread["thread_id"],
assistant_id,
@@ -131,7 +131,7 @@ Now we can invoke our graph to ensure it is working. Make sure to change the inp
=== "Javascript"
```js
const input = { "messages": [{ "role": "human", "content": "what's the weather in sf"}] }
const input = { "messages": [{ "role": "user", "content": "what's the weather in sf"}] }
const streamResponse = client.runs.stream(
thread["thread_id"],
+11 -4
View File
@@ -1,8 +1,11 @@
# How to kick off background runs
This guide covers how to kick off background runs for your agent.
This can be useful for long running jobs.
## Setup
First let's set up our client and thread:
=== "Python"
@@ -52,6 +55,8 @@ Output:
'values': None
}
## Check runs on thread
If we list the current runs on this thread, we will see that it's empty:
=== "Python"
@@ -79,19 +84,21 @@ Output:
[]
## Start runs on thread
Now let's kick off a run:
=== "Python"
```python
input = {"messages": [{"role": "human", "content": "what's the weather in sf"}]}
input = {"messages": [{"role": "user", "content": "what's the weather in sf"}]}
run = await client.runs.create(thread["thread_id"], assistant_id, input=input)
```
=== "Javascript"
```js
let input = {"messages": [{"role": "human", "content": "what's the weather in sf"}]};
let input = {"messages": [{"role": "user", "content": "what's the weather in sf"}]};
let run = await client.runs.create(thread["thread_id"], assistantID, { input });
```
@@ -141,7 +148,7 @@ Output:
"input": {
"messages": [
{
"role": "human",
"role": "user",
"content": "what's the weather in sf"
}
]
@@ -212,7 +219,7 @@ Output:
"input": {
"messages": [
{
"role": "human",
"role": "user",
"content": "what's the weather in sf"
}
]
Binary file not shown.

Before

Width:  |  Height:  |  Size: 322 KiB

@@ -219,7 +219,7 @@ We can verify the config is indeed taking effect:
"input": {
"messages": [
{
"role": "human",
"role": "user",
"content": "who made you?"
}
]
+10 -5
View File
@@ -1,9 +1,10 @@
## Enqueue
# Enqueue
This guide assumes knowledge of what double-texting is, which you can learn about in the [double-texting conceptual guide](../concepts/api.md#double-texting).
The guide covers the `enqueue` option for double texting, which adds the interruptions to a queue and executes them in the order they are received by the client. Below is a quick example of using the `enqueue` option.
## Setup
First, we will define a quick helper function for printing out JS and CURL model outputs (you can skip this if using Python):
@@ -82,6 +83,8 @@ Then, let's import our required packages and instantiate our client, assistant,
--data '{}'
```
## Create runs
Now let's start two runs, with the second interrupting the first one with a multitask strategy of "enqueue":
=== "Python"
@@ -90,12 +93,12 @@ Now let's start two runs, with the second interrupting the first one with a mult
first_run = await client.runs.create(
thread["thread_id"],
assistant_id,
input={"messages": [{"role": "human", "content": "what's the weather in sf?"}]},
input={"messages": [{"role": "user", "content": "what's the weather in sf?"}]},
)
second_run = await client.runs.create(
thread["thread_id"],
assistant_id,
input={"messages": [{"role": "human", "content": "what's the weather in nyc?"}]},
input={"messages": [{"role": "user", "content": "what's the weather in nyc?"}]},
multitask_strategy="enqueue",
)
```
@@ -106,13 +109,13 @@ Now let's start two runs, with the second interrupting the first one with a mult
const firstRun = await client.runs.create(
thread["thread_id"],
assistantId,
input={"messages": [{"role": "human", "content": "what's the weather in sf?"}]},
input={"messages": [{"role": "user", "content": "what's the weather in sf?"}]},
)
const secondRun = await client.runs.create(
thread["thread_id"],
assistantId,
input={"messages": [{"role": "human", "content": "what's the weather in nyc?"}]},
input={"messages": [{"role": "user", "content": "what's the weather in nyc?"}]},
multitask_strategy="enqueue",
)
```
@@ -136,6 +139,8 @@ Now let's start two runs, with the second interrupting the first one with a mult
}"
```
## View run results
Verify that the thread has data from both runs:
=== "Python"
@@ -61,7 +61,7 @@ And, now let's compile it with a breakpoint before the tool node:
=== "Python"
```python
input = {"messages": [{"role": "human", "content": "what's the weather in sf"}]}
input = {"messages": [{"role": "user", "content": "what's the weather in sf"}]}
async for chunk in client.runs.stream(
thread["thread_id"],
assistant_id,
@@ -77,7 +77,7 @@ Let's look at an example when no review is required (because no tools are called
=== "Javascript"
```js
const input = { "messages": [{ "role": "human", "content": "hi!" }] };
const input = { "messages": [{ "role": "user", "content": "hi!" }] };
const streamResponse = client.runs.stream(
thread["thread_id"],
@@ -64,7 +64,7 @@ Before replaying a state - we need to create states to replay from! In order to
=== "Javascript"
```js
const input = { "messages": [{ "role": "human", "content": "Please search the weather in SF" }] }
const input = { "messages": [{ "role": "user", "content": "Please search the weather in SF" }] }
const streamResponse = client.runs.stream(
thread["thread_id"],
@@ -62,7 +62,7 @@ Now, let's invoke our graph by interrupting before `ask_human` node:
input = {
"messages": [
{
"role": "human",
"role": "user",
"content": "Use the search tool to ask the user where they are, then look up the weather there",
}
]
+1 -1
View File
@@ -77,7 +77,7 @@ LangGraph Cloud supports multiple types of runs besides streaming runs.
Other guides that may prove helpful!
- [How to configure agents](./configuration_cloud.md)
- [How to convert LangGraph calls to LangGraph cloud calls](cloud_examples/langgraph_to_langgraph_cloud.ipynb)
- [How to convert LangGraph calls to LangGraph cloud calls](./langgraph_to_langgraph_cloud.ipynb)
- [How to integrate webhooks](./webhooks.md)
- [How to copy threads](./copy_threads.md)
- [How to check status of your threads](./check_thread_status.md)
@@ -1,9 +1,11 @@
## Interrupt
# Interrupt
This guide assumes knowledge of what double-texting is, which you can learn about in the [double-texting conceptual guide](../concepts/api.md#double-texting).
The guide covers the `interrupt` option for double texting, which interrupts the prior run of the graph and starts a new one with the double-text. This option does not delete the first run, but rather keeps it in the database but sets its status to `interrupted`. Below is a quick example of using the `interrupt` option.
## Setup
First, we will define a quick helper function for printing out JS and CURL model outputs (you can skip this if using Python):
=== "Javascript"
@@ -79,6 +81,8 @@ Now, let's import our required packages and instantiate our client, assistant, a
--data '{}'
```
## Create runs
Now we can start our two runs and join the second on euntil it has completed:
=== "Python"
@@ -88,13 +92,13 @@ Now we can start our two runs and join the second on euntil it has completed:
interrupted_run = await client.runs.create(
thread["thread_id"],
assistant_id,
input={"messages": [{"role": "human", "content": "what's the weather in sf?"}]},
input={"messages": [{"role": "user", "content": "what's the weather in sf?"}]},
)
await asyncio.sleep(2)
run = await client.runs.create(
thread["thread_id"],
assistant_id,
input={"messages": [{"role": "human", "content": "what's the weather in nyc?"}]},
input={"messages": [{"role": "user", "content": "what's the weather in nyc?"}]},
multitask_strategy="interrupt",
)
# wait until the second run completes
@@ -145,6 +149,8 @@ Now we can start our two runs and join the second on euntil it has completed:
--url <DEPLOYMENT_URL>/threads/<THREAD_ID>/runs/<RUN_ID>/join
```
## View run results
We can see that the thread has partial data from the first run + data from the second run
File diff suppressed because it is too large Load Diff
+10 -5
View File
@@ -1,9 +1,11 @@
## Reject
# Reject
This guide assumes knowledge of what double-texting is, which you can learn about in the [double-texting conceptual guide][double-texting].
The guide covers the `reject` option for double texting, which rejects the new run of the graph by throwing an error and continues with the original run until completion. Below is a quick example of using the `reject` option.
## Setup
First, we will define a quick helper function for printing out JS and CURL model outputs (you can skip this if using Python):
=== "Javascript"
@@ -78,6 +80,8 @@ Now, let's import our required packages and instantiate our client, assistant, a
--data '{}'
```
## Create runs
Now we can run a thread and try to run a second one with the "reject" option, which should fail since we have already started a run:
@@ -87,14 +91,14 @@ Now we can run a thread and try to run a second one with the "reject" option, wh
run = await client.runs.create(
thread["thread_id"],
assistant_id,
input={"messages": [{"role": "human", "content": "what's the weather in sf?"}]},
input={"messages": [{"role": "user", "content": "what's the weather in sf?"}]},
)
try:
await client.runs.create(
thread["thread_id"],
assistant_id,
input={
"messages": [{"role": "human", "content": "what's the weather in nyc?"}]
"messages": [{"role": "user", "content": "what's the weather in nyc?"}]
},
multitask_strategy="reject",
)
@@ -108,7 +112,7 @@ Now we can run a thread and try to run a second one with the "reject" option, wh
const run = await client.runs.create(
thread["thread_id"],
assistantId,
input={"messages": [{"role": "human", "content": "what's the weather in sf?"}]},
input={"messages": [{"role": "user", "content": "what's the weather in sf?"}]},
);
try {
@@ -116,7 +120,7 @@ Now we can run a thread and try to run a second one with the "reject" option, wh
thread["thread_id"],
assistantId,
{
input: {"messages": [{"role": "human", "content": "what's the weather in nyc?"}]},
input: {"messages": [{"role": "user", "content": "what's the weather in nyc?"}]},
multitask_strategy:"reject"
},
);
@@ -149,6 +153,7 @@ Output:
Failed to start concurrent run Client error '409 Conflict' for url 'http://localhost:8123/threads/f9e7088b-8028-4e5c-88d2-9cc9a2870e50/runs'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409
## View run results
We can verify that the original thread finished executing:
@@ -1,9 +1,11 @@
## Rollback
# Rollback
This guide assumes knowledge of what double-texting is, which you can learn about in the [double-texting conceptual guide][double-texting].
The guide covers the `rollback` option for double texting, which interrupts the prior run of the graph and starts a new one with the double-text. This option is very similar to the `interrupt` option, but in this case the first run is completely deleted from the database and cannot be restarted. Below is a quick example of using the `rollback` option.
## Setup
First, we will define a quick helper function for printing out JS and CURL model outputs (you can skip this if using Python):
=== "Javascript"
@@ -80,6 +82,8 @@ Now, let's import our required packages and instantiate our client, assistant, a
--data '{}'
```
## Create runs
Now let's run a thread with the multitask parameter set to "rollback":
=== "Python"
@@ -89,13 +93,13 @@ Now let's run a thread with the multitask parameter set to "rollback":
rolled_back_run = await client.runs.create(
thread["thread_id"],
assistant_id,
input={"messages": [{"role": "human", "content": "what's the weather in sf?"}]},
input={"messages": [{"role": "user", "content": "what's the weather in sf?"}]},
)
await asyncio.sleep(2)
run = await client.runs.create(
thread["thread_id"],
assistant_id,
input={"messages": [{"role": "human", "content": "what's the weather in nyc?"}]},
input={"messages": [{"role": "user", "content": "what's the weather in nyc?"}]},
multitask_strategy="rollback",
)
# wait until the second run completes
@@ -146,6 +150,8 @@ Now let's run a thread with the multitask parameter set to "rollback":
--url <DEPLOYMENT_URL>/threads/<THREAD_ID>/runs/<RUN_ID>/join
```
## View run results
We can see that the thread has data only from the second run
=== "Python"
+10 -2
View File
@@ -6,6 +6,8 @@ This means that you can run multiple agents on the same thread, which allows a d
In this example, we will create two agents and then call them both on the same thread.
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 by the first agent as context.
## Setup
=== "Python"
```python
@@ -124,6 +126,10 @@ Output:
}
}
## Run assistants on thread
### Run OpenAI assistant
We can now run the OpenAI assistant on the thread first.
=== "Python"
@@ -178,7 +184,7 @@ We can now run the OpenAI assistant on the thread first.
"input": {
"messages": [
{
"role": "human",
"role": "user",
"content": "who made you?"
}
]
@@ -218,6 +224,8 @@ Output:
Receiving event of type: updates
{'agent': {'messages': [{'content': 'I was created by OpenAI, a research organization focused on developing and advancing artificial intelligence technology.', 'additional_kwargs': {}, 'response_metadata': {'finish_reason': 'stop', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_157b3831f5'}, 'type': 'ai', 'name': None, 'id': 'run-f5735b86-b80d-4c71-8dc3-4782b5a9c7c8', 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None}]}}
### Run default assistant
Now, we can run it on the default assistant and see that this second assistant is aware of the initial question, and can answer the question, "and you?":
=== "Python"
@@ -266,7 +274,7 @@ Now, we can run it on the default assistant and see that this second assistant i
"input": {
"messages": [
{
"role": "human",
"role": "user",
"content": "and you?"
}
]
+5 -5
View File
@@ -59,7 +59,7 @@ Now, let's run the graph on the first thread, and provide it some information ab
=== "Python"
```python
input = {"messages": [{"role": "human", "content": "i like pepperoni pizza"}]}
input = {"messages": [{"role": "user", "content": "i like pepperoni pizza"}]}
config = {"configurable": {"user_id": "123"}}
# stream values
async for chunk in client.runs.stream(
@@ -162,7 +162,7 @@ Let's stay on the same thread and provide some additional information. Note that
=== "Python"
```python
input = {"messages": [{"role": "human", "content": "i also just moved to SF"}]}
input = {"messages": [{"role": "user", "content": "i also just moved to SF"}]}
# stream values
async for chunk in client.runs.stream(
thread["thread_id"],
@@ -270,7 +270,7 @@ Now, let's run the graph on a completely different thread, and see that it remem
```python
# new thread for new conversation
thread = await client.threads.create()
input = {"messages": [{"role": "human", "content": "where and what should i eat for dinner? Can you list some restaurants?"}]}
input = {"messages": [{"role": "user", "content": "where and what should i eat for dinner? Can you list some restaurants?"}]}
# stream values
async for chunk in client.runs.stream(
thread["thread_id"],
@@ -330,7 +330,7 @@ Now, let's run the graph on a completely different thread, and see that it remem
"assistant_id": "agent",
"input": {
"messages": [{
"role": "human",
"role": "user",
"content": "where and what should i eat for dinner? Can you list some restaurants?"
}]
},
@@ -389,7 +389,7 @@ Let's now run the graph for another user to verify that the preferences of the f
# new thread for new conversation
thread = await client.threads.create()
# create input
input = {"messages": [{"role": "human", "content": "where do I live? what do I like to eat?"}]}
input = {"messages": [{"role": "user", "content": "where do I live? what do I like to eat?"}]}
config = {"configurable": {"user_id": "321"}}
# stream values
async for chunk in client.runs.stream(
+4 -2
View File
@@ -6,6 +6,8 @@ This guide covers how to stream debug events from your graph (`stream_mode="debu
- `task`: These events will get streamed before each super-step, and will contain information about a single task. Each super-step works by executing a list of tasks, where each task is scoped to a specific node and input. Below we will discuss the format of these tasks in more detail.
- `task_result`: After each `task` event, you will see a corresponding `task_result` event which as the name suggests contains information on the results of the task executed in the super-step. Scroll more to learn about the exact structure of these events.
## Setup
First let's set up our client and thread:
=== "Python"
@@ -56,7 +58,7 @@ Output:
'values': None
}
## Stream graph in debug mode
=== "Python"
@@ -65,7 +67,7 @@ Output:
input = {
"messages": [
{
"role": "human",
"role": "user",
"content": "What's the weather in SF?",
}
]
+5 -3
View File
@@ -2,6 +2,8 @@
This guide covers how to stream events from your graph (`stream_mode="events"`). Depending on the use case and user experience of your LangGraph application, your application may process event types differently. Read more about events in this [conceptual guide](https://langchain-ai.github.io/langgraph/concepts/low_level/#astream_events-for-streaming-tokens-of-llm-calls).
## Setup
=== "Python"
```python
@@ -50,7 +52,7 @@ Output:
'values': None
}
## Stream graph in events mode
Streaming events produces responses containing an `event` key (in addition to other keys such as `data`). See the LangChain [`Runnable.astream_events()` reference](https://api.python.langchain.com/en/latest/runnables/langchain_core.runnables.base.Runnable.html#langchain_core.runnables.base.Runnable.astream_events) for all event types.
@@ -62,7 +64,7 @@ Streaming events produces responses containing an `event` key (in addition to ot
input = {
"messages": [
{
"role": "human",
"role": "user",
"content": "What's the weather in SF?",
}
]
@@ -87,7 +89,7 @@ Streaming events produces responses containing an `event` key (in addition to ot
const input = {
"messages": [
{
"role": "human",
"role": "user",
"content": "What's the weather in SF?",
}
]
@@ -38,6 +38,8 @@ With `stream_mode="messages"` two things will be streamed back:
Read more about how the `messages` streaming mode works [here](https://langchain-ai.github.io/langgraph/cloud/concepts/api/#modemessages)
## Setup
First let's set up our client and thread:
=== "Python"
@@ -179,6 +181,7 @@ Let's also define a helper function for better formatting of the tool calls in m
done
```
## Stream graph in messages mode
Now we can stream by messages, which will return complete messages (at the end of node execution) as well as tokens for any messages generated inside a node:
+5 -1
View File
@@ -2,6 +2,8 @@
This guide covers how to configure multiple streaming modes at the same time.
## Setup
First let's set up our client and thread:
=== "Python"
@@ -51,6 +53,8 @@ Output:
'values': None
}
## Stream graph with multiple modes
When configuring multiple streaming modes for a run, responses for each respective mode will be produced. In the following example, note that a `list` of modes (`messages`, `events`, `debug`) is passed to the `stream_mode` parameter and the response contains `events`, `debug`, `messages/complete`, `messages/metadata`, and `messages/partial` event types.
=== "Python"
@@ -60,7 +64,7 @@ When configuring multiple streaming modes for a run, responses for each respecti
input = {
"messages": [
{
"role": "human",
"role": "user",
"content": "What's the weather in SF?",
}
]
+5 -1
View File
@@ -2,6 +2,8 @@
This guide covers how to use `stream_mode="updates"` for your graph, which will stream the updates to the graph state that are made after each node is executed. This differs from using `stream_mode="values"`: instead of streaming the entire value of the state at each superstep, it only streams the updates from each of the nodes that made an update to the state at that superstep. Read [this conceptual guide](https://langchain-ai.github.io/langgraph/concepts/low_level/#stream-and-astream) to learn more.
## Setup
First let's set up our client and thread:
=== "Python"
@@ -51,6 +53,8 @@ Output:
'values': None
}
## Stream graph in updates mode
Now we can stream by updates, which outputs updates made to the state by each node after it has executed:
@@ -60,7 +64,7 @@ Now we can stream by updates, which outputs updates made to the state by each no
input = {
"messages": [
{
"role": "human",
"role": "user",
"content": "what's the weather in la"
}
]
+6 -2
View File
@@ -2,6 +2,8 @@
This guide covers how to use `stream_mode="values"`, which streams the value of the state at each superstep. This differs from using `stream_mode="updates"`: instead of streaming just the updates to the state from each node, it streams the entire graph state at that superstep. Read [this conceptual guide](https://langchain-ai.github.io/langgraph/concepts/low_level/#stream-and-astream) to learn more.
## Setup
First let's set up our client and thread:
=== "Python"
@@ -51,12 +53,14 @@ Output:
'values': None
}
## Stream graph in values mode
Now we can stream by values, which streams the full state of the graph after each node has finished executing:
=== "Python"
```python
input = {"messages": [{"role": "human", "content": "what's the weather in la"}]}
input = {"messages": [{"role": "user", "content": "what's the weather in la"}]}
# stream values
async for chunk in client.runs.stream(
@@ -73,7 +77,7 @@ Now we can stream by values, which streams the full state of the graph after eac
=== "Javascript"
```js
const input = {"messages": [{"role": "human", "content": "what's the weather in la"}]}
const input = {"messages": [{"role": "user", "content": "what's the weather in la"}]}
const streamResponse = client.runs.stream(
thread["thread_id"],
+8 -2
View File
@@ -14,7 +14,11 @@ The following endpoints accept `webhook` as a parameter:
- Stream Run Stateless -> POST /runs/stream
- Wait Run Stateless -> POST /runs/wait
In this example, we will show calling a webhook after streaming a run. First, let's setup our assistant and thread:
In this example, we will show calling a webhook after streaming a run.
## Setup
First, let's setup our assistant and thread:
=== "Python"
@@ -70,13 +74,15 @@ Output:
'values': None
}
## Use graph with a webhook
Now we can invoke a run with a webhook:
=== "Python"
```python
# create input
input = { "messages": [{ "role": "human", "content": "Hello!" }] }
input = { "messages": [{ "role": "user", "content": "Hello!" }] }
async for chunk in client.runs.stream(
thread_id=thread["thread_id"],
+1 -1
View File
@@ -30,7 +30,7 @@ This tutorial will use:
|-- langgraph.json # configuration file for LangGraph
|-- .env # environment files with API keys
2. The `agent.py`/`agent.ts` file should contain code for defining your graph. The following code is a simple example, the important thing is that at some point in your file you compile your graph and assign the compiled graph to a variable (in this case the `graph` variable). This example code uses `create_react_agent`, a prebuilt agent. You can read more about it [here](../concepts/agentic_concepts.md#react-agent).
2. The `agent.py`/`agent.ts` file should contain code for defining your graph. The following code is a simple example, the important thing is that at some point in your file you compile your graph and assign the compiled graph to a variable (in this case the `graph` variable). This example code uses `create_react_agent`, a prebuilt agent. You can read more about it [here](../concepts/agentic_concepts.md#react-implementation).
=== "Python"
+275 -127
View File
@@ -504,61 +504,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Config"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
},
"patch": {
"tags": [
"threads/state"
],
"summary": "Patch Thread State",
"description": "Patch state for a thread.",
"operationId": "patch_thread_state_threads__thread_id__state_patch",
"parameters": [
{
"description": "The ID of the thread.",
"required": true,
"schema": {
"type": "string",
"format": "uuid",
"title": "Thread Id",
"description": "The ID of the thread."
},
"name": "thread_id",
"in": "path"
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ThreadStatePatch"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Config"
"$ref": "#/components/schemas/ThreadStateUpdateResponse"
}
}
}
@@ -905,8 +851,8 @@
"tags": [
"runs/manage"
],
"summary": "List Runs Http",
"description": "List all runs for a thread.",
"summary": "List Runs",
"description": "List runs for a thread.",
"operationId": "list_runs_http_threads__thread_id__runs_get",
"parameters": [
{
@@ -951,8 +897,7 @@
"items": {
"$ref": "#/components/schemas/Run"
},
"type": "array",
"title": "Response List Runs Http Threads Thread Id Runs Get"
"type": "array"
}
}
}
@@ -973,8 +918,8 @@
"tags": [
"runs/create"
],
"summary": "Create Run",
"description": "Create a run.",
"summary": "Create Background Run",
"description": "Create a run, return immediately.",
"operationId": "create_run_threads__thread_id__runs_post",
"parameters": [
{
@@ -994,7 +939,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RunCreate"
"$ref": "#/components/schemas/RunCreateStateful"
}
}
},
@@ -1030,7 +975,7 @@
"runs/create"
],
"summary": "Create Thread Cron",
"description": "Create a thread specific cron.",
"description": "Create a cron to schedule runs on a thread.",
"operationId": "create_thread_cron_threads__thread_id__runs_crons_post",
"parameters": [
{
@@ -1085,8 +1030,8 @@
"tags": [
"runs/create"
],
"summary": "Stream Run",
"description": "Create a run.",
"summary": "Create Streaming Run",
"description": "Create a run, stream the output.",
"operationId": "stream_run_threads__thread_id__runs_stream_post",
"parameters": [
{
@@ -1106,7 +1051,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RunStream"
"$ref": "#/components/schemas/RunCreateStateful"
}
}
},
@@ -1139,8 +1084,8 @@
"tags": [
"runs/create"
],
"summary": "Wait Run",
"description": "Create a run, wait for the output.",
"summary": "Create Run and Get Output",
"description": "Create a run, return the final output.",
"operationId": "wait_run_threads__thread_id__runs_wait_post",
"parameters": [
{
@@ -1160,7 +1105,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RunCreate"
"$ref": "#/components/schemas/RunCreateStateful"
}
}
},
@@ -1193,7 +1138,7 @@
"tags": [
"runs/manage"
],
"summary": "Get Run Http",
"summary": "Get Run",
"description": "Get a run by ID.",
"operationId": "get_run_http_threads__thread_id__runs__run_id__get",
"parameters": [
@@ -1305,7 +1250,7 @@
"tags": [
"runs/manage"
],
"summary": "Join Run Http",
"summary": "Join Run",
"description": "Wait for a run to finish.",
"operationId": "join_run_http_threads__thread_id__runs__run_id__join_get",
"parameters": [
@@ -1356,12 +1301,68 @@
}
}
},
"/threads/{thread_id}/runs/{run_id}/stream": {
"get": {
"tags": [
"runs/manage"
],
"summary": "Join Run Stream",
"description": "Join a run stream. This endpoint streams output in real-time from a run similar to the /threads/__THREAD_ID__/runs/stream endpoint. Only output produced after this endpoint is called will be streamed.",
"operationId": "stream_run_http_threads__thread_id__runs__run_id__join_get",
"parameters": [
{
"description": "The ID of the thread.",
"required": true,
"schema": {
"type": "string",
"format": "uuid",
"title": "Thread Id",
"description": "The ID of the thread."
},
"name": "thread_id",
"in": "path"
},
{
"description": "The ID of the run.",
"required": true,
"schema": {
"type": "string",
"format": "uuid",
"title": "Run Id",
"description": "The ID of the run."
},
"name": "run_id",
"in": "path"
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/threads/{thread_id}/runs/{run_id}/cancel": {
"post": {
"tags": [
"runs/manage"
],
"summary": "Cancel Run Http",
"summary": "Cancel Run",
"operationId": "cancel_run_http_threads__thread_id__runs__run_id__cancel_post",
"parameters": [
{
@@ -1427,7 +1428,7 @@
"runs/create"
],
"summary": "Create Cron",
"description": "Create a cron with new thread.",
"description": "Create a cron to schedule runs on new threads.",
"operationId": "create_cron_runs_crons_post",
"requestBody": {
"content": {
@@ -1514,14 +1515,14 @@
"tags": [
"runs/create"
],
"summary": "Stream Run Stateless",
"description": "Create a stateless run.",
"summary": "Stream Run in new Thread",
"description": "Create a run in a new thread, stream the output.",
"operationId": "stream_run_stateless_runs_stream_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RunStream"
"$ref": "#/components/schemas/RunCreateStateless"
}
}
},
@@ -1554,14 +1555,14 @@
"tags": [
"runs/create"
],
"summary": "Wait Run Stateless",
"description": "Create a stateless run, wait for the output.",
"summary": "Create Run in new Thread and Get Output",
"description": "Create a run in a new thread, return the final output.",
"operationId": "wait_run_stateless_runs_wait_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RunCreate"
"$ref": "#/components/schemas/RunCreateStateless"
}
}
},
@@ -1594,14 +1595,54 @@
"tags": [
"runs/create"
],
"summary": "Run Stateless",
"description": "Create a stateless run that will run in the background.",
"summary": "Create Background Run in new Thread",
"description": "Create a run in a new thread, return immediately.",
"operationId": "run_stateless_runs_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RunCreate"
"$ref": "#/components/schemas/RunCreateStateless"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/runs/batch": {
"post": {
"tags": [
"runs/create"
],
"summary": "Create Run Batch",
"description": "Create a batch of runs in new threads, return immediately.",
"operationId": "run_batch_stateless_runs_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RunBatchCreate"
}
}
},
@@ -1966,7 +2007,7 @@
"title": "CronCreate",
"description": "Payload for creating a cron."
},
"CronSearch" : {
"CronSearch": {
"properties": {
"assistant_id": {
"type": "string",
@@ -1995,7 +2036,7 @@
}
},
"type": "object",
"required" : [],
"required": [],
"title": "CronSearch",
"description": "Payload for listing crons"
},
@@ -2005,6 +2046,14 @@
"type": "string",
"title": "Graph Id"
},
"input_schema": {
"type": "object",
"title": "Input Schema"
},
"output_schema": {
"type": "object",
"title": "Input Schema"
},
"state_schema": {
"type": "object",
"title": "State Schema"
@@ -2066,7 +2115,6 @@
"type": "string",
"enum": [
"pending",
"running",
"error",
"success",
"timeout",
@@ -2107,7 +2155,7 @@
],
"title": "Run"
},
"RunCreate": {
"RunCreateStateful": {
"properties": {
"assistant_id": {
"anyOf": [
@@ -2210,6 +2258,53 @@
],
"title": "Interrupt After"
},
"stream_mode": {
"anyOf": [
{
"items": {
"type": "string",
"enum": [
"values",
"messages",
"updates",
"events",
"debug"
]
},
"type": "array"
},
{
"type": "string",
"enum": [
"values",
"messages",
"updates",
"events",
"debug"
]
}
],
"title": "Stream Mode",
"default": [
"values"
]
},
"on_disconnect": {
"type": "string",
"enum": [
"cancel",
"continue"
],
"title": "On Disconnect",
"default": "cancel"
},
"feedback_keys": {
"items": {
"type": "string"
},
"type": "array",
"title": "Feedback Keys"
},
"multitask_strategy": {
"type": "string",
"enum": [
@@ -2226,10 +2321,19 @@
"required": [
"assistant_id"
],
"title": "RunCreate",
"title": "RunCreateStateful",
"description": "Payload for creating a run."
},
"RunStream": {
"RunBatchCreate": {
"type": "array",
"items": {
"$ref": "#/components/schemas/RunCreateStateless"
},
"minItems": 1,
"title": "RunBatchCreate",
"description": "Payload for creating a batch of runs."
},
"RunCreateStateless": {
"properties": {
"assistant_id": {
"anyOf": [
@@ -2244,10 +2348,6 @@
}
]
},
"checkpoint_id": {
"type": "string",
"title": "Checkpoint Id"
},
"input": {
"anyOf": [
{
@@ -2332,17 +2432,6 @@
],
"title": "Interrupt After"
},
"multitask_strategy": {
"type": "string",
"enum": [
"reject",
"rollback",
"interrupt",
"enqueue"
],
"title": "Multitask Strategy",
"default": "reject"
},
"stream_mode": {
"anyOf": [
{
@@ -2380,13 +2469,31 @@
},
"type": "array",
"title": "Feedback Keys"
},
"on_completion": {
"type": "string",
"enum": [
"delete",
"keep"
],
"title": "On Completion",
"default": "delete"
},
"on_disconnect": {
"type": "string",
"enum": [
"cancel",
"continue"
],
"title": "On Disconnect",
"default": "cancel"
}
},
"type": "object",
"required": [
"assistant_id"
],
"title": "RunStream",
"title": "RunCreateStateless",
"description": "Payload for creating a streaming run."
},
"SearchRequest": {
@@ -2453,14 +2560,20 @@
"metadata": {
"type": "object",
"title": "Metadata",
"description": "Metadata to search for."
"description": "Metadata to filter on."
},
"values": {
"type": "object",
"title": "Values",
"description": "State values to filter on."
},
"status": {
"type": "string",
"enum": [
"idle",
"busy",
"interrupted"
"interrupted",
"error"
],
"title": "Status",
"description": "Filter by thread status."
@@ -2511,9 +2624,14 @@
"enum": [
"idle",
"busy",
"interrupted"
"interrupted",
"error"
],
"title": "Status"
},
"values": {
"type": "object",
"title": "Values"
}
},
"type": "object",
@@ -2521,7 +2639,8 @@
"thread_id",
"created_at",
"updated_at",
"metadata"
"metadata",
"status"
],
"title": "Thread"
},
@@ -2578,6 +2697,35 @@
"type": "array",
"title": "Next"
},
"tasks": {
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"title": "Task Id"
},
"name": {
"type": "string",
"title": "Node Name"
},
"error": {
"type": "string",
"title": "Error"
},
"interrupts": {
"type": "array",
"items": {}
}
},
"required": [
"id",
"name"
]
},
"type": "array",
"title": "Tasks"
},
"checkpoint_id": {
"type": "string",
"title": "Checkpoint Id"
@@ -2601,25 +2749,10 @@
"next",
"checkpoint_id",
"metadata",
"created_at",
"parent_checkpoint_id"
"created_at"
],
"title": "ThreadState"
},
"ThreadStatePatch": {
"properties": {
"metadata": {
"type": "object",
"title": "Metadata"
}
},
"type": "object",
"required": [
"metadata"
],
"title": "ThreadStatePatch",
"description": "Payload for patching state of a thread."
},
"ThreadStateSearch": {
"properties": {
"limit": {
@@ -2656,6 +2789,9 @@
},
{
"type": "object"
},
{
"type": "null"
}
],
"title": "Values"
@@ -2670,9 +2806,21 @@
}
},
"type": "object",
"required": [
"values"
],
"title": "ThreadStateUpdate",
"description": "Payload for adding state to a thread."
},
"ThreadStateUpdateResponse": {
"properties": {
"checkpoint_id": {
"type": "string",
"title": "Checkpoint Id"
},
"as_node": {
"type": "string",
"title": "As Node"
}
},
"type": "object",
"title": "ThreadStateUpdate",
"description": "Payload for adding state to a thread."
},
+6
View File
@@ -2,6 +2,12 @@
The LangGraph Cloud API supports specific environment variables for configuring a deployment.
## `LANGCHAIN_TRACING_SAMPLING_RATE`
Sampling rate for traces sent to LangSmith. Valid values: Any float between `0` and `1`.
See <a href="https://docs.smith.langchain.com/how_to_guides/tracing/sample_traces" target="_blank">LangSmith documentation</a> for more details.
## `LANGGRAPH_AUTH_TYPE`
Type of authentication for the LangGraph Cloud API deployment. Valid values: `langsmith`, `noop`.