From ff1370a9a51f3607bdfd36063be515f817998822 Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Tue, 19 Nov 2024 00:41:18 -0800 Subject: [PATCH] Release CLI (#2465) --- libs/cli/README.md | 111 +++++++++++++++++++++++++++++++--- libs/cli/langgraph_cli/cli.py | 38 ++++++++---- libs/cli/poetry.lock | 8 +-- libs/cli/pyproject.toml | 4 +- 4 files changed, 136 insertions(+), 25 deletions(-) diff --git a/libs/cli/README.md b/libs/cli/README.md index 511e1b6fe..595372ef7 100644 --- a/libs/cli/README.md +++ b/libs/cli/README.md @@ -1,10 +1,105 @@ -# langchain-cli +# LangGraph CLI -This package implements the official CLI for LangGraph API. +The official command-line interface for LangGraph, providing tools to create, develop, and deploy LangGraph applications. -## How to Test CLI Changes Locally -These instructions are for CLI development and testing. Use the CLI examples to test CLI changes locally. -1. Make changes to the CLI code. -1. Navigate to the `libs/cli/examples`: `cd libs/cli/examples` -1. Install CLI examples dependencies: `poetry install` -1. Run/test CLI command (e.g. `langgraph build`). +## Installation + +Install via pip: +```bash +pip install langgraph-cli +``` + +For development mode with hot reloading: +```bash +pip install "langgraph-cli[inmem]" +``` + +## Commands + +### `langgraph new` 🌱 +Create a new LangGraph project from a template +```bash +langgraph new [PATH] --template TEMPLATE_NAME +``` + +### `langgraph dev` 🏃‍♀️ +Run LangGraph API server in development mode with hot reloading +```bash +langgraph dev [OPTIONS] + --host TEXT Host to bind to (default: 127.0.0.1) + --port INTEGER Port to bind to (default: 2024) + --no-reload Disable auto-reload + --debug-port INTEGER Enable remote debugging + --no-browser Skip opening browser window + -c, --config FILE Config file path (default: langgraph.json) +``` + +### `langgraph up` 🚀 +Launch LangGraph API server in Docker +```bash +langgraph up [OPTIONS] + -p, --port INTEGER Port to expose (default: 8123) + --wait Wait for services to start + --watch Restart on file changes + --verbose Show detailed logs + -c, --config FILE Config file path + -d, --docker-compose Additional services file +``` + +### `langgraph build` +Build a Docker image for your LangGraph application +```bash +langgraph build -t IMAGE_TAG [OPTIONS] + --platform TEXT Target platforms (e.g., linux/amd64,linux/arm64) + --pull / --no-pull Use latest/local base image + -c, --config FILE Config file path +``` + +### `langgraph dockerfile` +Generate a Dockerfile for custom deployments +```bash +langgraph dockerfile SAVE_PATH [OPTIONS] + -c, --config FILE Config file path +``` + +## Configuration + +The CLI uses a `langgraph.json` configuration file with these key settings: + +```json +{ + "dependencies": ["langchain_openai", "./your_package"], // Required: Package dependencies + "graphs": { + "my_graph": "./your_package/file.py:graph" // Required: Graph definitions + }, + "env": "./.env", // Optional: Environment variables + "python_version": "3.11", // Optional: Python version (3.11/3.12) + "pip_config_file": "./pip.conf", // Optional: pip configuration + "dockerfile_lines": [] // Optional: Additional Dockerfile commands +} +``` + +See the [full documentation](https://langchain-ai.github.io/langgraph/docs/cloud/reference/cli.html) for detailed configuration options. + +## Development + +To develop the CLI itself: + +1. Clone the repository +2. Navigate to the CLI directory: `cd libs/cli` +3. Install development dependencies: `poetry install` +4. Make your changes to the CLI code +5. Test your changes: + ```bash + # Run CLI commands directly + poetry run langgraph --help + + # Or use the examples + cd examples + poetry install + poetry run langgraph dev # or other commands + ``` + +## License + +This project is licensed under the terms specified in the repository's LICENSE file. diff --git a/libs/cli/langgraph_cli/cli.py b/libs/cli/langgraph_cli/cli.py index 60926e09b..4460f3f41 100644 --- a/libs/cli/langgraph_cli/cli.py +++ b/libs/cli/langgraph_cli/cli.py @@ -527,33 +527,49 @@ def new(path: Optional[str], template: Optional[str]) -> None: return create_new(path, template) -@click.option("--host", default="127.0.0.1", help="Host to bind the server to") -@click.option("--port", default=2024, type=int, help="Port to bind the server to") -@click.option("--no-reload", is_flag=True, help="Disable auto-reload") +@click.option( + "--host", + default="127.0.0.1", + help="Network interface to bind the development server to. Default 127.0.0.1 is recommended for security. Only use 0.0.0.0 in trusted networks", +) +@click.option( + "--port", + default=2024, + type=int, + help="Port number to bind the development server to. Example: langgraph dev --port 8000", +) +@click.option( + "--no-reload", + is_flag=True, + help="Disable automatic reloading when code changes are detected", +) @click.option( "--config", type=click.Path(exists=True), default="langgraph.json", - help="Path to configuration file", + help="Path to configuration file declaring dependencies, graphs and environment variables", ) @click.option( "--n-jobs-per-worker", default=None, type=int, - help="Number of jobs per worker. Default is None (meaning 10)", + help="Maximum number of concurrent jobs each worker process can handle. Default: 10", ) @click.option( "--no-browser", is_flag=True, - help="Disable automatic browser opening", + help="Skip automatically opening the browser when the server starts", ) @click.option( "--debug-port", default=None, type=int, - help="Port for debugger to listen on (default: none)", + help="Enable remote debugging by listening on specified port. Requires debugpy to be installed", +) +@cli.command( + "dev", + help="🏃‍♀️‍➡️ Run LangGraph API server in development mode with hot reloading and debugging support", ) -@cli.command("dev", help="🏃‍♀️‍➡️ Run LangGraph API server in development mode.") @log_command def dev( host: str, @@ -576,13 +592,13 @@ def dev( raise click.UsageError( "Required package 'langgraph-api-inmem' is not installed.\n" "Please install it with:\n\n" - " pip install langgraph-api-inmem\n\n" - "If you're developing locally, you can install it in development mode:\n" + ' pip install -U "langgraph-cli[inmem]"\n\n' + "If you're developing the langgraph-cli package locally, you can install in development mode:\n" " pip install -e ." ) from None raise click.UsageError( "Could not import run_server. This likely means your installation is incomplete.\n" - "Please ensure both langgraph-cli and langgraph-api-inmem are installed correctly." + "Please ensure langgraph-cli is installed with the 'inmem' extra: pip install -U \"langgraph-cli[inmem]\"" ) from None import json diff --git a/libs/cli/poetry.lock b/libs/cli/poetry.lock index a9c92efca..f2e6ebd23 100644 --- a/libs/cli/poetry.lock +++ b/libs/cli/poetry.lock @@ -509,13 +509,13 @@ langgraph-sdk = ">=0.1.32,<0.2.0" [[package]] name = "langgraph-api-inmem" -version = "0.0.2" +version = "0.0.3" description = "" optional = true python-versions = "<4.0.0,>=3.9.0" files = [ - {file = "langgraph_api_inmem-0.0.2-py3-none-any.whl", hash = "sha256:71769d03d4e7d7ef133290e68dd8b126395d516356a653e22f6997c3cefb3af3"}, - {file = "langgraph_api_inmem-0.0.2.tar.gz", hash = "sha256:62327775d099f24a80f2d9605a4f1fcceb121157b45d671bcfd191a9cad2b8d4"}, + {file = "langgraph_api_inmem-0.0.3-py3-none-any.whl", hash = "sha256:161f76dd916048c59ae2007bea3ab3e066479aeeaef3d348e815908c18af82d0"}, + {file = "langgraph_api_inmem-0.0.3.tar.gz", hash = "sha256:9ca6a4065877967028909fb1b5b9085503d7b0021067a43e663e55c865ff7e2c"}, ] [package.dependencies] @@ -1575,4 +1575,4 @@ inmem = ["langgraph-api-inmem"] [metadata] lock-version = "2.0" python-versions = "^3.9.0,<4.0" -content-hash = "431a17a3d5aa4084654e984a912add78e55f3f121727b74a10f47a9a806af546" +content-hash = "5a3dc8012db6a4cd103de557563e23f92b825caddd1d83c838282211a7aab4e3" diff --git a/libs/cli/pyproject.toml b/libs/cli/pyproject.toml index 49f164c04..217e3762e 100644 --- a/libs/cli/pyproject.toml +++ b/libs/cli/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langgraph-cli" -version = "0.1.55rc1" +version = "0.1.55" description = "CLI for interacting with LangGraph API" authors = [] license = "MIT" @@ -14,7 +14,7 @@ langgraph = "langgraph_cli.cli:cli" [tool.poetry.dependencies] python = "^3.9.0,<4.0" click = "^8.1.7" -langgraph-api-inmem = { version = ">=0.0.2,<0.1.0", optional = true } +langgraph-api-inmem = { version = ">=0.0.3,<0.1.0", optional = true } [tool.poetry.group.dev.dependencies] ruff = "^0.6.2"