From 11f2501c9823664500ded692775227637094be9e Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Fri, 17 Jan 2025 03:45:27 +0100 Subject: [PATCH 01/10] docs: add mention of JS CLI --- docs/docs/cloud/reference/cli.md | 570 +++++++++++++++++++------------ 1 file changed, 361 insertions(+), 209 deletions(-) diff --git a/docs/docs/cloud/reference/cli.md b/docs/docs/cloud/reference/cli.md index 37f4e38d9..78495d8e7 100644 --- a/docs/docs/cloud/reference/cli.md +++ b/docs/docs/cloud/reference/cli.md @@ -4,20 +4,23 @@ The LangGraph command line interface includes commands to build and run a LangGr ## Installation -1. Ensure that Docker is installed (e.g. `docker --version`). -2. Install the `langgraph-cli` package: - - === "pip" - ```bash - pip install langgraph-cli - ``` +1. Ensure that Docker is installed (e.g. `docker --version`). +2. Install the CLI package: - === "Homebrew (MacOS only)" + === "Python" ```bash + pip install langgraph-cli + + # Install via Homebrew brew install langgraph-cli ``` - -3. Run the command `langgraph --help` to confirm that the CLI is installed. + + === "JS" + ```bash + npx @langchain/langgraph-cli + ``` + +3. Run the command `langgraph --help` to confirm that the CLI is installed. [](){#langgraph.json} @@ -25,17 +28,6 @@ The LangGraph command line interface includes commands to build and run a LangGr The LangGraph CLI requires a JSON configuration file with the following keys: -| Key | Description | -| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `dependencies` | **Required**. Array of dependencies for LangGraph Cloud API server. Dependencies can be one of the following: (1) `"."`, which will look for local Python packages, (2) `pyproject.toml`, `setup.py` or `requirements.txt` in the app directory `"./local_package"`, or (3) a package name. | -| `graphs` | **Required**. Mapping from graph ID to path where the compiled graph or a function that makes a graph is defined. Example: | -| `auth` | _(Added in v0.0.11)_ Auth configuration containing the path to your authentication handler. Example: `./your_package/auth.py:auth`, where `auth` is an instance of `langgraph_sdk.Auth`. See [authentication guide](../../concepts/auth.md) for details. | -| `env` | Path to `.env` file or a mapping from environment variable to its value. | -| `store` | Configuration for adding semantic search to the BaseStore. Contains the following fields: | -| `python_version` | `3.11` or `3.12`. Defaults to `3.11`. | -| `pip_config_file` | Path to `pip` config file. | -| `dockerfile_lines` | Array of additional lines to add to Dockerfile following the import from parent image. | -

Note

@@ -43,113 +35,151 @@ The LangGraph CLI requires a JSON configuration file with the following keys:

