Compare commits

..
Author SHA1 Message Date
William Fu-Hinthorn 2f47d98b34 Update error message for missing dev command 2025-01-14 11:28:51 -08:00
Vadym BardaandGitHub b989502c24 checkpoint-sqlite/postgres: handle calling .list on async checkpointer (#3019) 2025-01-14 19:06:11 +00:00
Eugene YurtsevandGitHub 8507dc33f0 FIx docs: Update MULTIPLE_SUBGRAPHS.md (#3016) 2025-01-14 13:41:50 -05:00
Vadym BardaandGitHub a11ba2b38a docs: update replay in the concept docs (#3017) 2025-01-14 11:53:53 -05:00
Cesar William AlvarengaandGitHub a61ea101f6 fix: add missing END constant import (#3011) 2025-01-13 19:40:40 -05:00
Andrew NguonlyandGitHub c86155d3d3 docs: Add note about LangGraph Platform UI not available for self-hosted deployments (#3009)
Example screenshot:

![image](https://github.com/user-attachments/assets/8304b08d-bc9b-4cd3-8ff4-ed2471d3d6c7)
2025-01-13 13:05:18 -08:00
William FHandGitHub a03f1f7469 Bullseye (#3008) 2025-01-13 10:01:36 -08:00
Jimmy SambuoandGitHub d7199e5874 docs: use InjectedStore in semantic search guide (#2995)
When I tried to follow the How-to guide for [How to add semantic search
to your agent's
memory](https://langchain-ai.github.io/langgraph/how-tos/memory/semantic-search/#using-in-create_react_agent)
using `create_react_agent`, I got this error message when my agent used
the tool:

```python
1 validation error for upsert_memory
store
  Field required [type=missing, input_value={'content': '@jimmy works...ny.', 'memory_id': None}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missingTraceback (most recent call last):

  File "/usr/local/lib/python3.9/site-packages/langchain_core/tools/base.py", line 688, in run
    tool_args, tool_kwargs = self._to_args_and_kwargs(tool_input, tool_call_id)

  File "/usr/local/lib/python3.9/site-packages/langchain_core/tools/base.py", line 611, in _to_args_and_kwargs
    tool_input = self._parse_input(tool_input, tool_call_id)

  File "/usr/local/lib/python3.9/site-packages/langchain_core/tools/base.py", line 532, in _parse_input
    result = input_args.model_validate(tool_input)

  File "/usr/local/lib/python3.9/site-packages/pydantic/main.py", line 627, in model_validate
    return cls.__pydantic_validator__.validate_python(

pydantic_core._pydantic_core.ValidationError: 1 validation error for upsert_memory
store
  Field required [type=missing, input_value={'content': '@jimmy works...ny.', 'memory_id': None}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing
```

I believe it’s because the graph did not inject the store into the tool
if we use `InjectedToolArg`.

When looking at the guide for [How to pass runtime values to
tools](https://langchain-ai.github.io/langgraph/how-tos/pass-run-time-values-to-tools/),
it suggests to use `InjectedStore` with `create_react_agent`. After
changing my code to use `InjectedStore`, my agent was able to save to
the store.
2025-01-13 09:59:46 -05:00
Siddhesh dosiandGitHub 61f2151df7 Update customer-support.ipynb minor spell (#3002)
There was spelling mistake.
2025-01-13 09:52:19 -05:00
William FHandGitHub 713528ffc3 Add admonition regarding dockerfile usage (#3001) 2025-01-12 09:52:13 -08:00
Andrew NguonlyandGitHub 7bd79c2509 docs: Add docs for LANGCHAIN_ENDPOINT for self-hosted deployments (#2988)
@langchain-infra, is this correct? Is this needed or is it
redundant/unnecessary?
2025-01-10 15:24:38 -08:00
Andrew NguonlyandGitHub 9974787df6 docs: Add API docs for POST /v1/projects/{project_id}/revisions/{revision_id}/deploy endpoint (#2994) 2025-01-10 15:16:48 -08:00
William FHandGitHub 638712a73b Add support for custom fetch implementation (#2993) 2025-01-10 23:08:33 +00:00
30 changed files with 2227 additions and 117 deletions
+23 -1
View File
@@ -109,9 +109,31 @@ jobs:
- name: Build
run: yarn build
test-js:
runs-on: ubuntu-latest
strategy:
matrix:
working-directory:
- "libs/sdk-js"
defaults:
run:
working-directory: ${{ matrix.working-directory }}
steps:
- uses: actions/checkout@v3
- name: Setup Node.js (LTS)
uses: actions/setup-node@v3
with:
node-version: "20"
cache: "yarn"
cache-dependency-path: ${{ matrix.working-directory }}/yarn.lock
- name: Install dependencies
run: yarn install
- name: Run tests
run: yarn test
ci_success:
name: "CI Success"
needs: [lint, lint-js, test, test-langgraph, test-scheduler-kafka, integration-test]
needs: [lint, lint-js, test, test-langgraph, test-scheduler-kafka, integration-test, test-js]
if: |
always()
runs-on: ubuntu-latest
@@ -279,6 +279,58 @@
}
}
},
"/v1/projects/{project_id}/revisions/{revision_id}/deploy": {
"post": {
"tags": ["Revisions (v1)"],
"summary": "Deploy Revision",
"description": "Deploy revision by ID.\n\nThis endpoint redeploys the deployment of a revision without rebuilding the image for the deployment. Redeploying the deployment of a revision may mitigate intermittent issues with a deployment.\n\nThe revision must be in the `DEPLOYED` status and must be the latest revision of the project.",
"operationId": "deploy_revision_projects__project_id__revisions__revision_id__deploy_post",
"parameters": [
{
"required": true,
"schema": {
"type": "string",
"format": "uuid",
"title": "Project ID"
},
"name": "project_id",
"in": "path"
},
{
"required": true,
"schema": {
"type": "string",
"format": "uuid",
"title": "Revision ID"
},
"name": "revision_id",
"in": "path"
}
],
"responses": {
"400": {
"description": "Revision is not in DEPLOYED status or revision is not the latest revision for the project.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
},
"404": {
"description": "Revision not found.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
}
}
},
"/v1/projects/{project_id}/revisions/{revision_id}/interrupt": {
"post": {
"tags": ["Revisions (v1)"],
@@ -319,31 +371,6 @@
}
},
"schemas": {
"EnvVar": {
"type": "object",
"description": "An environment variable or secret.",
"properties": {
"name": {
"type": "string",
"description": "Environment variable or secret name.",
"required": true
},
"value": {
"type": "string",
"description": "Environment variable or secret value.",
"required": true
},
"type": {
"type": "string",
"enum": [
"default",
"secret"
],
"description": "Field to designate type of the environment variable (default) or secret.",
"required": true
}
}
},
"ContainerSpec": {
"type": "object",
"description": "Container specification for a revision's deployment.\n\nIf any field is omitted or set to `null`, the internal default value is used depending on the deployment type (`dev` or `prod`).",
@@ -404,6 +431,42 @@
}
}
},
"EnvVar": {
"type": "object",
"description": "An environment variable or secret.",
"properties": {
"name": {
"type": "string",
"description": "Environment variable or secret name.",
"required": true
},
"value": {
"type": "string",
"description": "Environment variable or secret value.",
"required": true
},
"type": {
"type": "string",
"enum": [
"default",
"secret"
],
"description": "Field to designate type of the environment variable (default) or secret.",
"required": true
}
}
},
"ErrorResponse": {
"type": "object",
"description": "Error response.",
"properties": {
"detail": {
"type": "string",
"description": "Error details.",
"required": true
}
}
},
"Project": {
"type": "object",
"description": "A project corresponds to a LangGraph Server deployment and the associated LangSmith tracing project.",
+4 -1
View File
@@ -289,4 +289,7 @@ RUN set -ex && \
RUN PIP_CONFIG_FILE=/pipconfig.txt PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/*
ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_graphs/src/agent.py:graph", "storm": "/deps/__outer_graphs/src/storm.py:graph"}'
```
```
???+ note "Updating your langgraph.json file"
The `langgraph dockerfile` command translates all the configuration in your `langgraph.json` file into Dockerfile commands. When using this command, you will have to re-run it whenever you update your `langgraph.json` file. Otherwise, your changes will not be reflected when you build or run the dockerfile.
+10 -3
View File
@@ -28,6 +28,10 @@ The guide below will explain the differences between the deployment options.
The Self-Hosted Enterprise version is only available for the **Enterprise** plan.
!!! warning "Note"
The LangGraph Platform Deployments view (within LangSmith SaaS and self-hosted LangSmith) is not available for Self-Hosted Enterprise LangGraph deployments. Self-hosted LangGraph deployments are managed externally from LangSmith (e.g. there is no UI to manage these deployments).
With a Self-Hosted Enterprise deployment, you are responsible for managing the infrastructure, including setting up and maintaining required databases and Redis instances.
Youll build a Docker image using the [LangGraph CLI](./langgraph_cli.md), which can then be deployed on your own infrastructure.
@@ -43,6 +47,10 @@ For more information, please see:
The Self-Hosted Lite version is available for all plans.
!!! warning "Note"
The LangGraph Platform Deployments view (within LangSmith SaaS and self-hosted LangSmith) is not available for Self-Hosted Lite LangGraph deployments. Self-hosted LangGraph deployments are managed externally from LangSmith (e.g. there is no UI to manage these deployments).
The Self-Hosted Lite deployment option is a free (up to 1 million nodes executed), limited version of LangGraph Platform that you can run locally or in a self-hosted manner.
With a Self-Hosted Lite deployment, you are responsible for managing the infrastructure, including setting up and maintaining required databases and Redis instances.
@@ -61,12 +69,11 @@ For more information, please see:
The Cloud SaaS version of LangGraph Platform is only available for **Plus** and **Enterprise** plans.
The [Cloud SaaS](./langgraph_cloud.md) version of LangGraph Platform is hosted as part of [LangSmith](https://smith.langchain.com/).
The Cloud SaaS version of LangGraph Platform provides a simple way to deploy and manage your LangGraph applications.
This deployment option provides an integration with GitHub, allowing you to deploy code from any of your repositories on GitHub.
This deployment option provides access to the LangGraph Platform UI (within LangSmith) and an integration with GitHub, allowing you to deploy code from any of your repositories on GitHub.
For more information, please see:
@@ -81,7 +88,7 @@ For more information, please see:
The Bring Your Own Cloud version of LangGraph Platform is only available for **Enterprise** plans.
This combines the best of both worlds for Cloud and Self-Hosted. We manage the infrastructure, so you don't have to, but the infrastructure all runs within your cloud. This is currently only available on AWS.
This combines the best of both worlds for Cloud and Self-Hosted. Create your deployments through the LangGraph Platform UI (within LangSmith) and we manage the infrastructure so you don't have to. The infrastructure all runs within your cloud. This is currently only available on AWS.
For more information please see:
Binary file not shown.

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 214 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 397 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 KiB

+3
View File
@@ -62,6 +62,9 @@ The server includes all API endpoints for your graph's runs, threads, assistants
The `langgraph dockerfile` command generates a [Dockerfile](https://docs.docker.com/reference/dockerfile/) that can be used to build images for and deploy instances of the [LangGraph API server](./langgraph_server.md). This is useful if you want to further customize the dockerfile or deploy in a more custom way.
??? note "Updating your langgraph.json file"
The `langgraph dockerfile` command translates all the configuration in your `langgraph.json` file into Dockerfile commands. When using this command, you will have to re-run it whenever you update your `langgraph.json` file. Otherwise, your changes will not be reflected when you build or run the dockerfile.
## Related
- [LangGraph CLI API Reference](../cloud/reference/cli.md)
+1 -1
View File
@@ -112,7 +112,7 @@ In this architecture, agents are defined as graph nodes. Each agent can communic
```python
from typing import Literal
from langchain_openai import ChatOpenAI
from langgraph.graph import StateGraph, MessagesState, START
from langgraph.graph import StateGraph, MessagesState, START, END
model = ChatOpenAI()
+6 -9
View File
@@ -147,24 +147,21 @@ In our example, the output of `get_state_history` will look like this:
### Replay
It's also possible to play-back a prior graph execution. If we `invoking` a graph with a `thread_id` and a `checkpoint_id`, then we will *re-play* the graph from a checkpoint that corresponds to the `checkpoint_id`.
It's also possible to play-back a prior graph execution. If we `invoke` a graph with a `thread_id` and a `checkpoint_id`, then we will *re-play* the previously executed steps _before_ a checkpoint that corresponds to the `checkpoint_id`, and only execute the steps _after_ the checkpoint.
* `thread_id` is simply the ID of a thread. This is always required.
* `checkpoint_id` This identifier refers to a specific checkpoint within a thread.
* `thread_id` is the ID of a thread.
* `checkpoint_id` is an identifier that refers to a specific checkpoint within a thread.
You must pass these when invoking the graph as part of the `configurable` portion of the config:
```python
# {"configurable": {"thread_id": "1"}} # valid config
# {"configurable": {"thread_id": "1", "checkpoint_id": "0c62ca34-ac19-445d-bbb0-5b4984975b2a"}} # also valid config
config = {"configurable": {"thread_id": "1"}}
config = {"configurable": {"thread_id": "1", "checkpoint_id": "0c62ca34-ac19-445d-bbb0-5b4984975b2a"}}
graph.invoke(None, config=config)
```
Importantly, LangGraph knows whether a particular checkpoint has been executed previously. If it has, LangGraph simply *re-plays* that particular step in the graph and does not re-execute the step. See this [how to guide on time-travel to learn more about replaying](../how-tos/human_in_the_loop/time-travel.ipynb).
Importantly, LangGraph knows whether a particular step has been executed previously. If it has, LangGraph simply *re-plays* that particular step in the graph and does not re-execute the step, but only for the steps _before_ the provided `checkpoint_id`. All of the steps _after_ `checkpoint_id` will be executed (i.e., a new fork), even if they have been executed previously. See this [how to guide on time-travel to learn more about replaying](../how-tos/human_in_the_loop/time-travel.ipynb).
![Replay](img/persistence/re_play.jpg)
![Replay](img/persistence/re_play.png)
### Update state
+4
View File
@@ -32,6 +32,10 @@ To use the Self-Hosted Enterprise version, you must acquire a license key that y
- Build the docker image for [LangGraph Server](./langgraph_server.md) using the [LangGraph CLI](./langgraph_cli.md).
- Deploy a web server that will run the docker image and pass in the necessary environment variables.
!!! warning "Note"
The LangGraph Platform Deployments view (within LangSmith SaaS and self-hosted LangSmith) is not available for Self-Hosted Lite or Self-Hosted Enterprise LangGraph deployments. Self-hosted LangGraph deployments are managed externally from LangSmith (e.g. there is no UI to manage these deployments).
For step-by-step instructions, see [How to set up a self-hosted deployment of LangGraph](../how-tos/deploy-self-hosted.md).
## Helm Chart
+3 -11
View File
@@ -17,17 +17,9 @@ We call these debugging techniques **Time Travel**, composed of two key actions:
![](./img/human_in_the_loop/replay.png)
Replaying allows us to revisit and reproduce an agent's past actions. This can be done either from the current state (or checkpoint) of the graph or from a specific checkpoint.
Replaying allows us to revisit and reproduce an agent's past actions, up to and including a specific step (checkpoint).
To replay from the current state, simply pass `None` as the input along with a `thread`:
```python
thread = {"configurable": {"thread_id": "1"}}
for event in graph.stream(None, thread, stream_mode="values"):
print(event)
```
To replay actions from a specific checkpoint, start by retrieving all checkpoints for the thread:
To replay actions before a specific checkpoint, start by retrieving all checkpoints for the thread:
```python
all_checkpoints = []
@@ -43,7 +35,7 @@ for event in graph.stream(None, config, stream_mode="values"):
print(event)
```
The graph efficiently replays previously executed nodes instead of re-executing them, leveraging its awareness of prior checkpoint executions.
The graph replays previously executed steps _before_ the provided `checkpoint_id` and executes the steps _after_ `checkpoint_id` (i.e., a new fork), even if they have been executed previously.
## Forking
+1
View File
@@ -29,6 +29,7 @@ You will eventually need to pass in the following environment variables to the L
- `DATABASE_URI`: Postgres connection details. Postgres will be used to store assistants, threads, runs, persist thread state and long term memory, and to manage the state of the background task queue with 'exactly once' semantics.
- `LANGSMITH_API_KEY`: (If using [Self-Hosted Lite](../concepts/deployment_options.md#self-hosted-lite)) LangSmith API key. This will be used to authenticate ONCE at server start up.
- `LANGGRAPH_CLOUD_LICENSE_KEY`: (If using [Self-Hosted Enterprise](../concepts/deployment_options.md#self-hosted-enterprise)) LangGraph Platform license key. This will be used to authenticate ONCE at server start up.
- `LANGCHAIN_ENDPOINT`: To send traces to a [self-hosted LangSmith](https://docs.smith.langchain.com/self_hosting) instance, set `LANGCHAIN_ENDPOINT` to the hostname of the self-hosted LangSmith instance.
## Build the Docker Image
@@ -208,7 +208,7 @@
"from typing import Optional\n",
"\n",
"from langchain.chat_models import init_chat_model\n",
"from langchain_core.tools import InjectedToolArg\n",
"from langgraph.prebuilt import InjectedStore\n",
"from langgraph.store.base import BaseStore\n",
"from typing_extensions import Annotated\n",
"\n",
@@ -232,7 +232,7 @@
" content: str,\n",
" *,\n",
" memory_id: Optional[uuid.UUID] = None,\n",
" store: Annotated[BaseStore, InjectedToolArg],\n",
" store: Annotated[BaseStore, InjectedStore],\n",
"):\n",
" \"\"\"Upsert a memory in the database.\"\"\"\n",
" # The LLM can use this tool to store a new memory\n",
@@ -1,6 +1,6 @@
# MULTIPLE_SUBGRAPHS
You are calling the same subgraph multiple times within a single LangGraph node with checkpointing enabled for each subgraph.
You are calling subgraphs multiple times within a single LangGraph node with checkpointing enabled for each subgraph.
This is currently not allowed due to internal restrictions on how checkpoint namespacing for subgraphs works.
@@ -9,4 +9,4 @@ This is currently not allowed due to internal restrictions on how checkpoint nam
The following may help resolve this error:
- If you don't need to interrupt/resume from a subgraph, pass `checkpointer=False` when compiling it like this: `.compile(checkpointer=False)`
- Don't imperatively call graphs multiple times in the same node, and instead use the [`Send`](https://langchain-ai.github.io/langgraph/concepts/low_level/#send) API.
- Don't imperatively call graphs multiple times in the same node, and instead use the [`Send`](https://langchain-ai.github.io/langgraph/concepts/low_level/#send) API.
@@ -246,7 +246,7 @@
"\n",
"Define the (`fetch_user_flight_information`) tool to let the agent see the current user's flight information. Then define tools to search for flights and manage the passenger's bookings stored in the SQL database.\n",
"\n",
"We the can [access the RunnableConfig](https://python.langchain.com/docs/how_to/tool_configure/#inferring-by-parameter-type) for a given run to check the `passenger_id` of the user accessing this application. The LLM never has to provide these explicitly, they are provided for a given invocation of the graph so that each user cannot access other passengers' booking information.\n",
"We then can [access the RunnableConfig](https://python.langchain.com/docs/how_to/tool_configure/#inferring-by-parameter-type) for a given run to check the `passenger_id` of the user accessing this application. The LLM never has to provide these explicitly, they are provided for a given invocation of the graph so that each user cannot access other passengers' booking information.\n",
"\n",
"<div class=\"admonition warning\">\n",
" <p class=\"admonition-title\">Compatibility</p>\n",
@@ -380,6 +380,18 @@ class AsyncPostgresSaver(BasePostgresSaver):
Yields:
Iterator[CheckpointTuple]: An iterator of matching checkpoint tuples.
"""
try:
# check if we are in the main thread, only bg threads can block
# we don't check in other methods to avoid the overhead
if asyncio.get_running_loop() is self.loop:
raise asyncio.InvalidStateError(
"Synchronous calls to AsyncSqliteSaver are only allowed from a "
"different thread. From the main thread, use the async interface. "
"For example, use `checkpointer.alist(...)` or `await "
"graph.ainvoke(...)`."
)
except RuntimeError:
pass
aiter_ = self.alist(config, filter=filter, before=before, limit=limit)
while True:
try:
@@ -410,7 +422,7 @@ class AsyncPostgresSaver(BasePostgresSaver):
if asyncio.get_running_loop() is self.loop:
raise asyncio.InvalidStateError(
"Synchronous calls to AsyncPostgresSaver are only allowed from a "
"different thread. From the main thread, use the async interface."
"different thread. From the main thread, use the async interface. "
"For example, use `await checkpointer.aget_tuple(...)` or `await "
"graph.ainvoke(...)`."
)
@@ -159,7 +159,7 @@ class AsyncSqliteSaver(BaseCheckpointSaver[str]):
if asyncio.get_running_loop() is self.loop:
raise asyncio.InvalidStateError(
"Synchronous calls to AsyncSqliteSaver are only allowed from a "
"different thread. From the main thread, use the async interface."
"different thread. From the main thread, use the async interface. "
"For example, use `await checkpointer.aget_tuple(...)` or `await "
"graph.ainvoke(...)`."
)
@@ -191,6 +191,18 @@ class AsyncSqliteSaver(BaseCheckpointSaver[str]):
Yields:
Iterator[CheckpointTuple]: An iterator of matching checkpoint tuples.
"""
try:
# check if we are in the main thread, only bg threads can block
# we don't check in other methods to avoid the overhead
if asyncio.get_running_loop() is self.loop:
raise asyncio.InvalidStateError(
"Synchronous calls to AsyncSqliteSaver are only allowed from a "
"different thread. From the main thread, use the async interface. "
"For example, use `checkpointer.alist(...)` or `await "
"graph.ainvoke(...)`."
)
except RuntimeError:
pass
aiter_ = self.alist(config, filter=filter, before=before, limit=limit)
while True:
try:
+6 -42
View File
@@ -1,18 +1,7 @@
import asyncio
import functools
import weakref
import sys
from typing import (
Any,
Callable,
Iterable,
Literal,
Optional,
TypeVar,
Union,
AsyncIterator,
)
from contextlib import asynccontextmanager
from typing import Any, Callable, Iterable, Literal, Optional, TypeVar, Union
from langgraph.store.base import (
BaseStore,
@@ -28,15 +17,9 @@ from langgraph.store.base import (
SearchOp,
_validate_namespace,
)
import asyncio
import logging
logger = logging.getLogger(__name__)
F = TypeVar("F", bound=Callable)
SUPPORTS_EXC_NOTES = sys.version_info >= (3, 11)
def _check_loop(func: F) -> F:
@functools.wraps(func)
@@ -84,8 +67,7 @@ class AsyncBatchedBaseStore(BaseStore):
) -> Optional[Item]:
fut = self._loop.create_future()
self._aqueue[fut] = GetOp(namespace, key)
async with _raise_with_queue_stats(self._aqueue):
return await fut
return await fut
async def asearch(
self,
@@ -99,8 +81,7 @@ class AsyncBatchedBaseStore(BaseStore):
) -> list[SearchItem]:
fut = self._loop.create_future()
self._aqueue[fut] = SearchOp(namespace_prefix, filter, limit, offset, query)
async with _raise_with_queue_stats(self._aqueue):
return await fut
return await fut
async def aput(
self,
@@ -112,8 +93,7 @@ class AsyncBatchedBaseStore(BaseStore):
_validate_namespace(namespace)
fut = self._loop.create_future()
self._aqueue[fut] = PutOp(namespace, key, value, index)
async with _raise_with_queue_stats(self._aqueue):
return await fut
return await fut
async def adelete(
self,
@@ -122,8 +102,7 @@ class AsyncBatchedBaseStore(BaseStore):
) -> None:
fut = self._loop.create_future()
self._aqueue[fut] = PutOp(namespace, key, None)
async with _raise_with_queue_stats(self._aqueue):
return await fut
return await fut
async def alist_namespaces(
self,
@@ -148,8 +127,7 @@ class AsyncBatchedBaseStore(BaseStore):
offset=offset,
)
self._aqueue[fut] = op
async with _raise_with_queue_stats(self._aqueue):
return await fut
return await fut
@_check_loop
def batch(self, ops: Iterable[Op]) -> list[Result]:
@@ -303,17 +281,3 @@ async def _run(
break
# remove strong ref to store
del s
@asynccontextmanager
async def _raise_with_queue_stats(
queue: dict[asyncio.Future, Op]
) -> AsyncIterator[None]:
try:
yield
except asyncio.CancelledError as e:
if SUPPORTS_EXC_NOTES:
e.add_note(f"Queue size: {len(queue)}")
else:
logger.warning(f"Queue size: {len(queue)}")
raise
+11 -1
View File
@@ -575,6 +575,13 @@ def dev(
try:
from langgraph_api.cli import run_server
except ImportError:
py_version_msg = ""
if sys.version_info < (3, 11):
py_version_msg = (
"\n\nNote: The in-mem server requires Python 3.11 or higher to be installed."
f" You are currently using Python {sys.version_info.major}.{sys.version_info.minor}."
' Please upgrade your Python version before installing "langgraph-cli[inmem]".'
)
try:
from importlib import util
@@ -582,16 +589,19 @@ def dev(
raise click.UsageError(
"Required package 'langgraph-api' is not installed.\n"
"Please install it with:\n\n"
' pip install -U "langgraph-cli[inmem]"\n\n'
' pip install -U "langgraph-cli[inmem]"'
f"{py_version_msg}"
) from None
except ImportError:
raise click.UsageError(
"Could not verify package installation. Please ensure Python is up to date and\n"
"langgraph-cli is installed with the 'inmem' extra: pip install -U \"langgraph-cli[inmem]\""
f"{py_version_msg}"
) from None
raise click.UsageError(
"Could not import run_server. This likely means your installation is incomplete.\n"
"Please ensure langgraph-cli is installed with the 'inmem' extra: pip install -U \"langgraph-cli[inmem]\""
f"{py_version_msg}"
) from None
config_json = langgraph_cli.config.validate_config_file(pathlib.Path(config))
+2 -2
View File
@@ -100,7 +100,7 @@ class Config(TypedDict, total=False):
def _parse_version(version_str: str) -> tuple[int, int]:
"""Parse a version string into a tuple of (major, minor)."""
try:
major, minor = map(int, version_str.split("."))
major, minor = map(int, version_str.split("-")[0].split("."))
return (major, minor)
except ValueError:
raise click.UsageError(f"Invalid version format: {version_str}") from None
@@ -159,7 +159,7 @@ def validate_config(config: Config) -> Config:
if config.get("python_version"):
pyversion = config["python_version"]
if not pyversion.count(".") == 1 or not all(
part.isdigit() for part in pyversion.split(".")
part.isdigit() for part in pyversion.split("-")[0].split(".")
):
raise click.UsageError(
f"Invalid Python version format: {pyversion}. "
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langgraph-cli"
version = "0.1.65"
version = "0.1.67"
description = "CLI for interacting with LangGraph API"
authors = []
license = "MIT"
+18
View File
@@ -91,6 +91,24 @@ def test_validate_config():
validate_config({"python_version": "3.10"})
assert "Minimum required version" in str(exc_info.value)
config = validate_config(
{
"python_version": "3.11-bullseye",
"dependencies": ["."],
"graphs": {"agent": "./agent.py:graph"},
}
)
assert config["python_version"] == "3.11-bullseye"
config = validate_config(
{
"python_version": "3.12-slim",
"dependencies": ["."],
"graphs": {"agent": "./agent.py:graph"},
}
)
assert config["python_version"] == "3.12-slim"
def test_validate_config_file():
with tempfile.TemporaryDirectory() as tmpdir:
+17
View File
@@ -0,0 +1,17 @@
/** @type {import('jest').Config} */
export default {
preset: 'ts-jest',
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
},
],
},
};
+7 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@langchain/langgraph-sdk",
"version": "0.0.35",
"version": "0.0.36",
"description": "Client library for interacting with the LangGraph API",
"type": "module",
"packageManager": "yarn@1.22.19",
@@ -9,7 +9,8 @@
"build": "yarn clean && yarn lc_build --create-entrypoints --pre --tree-shaking",
"prepublish": "yarn run build",
"format": "prettier --write src",
"lint": "prettier --check src && tsc --noEmit"
"lint": "prettier --check src && tsc --noEmit",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts"
},
"main": "index.js",
"license": "MIT",
@@ -20,12 +21,16 @@
"uuid": "^9.0.0"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@langchain/scripts": "^0.1.4",
"@tsconfig/recommended": "^1.0.2",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"@types/uuid": "^9.0.1",
"concat-md": "^0.5.1",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"typedoc": "^0.26.1",
"typedoc-plugin-markdown": "^4.1.0",
"typescript": "^5.4.5"
+7 -4
View File
@@ -37,7 +37,7 @@ import {
} from "./types.js";
import { mergeSignals } from "./utils/signals.js";
import { getEnvironmentVariable } from "./utils/env.js";
import { _getFetchImplementation } from "./singletons/fetch.js";
/**
* Get the API key from the environment.
* Precedence:
@@ -164,7 +164,8 @@ class BaseClient {
signal?: AbortSignal;
},
): Promise<T> {
const response = await this.asyncCaller.fetch(
const response = await this.asyncCaller.call(
_getFetchImplementation(),
...this.prepareFetchOptions(path, options),
);
if (response.status === 202 || response.status === 204) {
@@ -752,7 +753,8 @@ export class RunsClient extends BaseClient {
const endpoint =
threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`;
const response = await this.asyncCaller.fetch(
const response = await this.asyncCaller.call(
_getFetchImplementation(),
...this.prepareFetchOptions(endpoint, {
method: "POST",
json,
@@ -1044,7 +1046,8 @@ export class RunsClient extends BaseClient {
? { signal: options }
: options;
const response = await this.asyncCaller.fetch(
const response = await this.asyncCaller.call(
_getFetchImplementation(),
...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
method: "GET",
timeoutMs: null,
+1
View File
@@ -17,5 +17,6 @@ export type {
Checkpoint,
Interrupt,
} from "./schema.js";
export { overrideFetchImplementation } from "./singletons/fetch.js";
export type { OnConflictBehavior, Command } from "./types.js";
+29
View File
@@ -0,0 +1,29 @@
// Wrap the default fetch call due to issues with illegal invocations
// in some environments:
// https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err
// @ts-expect-error Broad typing to support a range of fetch implementations
const DEFAULT_FETCH_IMPLEMENTATION = (...args: any[]) => fetch(...args);
const LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for(
"lg:fetch_implementation",
);
/**
* Overrides the fetch implementation used for LangSmith calls.
* You should use this if you need to use an implementation of fetch
* other than the default global (e.g. for dealing with proxies).
* @param fetch The new fetch function to use.
*/
export const overrideFetchImplementation = (fetch: (...args: any[]) => any) => {
(globalThis as any)[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;
};
/**
* @internal
*/
export const _getFetchImplementation: () => (...args: any[]) => any = () => {
return (
(globalThis as any)[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ??
DEFAULT_FETCH_IMPLEMENTATION
);
};
+74
View File
@@ -0,0 +1,74 @@
/* eslint-disable no-process-env */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { jest } from "@jest/globals";
import { Client } from "../client.js";
import { overrideFetchImplementation } from "../singletons/fetch.js";
describe.each([[""], ["mocked"]])("Client uses %s fetch", (description) => {
let globalFetchMock: jest.Mock;
let overriddenFetch: jest.Mock;
let expectedFetchMock: jest.Mock;
let unexpectedFetchMock: jest.Mock;
beforeEach(() => {
globalFetchMock = jest.fn(() =>
Promise.resolve({
ok: true,
json: () =>
Promise.resolve({
batch_ingest_config: {
use_multipart_endpoint: true,
},
}),
text: () => Promise.resolve(""),
}),
);
overriddenFetch = jest.fn(() =>
Promise.resolve({
ok: true,
json: () =>
Promise.resolve({
batch_ingest_config: {
use_multipart_endpoint: true,
},
}),
text: () => Promise.resolve(""),
}),
);
expectedFetchMock =
description === "mocked" ? overriddenFetch : globalFetchMock;
unexpectedFetchMock =
description === "mocked" ? globalFetchMock : overriddenFetch;
if (description === "mocked") {
overrideFetchImplementation(overriddenFetch);
} else {
overrideFetchImplementation(globalFetchMock);
}
// Mock global fetch
(globalThis as any).fetch = globalFetchMock;
});
afterEach(() => {
jest.restoreAllMocks();
});
describe("createRuns", () => {
it("should create an example with the given input and generation", async () => {
const client = new Client({ apiKey: "test-api-key" });
const thread = await client.threads.create();
expect(expectedFetchMock).toHaveBeenCalledTimes(1);
expect(unexpectedFetchMock).not.toHaveBeenCalled();
jest.clearAllMocks(); // Clear all mocks before the next operation
// Then clear & run the function
await client.runs.create(thread.thread_id, "somegraph", {
input: { foo: "bar" },
});
expect(expectedFetchMock).toHaveBeenCalledTimes(1);
expect(unexpectedFetchMock).not.toHaveBeenCalled();
});
});
});
+1880 -7
View File
File diff suppressed because it is too large Load Diff