From 9220049b35d9900885abb7e2f9782c8112882884 Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Wed, 4 Dec 2024 06:28:54 -0800 Subject: [PATCH 1/3] Add store langgraph.json config ref (#2622) --- docs/docs/cloud/reference/cli.md | 117 +++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 37 deletions(-) diff --git a/docs/docs/cloud/reference/cli.md b/docs/docs/cloud/reference/cli.md index 0db84cb43..34629fa4e 100644 --- a/docs/docs/cloud/reference/cli.md +++ b/docs/docs/cloud/reference/cli.md @@ -26,10 +26,11 @@ 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: | | `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. | @@ -41,33 +42,75 @@ The LangGraph CLI requires a JSON configuration file with the following keys:

-Example: +### Examples + +#### Basic Configuration ```json { - "dependencies": ["langchain_openai", "./your_package"], + "dependencies": ["."], "graphs": { - "my_graph_id": "./your_package/your_file.py:variable" - }, - "env": "./.env" + "chat": "./chat/graph.py:graph" + } } ``` -Example with environment variables: +#### 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 { - "python_version": "3.11", - "dependencies": ["langchain_openai", "."], + "dependencies": ["."], "graphs": { - "my_graph_id": "./your_package/your_file.py:make_graph" + "memory_agent": "./agent/graph.py:graph" }, - "env": { - "OPENAI_API_KEY": "secret-key" + "store": { + "index": { + "embed": "openai:text-embedding-3-small", + "dims": 1536, + "fields": ["$"] + } } } ``` +#### 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 +``` + ## Commands The base command for the LangGraph CLI is `langgraph`. @@ -98,16 +141,16 @@ 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 | +| 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` @@ -122,7 +165,7 @@ 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. | @@ -141,20 +184,20 @@ 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 | -| `--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` | +| 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. | +| `--recreate / --no-recreate` | `no-recreate` | Recreate containers even if their configuration and image haven't changed | +| `--help` | | Display command documentation. | ### `dockerfile` @@ -169,7 +212,7 @@ 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. | From 84d33f9621dbdc8b7ee76b371da40d7fded060d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=9B=E9=9C=B2=E5=85=88=E7=94=9F?= Date: Wed, 4 Dec 2024 22:29:28 +0800 Subject: [PATCH 2/3] Fix typos in langgraph_sdk client. (#2621) Fix typos in langgraph_sdk client. Signed-off-by: zhanluxianshen --- libs/sdk-py/langgraph_sdk/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/sdk-py/langgraph_sdk/client.py b/libs/sdk-py/langgraph_sdk/client.py index 3c570df2a..c453eb749 100644 --- a/libs/sdk-py/langgraph_sdk/client.py +++ b/libs/sdk-py/langgraph_sdk/client.py @@ -190,7 +190,7 @@ class LangGraphClient: class HttpClient: - """Hancle async requests to the LangGraph API. + """Handle async requests to the LangGraph API. Adds additional error messaging & content handling above the provided httpx client. From a8db511e2469ece19823c8bceaa4fdd062d343c6 Mon Sep 17 00:00:00 2001 From: ACMCMC <20495460+ACMCMC@users.noreply.github.com> Date: Wed, 4 Dec 2024 14:30:05 +0000 Subject: [PATCH 3/3] Fix typo (#2620) --- docs/docs/concepts/human_in_the_loop.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/docs/concepts/human_in_the_loop.md b/docs/docs/concepts/human_in_the_loop.md index 8728d4ba5..45ce792d4 100644 --- a/docs/docs/concepts/human_in_the_loop.md +++ b/docs/docs/concepts/human_in_the_loop.md @@ -27,8 +27,8 @@ Adding a [breakpoint](./low_level.md#breakpoints) a specific location in the gra Here, we compile our graph with a checkpointer and a breakpoint at the node we want to interrupt before, `step_for_human_in_the_loop`. We then perform one of the above interaction patterns, which will create a new checkpoint if a human edits the graph state. The new checkpoint is saved to the `thread` and we can resume the graph execution from there by passing in `None` as the input. ```python -# Compile our graph with a checkpoitner and a breakpoint before "step_for_human_in_the_loop" -graph = builder.compile(checkpointer=checkpoitner, interrupt_before=["step_for_human_in_the_loop"]) +# Compile our graph with a checkpointer and a breakpoint before "step_for_human_in_the_loop" +graph = builder.compile(checkpointer=checkpointer, interrupt_before=["step_for_human_in_the_loop"]) # Run the graph up to the breakpoint thread_config = {"configurable": {"thread_id": "1"}} @@ -98,8 +98,8 @@ With persistence, we can surface the current agent state as well as the next ste If approved, the graph resumes execution from the last saved checkpoint, which is saved to the `thread`: ```python -# Compile our graph with a checkpoitner and a breakpoint before the step to approve -graph = builder.compile(checkpointer=checkpoitner, interrupt_before=["node_2"]) +# Compile our graph with a checkpointer and a breakpoint before the step to approve +graph = builder.compile(checkpointer=checkpointer, interrupt_before=["node_2"]) # Run the graph up to the breakpoint for event in graph.stream(inputs, thread, stream_mode="values"): @@ -131,8 +131,8 @@ We can edit the graph state by forking the current checkpoint, which is saved to We can then proceed with the graph from our forked checkpoint as done before. ```python -# Compile our graph with a checkpoitner and a breakpoint before the step to review -graph = builder.compile(checkpointer=checkpoitner, interrupt_before=["node_2"]) +# Compile our graph with a checkpointer and a breakpoint before the step to review +graph = builder.compile(checkpointer=checkpointer, interrupt_before=["node_2"]) # Run the graph up to the breakpoint for event in graph.stream(inputs, thread, stream_mode="values"): @@ -173,8 +173,8 @@ With input, we explicitly define a node in our graph for collecting human input! The state update with the human input then runs *as this node*. ```python -# Compile our graph with a checkpoitner and a breakpoint before the step to to collect human input -graph = builder.compile(checkpointer=checkpoitner, interrupt_before=["human_input"]) +# Compile our graph with a checkpointer and a breakpoint before the step to to collect human input +graph = builder.compile(checkpointer=checkpointer, interrupt_before=["human_input"]) # Run the graph up to the breakpoint for event in graph.stream(inputs, thread, stream_mode="values"): @@ -211,8 +211,8 @@ Even if the tool call is correct, we may also want to apply discretion: With these points in mind, we can combine the above ideas to create a human-in-the-loop review of a tool call. ```python -# Compile our graph with a checkpoitner and a breakpoint before the step to to review the tool call from the LLM -graph = builder.compile(checkpointer=checkpoitner, interrupt_before=["human_review"]) +# Compile our graph with a checkpointer and a breakpoint before the step to to review the tool call from the LLM +graph = builder.compile(checkpointer=checkpointer, interrupt_before=["human_review"]) # Run the graph up to the breakpoint for event in graph.stream(inputs, thread, stream_mode="values"): @@ -319,4 +319,4 @@ for event in graph.stream(None, config, stream_mode="values"): See [this additional conceptual guide](https://langchain-ai.github.io/langgraph/concepts/persistence/#update-state) for related context on forking. -See see [this guide](../how-tos/human_in_the_loop/time-travel.ipynb) for a detailed how-to on doing time-travel! \ No newline at end of file +See see [this guide](../how-tos/human_in_the_loop/time-travel.ipynb) for a detailed how-to on doing time-travel!