+=== "Python" + + | Key | Description | + | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | + | `dependencies` | **Required**. Array of dependencies for LangGraph Cloud API server. Dependencies can be one of the following: (1) `"."`, which will look for local Python packages, (2) `pyproject.toml`, `setup.py` or `requirements.txt` in the app directory `"./local_package"`, or (3) a package name. | + | `graphs` | **Required**. Mapping from graph ID to path where the compiled graph or a function that makes a graph is defined. Example: | + | `auth` | _(Added in v0.0.11)_ Auth configuration containing the path to your authentication handler. Example: `./your_package/auth.py:auth`, where `auth` is an instance of `langgraph_sdk.Auth`. See [authentication guide](../../concepts/auth.md) for details. | + | `env` | Path to `.env` file or a mapping from environment variable to its value. | + | `store` | Configuration for adding semantic search to the BaseStore. Contains the following fields: | + | `python_version` | `3.11` or `3.12`. Defaults to `3.11`. | + | `node_version` | Specify `node_version: 20` to use LangGraph.js. | + | `pip_config_file` | Path to `pip` config file. | + | `dockerfile_lines` | Array of additional lines to add to Dockerfile following the import from parent image. | + +=== "JS" + + | Key | Description | + | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | + | `graphs` | **Required**. Mapping from graph ID to path where the compiled graph or a function that makes a graph is defined. Example: | + | `env` | Path to `.env` file or a mapping from environment variable to its value. | + | `store` | Configuration for adding semantic search to the BaseStore. Contains the following fields: | + | `node_version` | Specify `node_version: 20` to use LangGraph.js. | + | `dockerfile_lines` | Array of additional lines to add to Dockerfile following the import from parent image. | + ### Examples -#### Basic Configuration +=== "Python" + + #### Basic Configuration -```json -{ - "dependencies": ["."], - "graphs": { - "chat": "./chat/graph.py:graph" - } -} -``` - -#### Adding semantic search to the store - -All deployments come with a DB-backed BaseStore. Adding an "index" configuration to your `langgraph.json` will enable [semantic search](../deployment/semantic_search.md) within the BaseStore of your deployment. - -The `fields` configuration determines which parts of your documents to embed: - -- If omitted or set to `["$"]`, the entire document will be embedded -- To embed specific fields, use JSON path notation: `["metadata.title", "content.text"]` -- Documents missing specified fields will still be stored but won't have embeddings for those fields -- You can still override which fields to embed on a specific item at `put` time using the `index` parameter - -```json -{ - "dependencies": ["."], - "graphs": { - "memory_agent": "./agent/graph.py:graph" - }, - "store": { - "index": { - "embed": "openai:text-embedding-3-small", - "dims": 1536, - "fields": ["$"] + ```json + { + "dependencies": ["."], + "graphs": { + "chat": "./chat/graph.py:graph" + } } - } -} -``` + ``` -!!! note "Common model dimensions" - - openai:text-embedding-3-large: 3072 - - openai:text-embedding-3-small: 1536 - - openai:text-embedding-ada-002: 1536 - - cohere:embed-english-v3.0: 1024 - - cohere:embed-english-light-v3.0: 384 - - cohere:embed-multilingual-v3.0: 1024 - - cohere:embed-multilingual-light-v3.0: 384 + #### Adding semantic search to the store -#### Semantic search with a custom embedding function + All deployments come with a DB-backed BaseStore. Adding an "index" configuration to your `langgraph.json` will enable [semantic search](../deployment/semantic_search.md) within the BaseStore of your deployment. -If you want to use semantic search with a custom embedding function, you can pass a path to a custom embedding function: + The `fields` configuration determines which parts of your documents to embed: -```json -{ - "dependencies": ["."], - "graphs": { - "memory_agent": "./agent/graph.py:graph" - }, - "store": { - "index": { - "embed": "./embeddings.py:embed_texts", - "dims": 768, - "fields": ["text", "summary"] - } - } -} -``` + - If omitted or set to `["$"]`, the entire document will be embedded + - To embed specific fields, use JSON path notation: `["metadata.title", "content.text"]` + - Documents missing specified fields will still be stored but won't have embeddings for those fields + - You can still override which fields to embed on a specific item at `put` time using the `index` parameter -The `embed` field in store configuration can reference a custom function that takes a list of strings and returns a list of embeddings. Example implementation: - -```python -# embeddings.py -def embed_texts(texts: list[str]) -> list[list[float]]: - """Custom embedding function for semantic search.""" - # Implementation using your preferred embedding model - return [[0.1, 0.2, ...] for _ in texts] # dims-dimensional vectors -``` - -#### Adding custom authentication - -```json -{ - "dependencies": ["."], - "graphs": { - "chat": "./chat/graph.py:graph" - }, - "auth": { - "path": "./auth.py:auth", - "openapi": { - "securitySchemes": { - "apiKeyAuth": { - "type": "apiKey", - "in": "header", - "name": "X-API-Key" - } + ```json + { + "dependencies": ["."], + "graphs": { + "memory_agent": "./agent/graph.py:graph" }, - "security": [ - {"apiKeyAuth": []} - ] - }, - "disable_studio_auth": false - } -} -``` + "store": { + "index": { + "embed": "openai:text-embedding-3-small", + "dims": 1536, + "fields": ["$"] + } + } + } + ``` + + !!! note "Common model dimensions" + - `openai:text-embedding-3-large`: 3072 + - `openai:text-embedding-3-small`: 1536 + - `openai:text-embedding-ada-002`: 1536 + - `cohere:embed-english-v3.0`: 1024 + - `cohere:embed-english-light-v3.0`: 384 + - `cohere:embed-multilingual-v3.0`: 1024 + - `cohere:embed-multilingual-light-v3.0`: 384 + + #### Semantic search with a custom embedding function + + If you want to use semantic search with a custom embedding function, you can pass a path to a custom embedding function: + + ```json + { + "dependencies": ["."], + "graphs": { + "memory_agent": "./agent/graph.py:graph" + }, + "store": { + "index": { + "embed": "./embeddings.py:embed_texts", + "dims": 768, + "fields": ["text", "summary"] + } + } + } + ``` + + The `embed` field in store configuration can reference a custom function that takes a list of strings and returns a list of embeddings. Example implementation: + + ```python + # embeddings.py + def embed_texts(texts: list[str]) -> list[list[float]]: + """Custom embedding function for semantic search.""" + # Implementation using your preferred embedding model + return [[0.1, 0.2, ...] for _ in texts] # dims-dimensional vectors + ``` + + #### Adding custom authentication + + ```json + { + "dependencies": ["."], + "graphs": { + "chat": "./chat/graph.py:graph" + }, + "auth": { + "path": "./auth.py:auth", + "openapi": { + "securitySchemes": { + "apiKeyAuth": { + "type": "apiKey", + "in": "header", + "name": "X-API-Key" + } + }, + "security": [{ "apiKeyAuth": [] }] + }, + "disable_studio_auth": false + } + } + ``` + + See the [authentication conceptual guide](../../concepts/auth.md) for details, and the [setting up custom authentication](../../tutorials/auth/getting_started.md) guide for a practical walk through of the process. + + +=== "JS" + + #### Basic Configuration + + ```json + { + "graphs": { + "chat": "./src/graph.ts:graph" + } + } + ``` -See the [authentication conceptual guide](../../concepts/auth.md) for details, and the [setting up custom authentication](../../tutorials/auth/getting_started.md) guide for a practical walk through of the process. ## Commands @@ -157,139 +187,261 @@ The base command for the LangGraph CLI is `langgraph`. **Usage** -``` -langgraph [OPTIONS] COMMAND [ARGS] -``` +=== "Python" + + ``` + langgraph [OPTIONS] COMMAND [ARGS] + ``` +=== "JS" + + ``` + npx @langchain/langgraph-cli [OPTIONS] COMMAND [ARGS] + ``` + + We will be referring to `npx @langchain/langgraph-cli` as `langgraph` in the following commands. ### `dev` -Run LangGraph API server in development mode with hot reloading and debugging capabilities. This lightweight server requires no Docker installation and is suitable for development and testing. State is persisted to a local directory. +=== "Python" -!!! note "Python only" + Run LangGraph API server in development mode with hot reloading and debugging capabilities. This lightweight server requires no Docker installation and is suitable for development and testing. State is persisted to a local directory. - Currently, the CLI only supports Python >= 3.11. - JS support is coming soon. + !!! note -**Installation** + Currently, the CLI only supports Python >= 3.11. -This command requires the "inmem" extra to be installed: + **Installation** -```bash -pip install -U "langgraph-cli[inmem]" -``` + This command requires the "inmem" extra to be installed: -**Usage** + ```bash + pip install -U "langgraph-cli[inmem]" + ``` -``` -langgraph dev [OPTIONS] -``` + **Usage** -**Options** + ``` + langgraph dev [OPTIONS] + ``` -| Option | Default | Description | -| ----------------------------- | ---------------- | ----------------------------------------------------------------------------------- | -| `-c, --config FILE` | `langgraph.json` | Path to configuration file declaring dependencies, graphs and environment variables | -| `--host TEXT` | `127.0.0.1` | Host to bind the server to | -| `--port INTEGER` | `2024` | Port to bind the server to | -| `--no-reload` | | Disable auto-reload | -| `--n-jobs-per-worker INTEGER` | | Number of jobs per worker. Default is 10 | -| `--no-browser` | | Disable automatic browser opening | -| `--debug-port INTEGER` | | Port for debugger to listen on | -| `--help` | | Display command documentation | + **Options** + + | Option | Default | Description | + | ----------------------------- | ---------------- | ----------------------------------------------------------------------------------- | + | `-c, --config FILE` | `langgraph.json` | Path to configuration file declaring dependencies, graphs and environment variables | + | `--host TEXT` | `127.0.0.1` | Host to bind the server to | + | `--port INTEGER` | `2024` | Port to bind the server to | + | `--no-reload` | | Disable auto-reload | + | `--n-jobs-per-worker INTEGER` | | Number of jobs per worker. Default is 10 | + | `--debug-port INTEGER` | | Port for debugger to listen on | + | `--help` | | Display command documentation | + + +=== "JS" + + Run LangGraph API server in development mode with hot reloading capabilities. This lightweight server requires no Docker installation and is suitable for development and testing. State is persisted to a local directory. + + **Usage** + + ``` + langgraph dev [OPTIONS] + ``` + + **Options** + + | Option | Default | Description | + | ----------------------------- | ---------------- | ----------------------------------------------------------------------------------- | + | `-c, --config FILE` | `langgraph.json` | Path to configuration file declaring dependencies, graphs and environment variables | + | `--host TEXT` | `127.0.0.1` | Host to bind the server to | + | `--port INTEGER` | `2024` | Port to bind the server to | + | `--no-reload` | | Disable auto-reload | + | `--n-jobs-per-worker INTEGER` | | Number of jobs per worker. Default is 10 | + | `--debug-port INTEGER` | | Port for debugger to listen on | + | `--help` | | Display command documentation | ### `build` -Build LangGraph Cloud API server Docker image. +=== "Python" -**Usage** + Build LangGraph Cloud API server Docker image. -``` -langgraph build [OPTIONS] -``` + **Usage** -**Options** + ``` + langgraph build [OPTIONS] + ``` + + **Options** + + | Option | Default | Description | + | -------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------- | + | `--platform TEXT` | | Target platform(s) to build the Docker image for. Example: `langgraph build --platform linux/amd64,linux/arm64` | + | `-t, --tag TEXT` | | **Required**. Tag for the Docker image. Example: `langgraph build -t my-image` | + | `--pull / --no-pull` | `--pull` | Build with latest remote Docker image. Use `--no-pull` for running the LangGraph Cloud API server with locally built images. | + | `-c, --config FILE` | `langgraph.json` | Path to configuration file declaring dependencies, graphs and environment variables. | + | `--help` | | Display command documentation. | + +=== "JS" + + Build LangGraph Cloud API server Docker image. + + **Usage** + + ``` + langgraph build [OPTIONS] + ``` + + **Options** + + | Option | Default | Description | + | -------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------- | + | `--platform TEXT` | | Target platform(s) to build the Docker image for. Example: `langgraph build --platform linux/amd64,linux/arm64` | + | `-t, --tag TEXT` | | **Required**. Tag for the Docker image. Example: `langgraph build -t my-image` | + | `--no-pull` | | Use locally built images. Defaults to `false` to build with latest remote Docker image. | + | `-c, --config FILE` | `langgraph.json` | Path to configuration file declaring dependencies, graphs and environment variables. | + | `--help` | | Display command documentation. | -| Option | Default | Description | -| -------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------- | -| `--platform TEXT` | | Target platform(s) to build the Docker image for. Example: `langgraph build --platform linux/amd64,linux/arm64` | -| `-t, --tag TEXT` | | **Required**. Tag for the Docker image. Example: `langgraph build -t my-image` | -| `--pull / --no-pull` | `--pull` | Build with latest remote Docker image. Use `--no-pull` for running the LangGraph Cloud API server with locally built images. | -| `-c, --config FILE` | `langgraph.json` | Path to configuration file declaring dependencies, graphs and environment variables. | -| `--help` | | Display command documentation. | ### `up` -Start LangGraph API server. For local testing, requires a LangSmith API key with access to LangGraph Cloud closed beta. Requires a license key for production use. +=== "Python" -**Usage** + Start LangGraph API server. For local testing, requires a LangSmith API key with access to LangGraph Cloud closed beta. Requires a license key for production use. -``` -langgraph up [OPTIONS] -``` + **Usage** -**Options** + ``` + langgraph up [OPTIONS] + ``` -| Option | Default | Description | -| ---------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------- | -| `--wait` | | Wait for services to start before returning. Implies --detach | -| `--postgres-uri TEXT` | Local database | Postgres URI to use for the database. | -| `--watch` | | Restart on file changes | -| `--debugger-base-url TEXT` | `http://127.0.0.1:[PORT]` | URL used by the debugger to access LangGraph API. | -| `--debugger-port INTEGER` | | Pull the debugger image locally and serve the UI on specified port | -| `--verbose` | | Show more output from the server logs. | -| `-c, --config FILE` | `langgraph.json` | Path to configuration file declaring dependencies, graphs and environment variables. | -| `-d, --docker-compose FILE` | | Path to docker-compose.yml file with additional services to launch. | -| `-p, --port INTEGER` | `8123` | Port to expose. Example: `langgraph up --port 8000` | -| `--pull / --no-pull` | `pull` | Pull latest images. Use `--no-pull` for running the server with locally-built images. Example: `langgraph up --no-pull` | -| `--recreate / --no-recreate` | `no-recreate` | Recreate containers even if their configuration and image haven't changed | -| `--help` | | Display command documentation. | + **Options** + + | Option | Default | Description | + | ---------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------- | + | `--wait` | | Wait for services to start before returning. Implies --detach | + | `--postgres-uri TEXT` | Local database | Postgres URI to use for the database. | + | `--watch` | | Restart on file changes | + | `--debugger-base-url TEXT` | `http://127.0.0.1:[PORT]` | URL used by the debugger to access LangGraph API. | + | `--debugger-port INTEGER` | | Pull the debugger image locally and serve the UI on specified port | + | `--verbose` | | Show more output from the server logs. | + | `-c, --config FILE` | `langgraph.json` | Path to configuration file declaring dependencies, graphs and environment variables. | + | `-d, --docker-compose FILE` | | Path to docker-compose.yml file with additional services to launch. | + | `-p, --port INTEGER` | `8123` | Port to expose. Example: `langgraph up --port 8000` | + | `--pull / --no-pull` | `pull` | Pull latest images. Use `--no-pull` for running the server with locally-built images. Example: `langgraph up --no-pull` | + | `--recreate / --no-recreate` | `no-recreate` | Recreate containers even if their configuration and image haven't changed | + | `--help` | | Display command documentation. | + +=== "JS" + + Start LangGraph API server. For local testing, requires a LangSmith API key with access to LangGraph Cloud closed beta. Requires a license key for production use. + + **Usage** + + ``` + langgraph up [OPTIONS] + ``` + + **Options** + + | Option | Default | Description | + | ---------------------------------------------------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------- | + | `--wait` | | Wait for services to start before returning. Implies --detach | + | `--postgres-uri TEXT` | Local database | Postgres URI to use for the database. | + | `--watch` | | Restart on file changes | + | `-c, --config FILE` | `langgraph.json` | Path to configuration file declaring dependencies, graphs and environment variables. | + | `-d, --docker-compose FILE` | | Path to docker-compose.yml file with additional services to launch. | + | `-p, --port INTEGER` | `8123` | Port to expose. Example: `langgraph up --port 8000` | + | `--no-pull` | | Use locally built images. Defaults to `false` to build with latest remote Docker image. | + | `--recreate` | | Recreate containers even if their configuration and image haven't changed | + | `--help` | | Display command documentation. | ### `dockerfile` -Generate a Dockerfile for building a LangGraph Cloud API server Docker image. +=== "Python" -**Usage** + Generate a Dockerfile for building a LangGraph Cloud API server Docker image. -``` -langgraph dockerfile [OPTIONS] SAVE_PATH -``` + **Usage** -**Options** + ``` + langgraph dockerfile [OPTIONS] SAVE_PATH + ``` -| Option | Default | Description | -| ------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------- | -| `-c, --config FILE` | `langgraph.json` | Path to the [configuration file](#configuration-file) declaring dependencies, graphs and environment variables. | -| `--help` | | Show this message and exit. | + **Options** -Example: + | Option | Default | Description | + | ------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------- | + | `-c, --config FILE` | `langgraph.json` | Path to the [configuration file](#configuration-file) declaring dependencies, graphs and environment variables. | + | `--help` | | Show this message and exit. | -```bash -langgraph dockerfile -c langgraph.json Dockerfile -``` + Example: -This generates a Dockerfile that looks similar to: + ```bash + langgraph dockerfile -c langgraph.json Dockerfile + ``` -```dockerfile -FROM langchain/langgraph-api:3.11 + This generates a Dockerfile that looks similar to: -ADD ./pipconf.txt /pipconfig.txt + ```dockerfile + FROM langchain/langgraph-api:3.11 -RUN PIP_CONFIG_FILE=/pipconfig.txt PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt langchain_community langchain_anthropic langchain_openai wikipedia scikit-learn + ADD ./pipconf.txt /pipconfig.txt -ADD ./graphs /deps/__outer_graphs/src -RUN set -ex && \ - for line in '[project]' \ - 'name = "graphs"' \ - 'version = "0.1"' \ - '[tool.setuptools.package-data]' \ - '"*" = ["**/*"]'; do \ - echo "$line" >> /deps/__outer_graphs/pyproject.toml; \ - done + RUN PIP_CONFIG_FILE=/pipconfig.txt PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt langchain_community langchain_anthropic langchain_openai wikipedia scikit-learn -RUN PIP_CONFIG_FILE=/pipconfig.txt PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* + ADD ./graphs /deps/__outer_graphs/src + RUN set -ex && \ + for line in '[project]' \ + 'name = "graphs"' \ + 'version = "0.1"' \ + '[tool.setuptools.package-data]' \ + '"*" = ["**/*"]'; do \ + echo "$line" >> /deps/__outer_graphs/pyproject.toml; \ + done -ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_graphs/src/agent.py:graph", "storm": "/deps/__outer_graphs/src/storm.py:graph"}' -``` + 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"}' + ``` + +=== "JS" + + Generate a Dockerfile for building a LangGraph Cloud API server Docker image. + + **Usage** + + ``` + langgraph dockerfile [OPTIONS] SAVE_PATH + ``` + + **Options** + + | Option | Default | Description | + | ------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------- | + | `-c, --config FILE` | `langgraph.json` | Path to the [configuration file](#configuration-file) declaring dependencies, graphs and environment variables. | + | `--help` | | Show this message and exit. | + + Example: + + ```bash + langgraph dockerfile -c langgraph.json Dockerfile + ``` + + This generates a Dockerfile that looks similar to: + + ```dockerfile + FROM langchain/langgraphjs-api:20 + + ADD . /deps/agent + + RUN cd /deps/agent && yarn install + + ENV LANGSERVE_GRAPHS='{"agent":"./src/react_agent/graph.ts:graph"}' + + WORKDIR /deps/agent + + RUN (test ! -f /api/langgraph_api/js/build.mts && echo "Prebuild script not found, skipping") || tsx /api/langgraph_api/js/build.mts + ``` ???+ 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. \ No newline at end of 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. From efa51fe22cb80d9e33aa9b4d0703ce066b57be18 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Fri, 17 Jan 2025 20:23:37 +0100 Subject: [PATCH 02/10] Update README.md --- docs/docs/cloud/reference/cli.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/docs/cloud/reference/cli.md b/docs/docs/cloud/reference/cli.md index 78495d8e7..00396620e 100644 --- a/docs/docs/cloud/reference/cli.md +++ b/docs/docs/cloud/reference/cli.md @@ -18,9 +18,12 @@ The LangGraph command line interface includes commands to build and run a LangGr === "JS" ```bash npx @langchain/langgraph-cli + + # Install globally + npm install -g @langchain/langgraph-cli ``` -3. Run the command `langgraph --help` to confirm that the CLI is installed. +3. Run the command `langgraph --help` or `npx @langchain/langgraph-cli --help` to confirm that the CLI is working correctly. [](){#langgraph.json} @@ -55,7 +58,7 @@ The LangGraph CLI requires a JSON configuration file with the following keys: | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `graphs` | **Required**. Mapping from graph ID to path where the compiled graph or a function that makes a graph is defined. Example: | | `env` | Path to `.env` file or a mapping from environment variable to its value. | - | `store` | Configuration for adding semantic search to the BaseStore. Contains the following fields: | + | `store` | Configuration for adding semantic search to the BaseStore. Contains the following fields: | | `node_version` | Specify `node_version: 20` to use LangGraph.js. | | `dockerfile_lines` | Array of additional lines to add to Dockerfile following the import from parent image. | @@ -183,23 +186,23 @@ The LangGraph CLI requires a JSON configuration file with the following keys: ## Commands -The base command for the LangGraph CLI is `langgraph`. - **Usage** === "Python" + The base command for the LangGraph CLI is `langgraph`. + ``` langgraph [OPTIONS] COMMAND [ARGS] ``` === "JS" + The base command for the LangGraph.js CLI is `langgraphjs`. We recommend using `npx` to always use the latest version of the CLI. + ``` npx @langchain/langgraph-cli [OPTIONS] COMMAND [ARGS] ``` - We will be referring to `npx @langchain/langgraph-cli` as `langgraph` in the following commands. - ### `dev` === "Python" @@ -244,7 +247,7 @@ The base command for the LangGraph CLI is `langgraph`. **Usage** ``` - langgraph dev [OPTIONS] + npx @langchain/langgraph-cli dev [OPTIONS] ``` **Options** @@ -288,7 +291,7 @@ The base command for the LangGraph CLI is `langgraph`. **Usage** ``` - langgraph build [OPTIONS] + npx @langchain/langgraph-cli build [OPTIONS] ``` **Options** @@ -338,7 +341,7 @@ The base command for the LangGraph CLI is `langgraph`. **Usage** ``` - langgraph up [OPTIONS] + npx @langchain/langgraph-cli up [OPTIONS] ``` **Options** @@ -411,7 +414,7 @@ The base command for the LangGraph CLI is `langgraph`. **Usage** ``` - langgraph dockerfile [OPTIONS] SAVE_PATH + npx @langchain/langgraph-cli dockerfile [OPTIONS] SAVE_PATH ``` **Options** From 0e79407973d2a91279d425ed0e3a1b278c32f470 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Fri, 17 Jan 2025 20:27:42 +0100 Subject: [PATCH 03/10] Last pass --- docs/docs/cloud/reference/cli.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/docs/cloud/reference/cli.md b/docs/docs/cloud/reference/cli.md index 00396620e..875fd7e0f 100644 --- a/docs/docs/cloud/reference/cli.md +++ b/docs/docs/cloud/reference/cli.md @@ -19,7 +19,7 @@ The LangGraph command line interface includes commands to build and run a LangGr ```bash npx @langchain/langgraph-cli - # Install globally + # Install globally, will be available as `langgraphjs` npm install -g @langchain/langgraph-cli ``` @@ -197,12 +197,14 @@ The LangGraph CLI requires a JSON configuration file with the following keys: ``` === "JS" - The base command for the LangGraph.js CLI is `langgraphjs`. We recommend using `npx` to always use the latest version of the CLI. + The base command for the LangGraph.js CLI is `langgraphjs`. ``` npx @langchain/langgraph-cli [OPTIONS] COMMAND [ARGS] ``` + We recommend using `npx` to always use the latest version of the CLI. + ### `dev` === "Python" @@ -407,6 +409,9 @@ The LangGraph CLI requires a JSON configuration file with the following keys: 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. + === "JS" Generate a Dockerfile for building a LangGraph Cloud API server Docker image. @@ -427,7 +432,7 @@ The LangGraph CLI requires a JSON configuration file with the following keys: Example: ```bash - langgraph dockerfile -c langgraph.json Dockerfile + npx @langchain/langgraph-cli dockerfile -c langgraph.json Dockerfile ``` This generates a Dockerfile that looks similar to: @@ -446,5 +451,5 @@ The LangGraph CLI requires a JSON configuration file with the following keys: RUN (test ! -f /api/langgraph_api/js/build.mts && echo "Prebuild script not found, skipping") || tsx /api/langgraph_api/js/build.mts ``` -???+ 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. + ???+ note "Updating your langgraph.json file" + The `npx @langchain/langgraph-cli 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. From 0f1b0bfba352e0f42e125d11b617f944ab4b12cb Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Fri, 17 Jan 2025 20:32:16 +0100 Subject: [PATCH 04/10] typo --- docs/docs/cloud/reference/cli.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/cloud/reference/cli.md b/docs/docs/cloud/reference/cli.md index 875fd7e0f..01286a5e3 100644 --- a/docs/docs/cloud/reference/cli.md +++ b/docs/docs/cloud/reference/cli.md @@ -46,7 +46,7 @@ The LangGraph CLI requires a JSON configuration file with the following keys: | `graphs` | **Required**. Mapping from graph ID to path where the compiled graph or a function that makes a graph is defined. Example:
  • `./your_package/your_file.py:variable`, where `variable` is an instance of `langgraph.graph.state.CompiledStateGraph`
  • `./your_package/your_file.py:make_graph`, where `make_graph` is a function that takes a config dictionary (`langchain_core.runnables.RunnableConfig`) and creates an instance of `langgraph.graph.state.StateGraph` / `langgraph.graph.state.CompiledStateGraph`.
