Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langchain ai Langgraph Config Graph Paths

From Leeroopedia
Property Value
API `_update_graph_paths` and `_assemble_local_deps`
Type API Doc
Source `libs/cli/langgraph_cli/config.py`
Library langgraph-cli
Related Workflow CLI_Deployment

Overview

The `_update_graph_paths` and `_assemble_local_deps` functions are internal components of the LangGraph CLI that handle the mapping of graph import paths from the host filesystem to container-internal paths during Docker image building. `_assemble_local_deps` catalogues all local dependencies, classifying them as real packages or faux packages and determining their container destinations. `_update_graph_paths` then rewrites each graph's import string so it resolves correctly inside the Docker container.

Description

_assemble_local_deps

This function iterates over all entries in the `dependencies` list that start with `"."` (indicating a local path) and classifies each:

  • Real packages: Directories containing `pyproject.toml` or `setup.py`. These are mapped to `/deps/<directory_name>` in the container and installed with `pip install -e .`.
  • Faux packages: Directories without standard packaging files. These are mapped to `/deps/outer-<directory_name>/...` and receive a generated `pyproject.toml`.
  • Requirements files: If a faux package directory contains a `requirements.txt`, it is tracked for installation before the package itself.

The function also handles:

  • Reserved package name detection (prevents conflicts with `langgraph-api`, `pydantic`, `fastapi`, etc.).
  • Duplicate directory name resolution via a counter.
  • Working directory assignment when `"."` is in the dependencies.
  • Additional Docker build contexts for dependencies in parent directories.

The result is a `LocalDeps` named tuple containing all the information needed to generate Dockerfile instructions and rewrite paths.

_update_graph_paths

This function iterates over each entry in the `graphs` dictionary and:

  1. Extracts the import string (either from a plain string value or a dictionary's `"path"` key).
  2. Splits the import string into module path and attribute name at the `":"` separator.
  3. If the module path contains `/` or `\` (indicating a file path), resolves it to an absolute host path.
  4. Searches through real packages and faux packages in `local_deps` to find the matching container path.
  5. Rewrites the graph entry in the config to use the container-internal POSIX path.

LocalDeps Named Tuple

Field Type Description
`pip_reqs` `list[tuple[pathlib.Path, str]]` Local `requirements.txt` files and their container destinations
`real_pkgs` `dict[pathlib.Path, tuple[str, str]]` Real packages: host path to (dependency string, container name)
`faux_pkgs` `dict[pathlib.Path, tuple[str, str]]` Faux packages: host path to (dependency string, container path)
`working_dir` None` Container working directory if `"."` is in dependencies
`additional_contexts` `list[pathlib.Path]` Parent directory dependencies needing additional Docker build contexts

Code Reference

Source Location

Function File Line
`_update_graph_paths` `libs/cli/langgraph_cli/config.py` L492
`_assemble_local_deps` `libs/cli/langgraph_cli/config.py` L374
`LocalDeps` `libs/cli/langgraph_cli/config.py` L316

Signature

def _update_graph_paths(
    config_path: pathlib.Path, config: Config, local_deps: LocalDeps
) -> None:
    """Remap each graph's import path to the correct in-container path."""
    ...
def _assemble_local_deps(config_path: pathlib.Path, config: Config) -> LocalDeps:
    ...

Import

These are internal functions within the `langgraph_cli` package:

# Internal usage only (not part of public API)
from langgraph_cli.config import _assemble_local_deps, _update_graph_paths

I/O Contract

_assemble_local_deps

Direction Name Type Description
Input `config_path` `pathlib.Path` Resolved path to the configuration file
Input `config` `Config` Validated configuration dictionary
Output return `LocalDeps` Named tuple containing classified local dependencies
Raises `FileNotFoundError` If a local dependency path does not exist
Raises `NotADirectoryError` If a local dependency path is not a directory
Raises `ValueError` If a reserved package name is used or a hyphenated flat-layout name is detected

_update_graph_paths

Direction Name Type Description
Input `config_path` `pathlib.Path` Path to the configuration file
Input `config` `Config` Configuration dictionary (mutated in place)
Input `local_deps` `LocalDeps` Classified local dependencies from `_assemble_local_deps`
Output return `None` The `config["graphs"]` dictionary is modified in place
Raises `ValueError` If the import string format is invalid or the module is not found in dependencies
Raises `FileNotFoundError` If the referenced local module file does not exist
Raises `IsADirectoryError` If the module path points to a directory

Usage Examples

Assembling Local Dependencies

import pathlib
from langgraph_cli.config import validate_config_file, _assemble_local_deps

config_path = pathlib.Path("langgraph.json")
config = validate_config_file(config_path)
local_deps = _assemble_local_deps(config_path, config)

# Inspect classified dependencies
for path, (dep_str, container_name) in local_deps.real_pkgs.items():
    print(f"Real package: {path} -> /deps/{container_name}")

for path, (dep_str, container_path) in local_deps.faux_pkgs.items():
    print(f"Faux package: {path} -> {container_path}")

Updating Graph Paths for Container

import pathlib
from langgraph_cli.config import (
    validate_config_file,
    _assemble_local_deps,
    _update_graph_paths,
)

config_path = pathlib.Path("langgraph.json")
config = validate_config_file(config_path)
local_deps = _assemble_local_deps(config_path, config)

# Before: config["graphs"]["agent"] == "./my_pkg/agent.py:graph"
_update_graph_paths(config_path, config, local_deps)
# After:  config["graphs"]["agent"] == "/deps/my_pkg/agent.py:graph"

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment