Skip to content

Commit

Permalink
CLI docs (#2464)
Browse files Browse the repository at this point in the history
Co-authored-by: Harrison Chase <[email protected]>
  • Loading branch information
hinthornw and hwchase17 authored Nov 19, 2024
1 parent e3a30a9 commit 12052d7
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 10 deletions.
46 changes: 37 additions & 9 deletions docs/docs/cloud/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Example:
}
```

Example:
Example with environment variables:

```json
{
Expand All @@ -78,6 +78,37 @@ The base command for the LangGraph CLI is `langgraph`.
langgraph [OPTIONS] COMMAND [ARGS]
```

### `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.

**Installation**

This command requires the "inmem" extra to be installed:

```bash
pip install -U "langgraph-cli[inmem]"
```

**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 |
| `--no-browser` | | Disable automatic browser opening |
| `--debug-port INTEGER` | | Port for debugger to listen on |
| `--help` | | Display command documentation |

### `build`

Build LangGraph Cloud API server Docker image.
Expand All @@ -100,7 +131,7 @@ langgraph build [OPTIONS]

### `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.
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**

Expand All @@ -120,8 +151,8 @@ langgraph up [OPTIONS]
| `--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 test --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` |
| `-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. |

Expand All @@ -148,9 +179,9 @@ Example:
langgraph dockerfile -c langgraph.json Dockerfile
```

Would generate something like the following:
This generates a Dockerfile that looks similar to:

```text
```dockerfile
FROM langchain/langgraph-api:3.11

ADD ./pipconf.txt /pipconfig.txt
Expand All @@ -170,6 +201,3 @@ 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"}'
```

You can then customize, build images, push, and deploy from this file.
21 changes: 20 additions & 1 deletion docs/docs/concepts/langgraph_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,28 @@ The CLI provides the following core functionality:

The `langgraph build` command builds a Docker image for the [LangGraph API server](./langgraph_server.md) that can be directly deployed.

### `dev`

!!! note "New in version 0.1.55"
The `langgraph dev` command was introduced in langgraph-cli version 0.1.55.

The `langgraph dev` command starts a lightweight development server that requires no Docker installation. This server is ideal for rapid development and testing, with features like:

- Hot reloading: Changes to your code are automatically detected and reloaded
- Debugger support: Attach your IDE's debugger for line-by-line debugging
- In-memory state with local persistence: Server state is stored in memory for speed but persisted locally between restarts

To use this command, you need to install the CLI with the "inmem" extra:

```bash
pip install -U "langgraph-cli[inmem]"
```

**Note**: This command is intended for local development and testing only. It is not recommended for production use. Since it does not use Docker, we recommend using virtual environments to manage your project's dependencies.

### `up`

The `langgraph up` command starts an instance of the [LangGraph API server](./langgraph_server.md) locally. This requires docker to be installed and running locally. It also requires a LangSmith API key for local development or a license key for production use.
The `langgraph up` command starts an instance of the [LangGraph API server](./langgraph_server.md) locally in a docker container. This requires thedocker server to be running locally. It also requires a LangSmith API key for local development or a license key for production use.

The server includes all API endpoints for your graph's runs, threads, assistants, etc. as well as the other services required to run your agent, including a managed database for checkpointing and storage.

Expand Down
10 changes: 10 additions & 0 deletions docs/docs/concepts/langgraph_studio.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ While in Beta, LangGraph Studio is available for free to all [LangSmith](https:/

If you have deployed your LangGraph application on LangGraph Platform (Cloud), you can access the studio as part of that

### Development server

LangGraph CLI also contains a command for running an in-memory development server that can be used to connect a local LangGraph app with the studio.
See [instructions here](../cloud/reference/cli.md#dev) for more information.

The way this works is that it runs inside your local environment.
It will spin up an in-memory, development server to deploy the graph.
You can then connect to the studio via the Cloud hosted version of LangGraph Platform.
To be clear, the web studio will connect to your locally running server - your agent is still running locally and never leaves your device.

## Studio FAQs

### Why is my project failing to start?
Expand Down
86 changes: 86 additions & 0 deletions docs/docs/how-tos/local-studio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# How to connect a local agent to LangGraph Studio

This guide shows you how to connect your local agent to [LangGraph Studio](../concepts/langgraph_studio.md) for visualization, interaction, and debugging.

## Connection Options

There are two ways to connect your local agent to LangGraph Studio:

- [LangGraph Desktop](../concepts/langgraph_studio.md#desktop-app): Application, Mac only, requires Docker
- [Development Server](../concepts/langgraph_studio.md#dev-server): Python package, all platforms, no Docker

In this guide we will cover how to use the development server as that is generally an easier and better experience.

## Setup your application

First, you will need to setup your application in the proper format.
This means defining a `langgraph.json` file which contains paths to your agent(s).
See [this guide](../concepts/application_structure.md) for information on how to do so.

## Install langgraph-cli

You will need to install [`langgraph-cli`](../cloud/reference/cli.md#langgraph-cli) (version `0.1.55` or higher).
You will need to make sure to install the `inmem` extras.

```shell
pip install "langgraph-cli[inmem]==0.1.55"
```

## Run the development server

1. Navigate to your project directory (where `langgraph.json` is located)

2. Start the server:
```bash
langgraph dev
```

This will look for the `langgraph.json` file in your current directory.
In there, it will find the paths to the graph(s), and start those up.
It will then automatically connect to the cloud-hosted studio.

## Use the studio

After connecting to the studio, a browser window should automatically pop up.
This will use the cloud hosted studio UI to connect to your local development server.
Your graph is still running locally, the UI is connecting to visualizing the agent and threads that are defined locally.

The graph will always use the most up-to-date code, so you will be able to change the underlying code and have it automatically reflected in the studio.
This is useful for debugging workflows.
You can run your graph in the UI until it messes up, go in and change your code, and then rerun from the node that failed.

# (Optional) Attach a debugger

For step-by-step debugging with breakpoints and variable inspection:

```bash
# Install debugpy package
pip install debugpy
# Start server with debugging enabled
langgraph dev --debug-port 5678
```

Then attach your preferred debugger:

=== "VS Code"
Add this configuration to `launch.json`:
```json
{
"name": "Attach to LangGraph",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "0.0.0.0",
"port": 5678
}
}
```
Specify the port number you chose in the previous step.

=== "PyCharm"
1. Go to Run → Edit Configurations
2. Click + and select "Python Debug Server"
3. Set IDE host name: `localhost`
4. Set port: `5678` (or the port number you chose in the previous step)
5. Click "OK" and start debugging

0 comments on commit 12052d7

Please sign in to comment.