| | `auth` | _(Added in v0.0.11)_ Auth configuration containing the path to your authentication handler. Example: `./your_package/auth.py:auth`, where `auth` is an instance of `langgraph_sdk.Auth`. See [authentication guide](../../concepts/auth.md) for details. | | `env` | Path to `.env` file or a mapping from environment variable to its value. | - | `store` | Configuration for adding semantic search to the BaseStore. Contains the following fields:
  • `index`: Configuration for semantic search indexing with fields:
    • `embed`: Embedding provider (e.g., "openai:text-embedding-3-small") or path to custom embedding function
    • `dims`: Dimension size of the embedding model. Used to initialize the vector table.
    • `fields` (optional): List of fields to index. Defaults to `["$"]`, meaningto index entire documents. Can be specific fields like `["text", "summary", "some.value"]`
| + | `store` | Configuration for adding semantic search to the BaseStore. Contains the following fields:
  • `index`: Configuration for semantic search indexing with fields:
    • `embed`: Embedding provider (e.g., "openai:text-embedding-3-small") or path to custom embedding function
    • `dims`: Dimension size of the embedding model. Used to initialize the vector table.
    • `fields` (optional): List of fields to index. Defaults to `["$"]`, which means to index entire documents. Can be specific fields like `["text", "summary", "some.value"]`
