Skip to content

Commit

Permalink
Release CLI (#2465)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Nov 19, 2024
1 parent 679a736 commit ff1370a
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 25 deletions.
111 changes: 103 additions & 8 deletions libs/cli/README.md
Original file line number Diff line number Diff line change
@@ -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.
38 changes: 27 additions & 11 deletions libs/cli/langgraph_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions libs/cli/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions libs/cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit ff1370a

Please sign in to comment.