| | `python_version` | `3.11` or `3.12`. Defaults to `3.11`. | | `node_version` | Specify `node_version: 20` to use LangGraph.js. | | `pip_config_file` | Path to `pip` config file. | @@ -58,7 +58,7 @@ The LangGraph CLI requires a JSON configuration file with the following keys: | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `graphs` | **Required**. Mapping from graph ID to path where the compiled graph or a function that makes a graph is defined. Example:
  • `./src/graph.ts:variable`, where `variable` is an instance of `CompiledStateGraph`
  • `./src/graph.ts:makeGraph`, where `makeGraph` is a function that takes a config dictionary (`LangGraphRunnableConfig`) and creates an instance of `StateGraph` / `CompiledStateGraph`.
| | `env` | Path to `.env` file or a mapping from environment variable to its value. | - | `store` | Configuration for adding semantic search to the BaseStore. Contains the following fields:
  • `index`: Configuration for semantic search indexing with fields:
    • `embed`: Embedding provider (e.g., "openai:text-embedding-3-small") or path to custom embedding function
    • `dims`: Dimension size of the embedding model. Used to initialize the vector table.
    • `fields` (optional): List of fields to index. Defaults to `["$"]`, meaning to index entire documents. Can be specific fields like `["text", "summary", "some.value"]`
| + | `store` | Configuration for adding semantic search to the BaseStore. Contains the following fields:
  • `index`: Configuration for semantic search indexing with fields:
    • `embed`: Embedding provider (e.g., "openai:text-embedding-3-small") or path to custom embedding function
    • `dims`: Dimension size of the embedding model. Used to initialize the vector table.
    • `fields` (optional): List of fields to index. Defaults to `["$"]`, which means to index entire documents. Can be specific fields like `["text", "summary", "some.value"]`
| | `node_version` | Specify `node_version: 20` to use LangGraph.js. | | `dockerfile_lines` | Array of additional lines to add to Dockerfile following the import from parent image. | From e18f2b3795ec051466855f1860103b0c86545cf6 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Fri, 17 Jan 2025 20:02:41 +0100 Subject: [PATCH 05/10] fix(cli): warn users to use the JS cli for JS graphs --- libs/cli/langgraph_cli/cli.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/cli/langgraph_cli/cli.py b/libs/cli/langgraph_cli/cli.py index 98d585f40..17088b713 100644 --- a/libs/cli/langgraph_cli/cli.py +++ b/libs/cli/langgraph_cli/cli.py @@ -605,6 +605,11 @@ def dev( ) from None config_json = langgraph_cli.config.validate_config_file(pathlib.Path(config)) + if config_json.get("node_version"): + raise click.UsageError( + "In-mem server for JS graphs is not supported in this version of the LangGraph CLI. Please use `npx @langchain/langgraph-cli` instead." + ) from None + cwd = os.getcwd() sys.path.append(cwd) dependencies = config_json.get("dependencies", []) From 25239891bc2714f5f901c0ac0c4cc84e0fa700ed Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Tue, 21 Jan 2025 00:17:12 +0100 Subject: [PATCH 06/10] feat(cli): add detection for bun.lockb --- libs/cli/langgraph_cli/config.py | 5 ++++- libs/cli/pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/cli/langgraph_cli/config.py b/libs/cli/langgraph_cli/config.py index 6fb6b309a..be8cfd085 100644 --- a/libs/cli/langgraph_cli/config.py +++ b/libs/cli/langgraph_cli/config.py @@ -469,10 +469,11 @@ def node_config_to_docker(config_path: pathlib.Path, config: Config, base_image: except OSError: return False - npm, yarn, pnpm = [ + npm, yarn, pnpm, bun = [ test_file("package-lock.json"), test_file("yarn.lock"), test_file("pnpm-lock.yaml"), + test_file("bun.lockb"), ] if yarn: @@ -481,6 +482,8 @@ def node_config_to_docker(config_path: pathlib.Path, config: Config, base_image: install_cmd = "pnpm i --frozen-lockfile" elif npm: install_cmd = "npm ci" + elif bun: + install_cmd = "bun i" else: install_cmd = "npm i" store_config = config.get("store") diff --git a/libs/cli/pyproject.toml b/libs/cli/pyproject.toml index 6595cc7b9..bcb314066 100644 --- a/libs/cli/pyproject.toml +++ b/libs/cli/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langgraph-cli" -version = "0.1.67" +version = "0.1.68" description = "CLI for interacting with LangGraph API" authors = [] license = "MIT" From b2213e523efb2e8ee78a742e9685a11c3a34b2f1 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Mon, 20 Jan 2025 16:03:27 -0800 Subject: [PATCH 07/10] Add get_store function --- libs/langgraph/langgraph/utils/config.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/langgraph/langgraph/utils/config.py b/libs/langgraph/langgraph/utils/config.py index 309c6d6be..55c89b3ba 100644 --- a/libs/langgraph/langgraph/utils/config.py +++ b/libs/langgraph/langgraph/utils/config.py @@ -23,9 +23,11 @@ from langgraph.constants import ( CONFIG_KEY_CHECKPOINT_ID, CONFIG_KEY_CHECKPOINT_MAP, CONFIG_KEY_CHECKPOINT_NS, + CONFIG_KEY_STORE, NS_END, NS_SEP, ) +from langgraph.store.base import BaseStore def recast_checkpoint_ns(ns: str) -> str: @@ -332,4 +334,9 @@ def get_config() -> RunnableConfig: if var_config := var_child_runnable_config.get(): return var_config else: - raise RuntimeError("Called get_configurable outside of a runnable context") + raise RuntimeError("Called get_config outside of a runnable context") + + +def get_store() -> BaseStore: + config = get_config() + return config[CONF][CONFIG_KEY_STORE] From 6087b1969e95e3621738f0873d7cf337546b54cc Mon Sep 17 00:00:00 2001 From: Bagatur <22008038+baskaryan@users.noreply.github.com> Date: Mon, 20 Jan 2025 18:28:57 -0800 Subject: [PATCH 08/10] python[patch]: call create_react_agent model node without is_last_step (#3114) So that you can call agent.nodes['agent'].invoke({'messages': []}) without needing to specify is_last_step. very helpful for evaluating just the model node of the agent --- libs/langgraph/langgraph/prebuilt/chat_agent_executor.py | 4 ++-- libs/langgraph/pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py b/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py index a14007713..ceeba34b3 100644 --- a/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py @@ -635,7 +635,7 @@ def create_react_agent( if ( ( "remaining_steps" not in state - and state["is_last_step"] + and state.get("is_last_step", False) and has_tool_calls ) or ( @@ -672,7 +672,7 @@ def create_react_agent( if ( ( "remaining_steps" not in state - and state["is_last_step"] + and state.get("is_last_step", False) and has_tool_calls ) or ( diff --git a/libs/langgraph/pyproject.toml b/libs/langgraph/pyproject.toml index a0b366809..742c9bd0e 100644 --- a/libs/langgraph/pyproject.toml +++ b/libs/langgraph/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langgraph" -version = "0.2.64" +version = "0.2.65" description = "Building stateful, multi-actor applications with LLMs" authors = [] license = "MIT" From 19a91f4677f3d0e0dd74449efa9a5a96fb5d1302 Mon Sep 17 00:00:00 2001 From: viren-vii <56278281+viren-vii@users.noreply.github.com> Date: Tue, 21 Jan 2025 09:33:31 -0500 Subject: [PATCH 09/10] Update persistence_postgres.ipynb to remove typo in markdown cell. (#3119) Fixed a typo that was interrupting the markdown. --- docs/docs/how-tos/persistence_postgres.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/docs/how-tos/persistence_postgres.ipynb b/docs/docs/how-tos/persistence_postgres.ipynb index 572759289..332c98cae 100644 --- a/docs/docs/how-tos/persistence_postgres.ipynb +++ b/docs/docs/how-tos/persistence_postgres.ipynb @@ -44,7 +44,8 @@ "...\n", "```\n", "\n", - "!!! info \"Setup\n", + "!!! info \"Setup\"", + "\n", " You need to run `.setup()` once on your checkpointer to initialize the database before you can use it." ] }, From 6eeb9de46aa825123dba1e1aa04561f0fbe9b403 Mon Sep 17 00:00:00 2001 From: Roy Barber Date: Tue, 21 Jan 2025 14:34:57 +0000 Subject: [PATCH 10/10] DOCS: Incorrect reference to JS/TS SDK as Python SDK (#3103) Small typo in the Local Server page: https://langchain-ai.github.io/langgraph/tutorials/langgraph-platform/local-server/ --- docs/docs/tutorials/langgraph-platform/local-server.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/tutorials/langgraph-platform/local-server.md b/docs/docs/tutorials/langgraph-platform/local-server.md index 8393cb13b..402ee77f7 100644 --- a/docs/docs/tutorials/langgraph-platform/local-server.md +++ b/docs/docs/tutorials/langgraph-platform/local-server.md @@ -250,4 +250,4 @@ Access detailed documentation for development and API usage: - **[LangGraph Server API Reference](../../cloud/reference/api/api_ref.html)**: Explore the LangGraph Server API documentation. - **[Python SDK Reference](../../cloud/reference/sdk/python_sdk_ref.md)**: Explore the Python SDK API Reference. -- **[JS/TS SDK Reference](../../cloud/reference/sdk/js_ts_sdk_ref.md)**: Explore the Python SDK API Reference. +- **[JS/TS SDK Reference](../../cloud/reference/sdk/js_ts_sdk_ref.md)**: Explore the JS/TS SDK API Reference.