langgraph-api doesn't support dict format for graph specification #559

Closed
opened 2026-02-20 17:40:43 -05:00 by yindo · 3 comments
Owner

Originally created by @gfortaine on GitHub (Apr 5, 2025).

Originally assigned to: @eyurtsev on GitHub.

Hi team,

PR #4164 updated the LangGraph CLI to allow specifying graphs in langgraph.json using a dictionary format:

{
  "dependencies": ["./my_agent"],
  "graphs": {
    "agent": {
      "path": "./my_agent/agent.py:graph",
      "description": "this is my agent description"
    }
  },
  "env": ".env"
}

However, the langgraph-api package, specifically the collect_graphs_from_env function in langgraph_api/graph.py, was not updated to handle this new format. It still assumes the value for each graph is a string (path:variable).

This leads to the following error when langgraph-api tries to parse a langgraph.json using the dictionary format:

Traceback (most recent call last):
  File ".../langgraph_api/lifespan.py", line 49, in lifespan
    await collect_graphs_from_env(True)
  File ".../langgraph_api/graph.py", line 198, in collect_graphs_from_env
    path_or_module, variable = value.rsplit(":", maxsplit=1)
                               ^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'rsplit'

The collect_graphs_from_env function needs to be updated to check the type of the value and extract the path string if it's a dictionary.

Here's a suggested implementation for the relevant part of the function:

async def collect_graphs_from_env(register: bool = False) -> None:
    # ... (previous code) ...

    if paths_str:
        specs = []
        for key, value in json.loads(paths_str).items():
            # Check if value is a dictionary (new format) or string (old format)
            if isinstance(value, dict):
                path_string = value.get("path")
                if not path_string or not isinstance(path_string, str):
                    raise ValueError(
                        f"Invalid dictionary format for graph '{key}'. Missing or invalid 'path' key."
                    )
            elif isinstance(value, str):
                path_string = value
            else:
                raise ValueError(
                    f"Invalid format for graph '{key}'. Expected string or dictionary, got {type(value)}."
                )

            try:
                path_or_module, variable = path_string.rsplit(":", maxsplit=1)
            except ValueError as e:
                raise ValueError(
                    f"Invalid path string '{path_string}' for graph '{key}'."
                    " Did you miss a variable name?\n"
                    " Expected format: 'path/to/file.py:variable_name' or 'my.module:variable_name'"
                ) from e

            # Determine if it's a module path or file path based on the presence of '/'
            is_module_path = "/" not in path_or_module
            specs.append(
                GraphSpec(
                    key,
                    module=path_or_module if is_module_path else None,
                    path=None if is_module_path else path_or_module,
                    variable=variable,
                    config=config_per_graph.get(key),
                )
            )
    # ... (rest of the function) ...

Could you please update langgraph-api to align with the CLI changes? Thanks!

Originally created by @gfortaine on GitHub (Apr 5, 2025). Originally assigned to: @eyurtsev on GitHub. Hi team, PR #4164 updated the LangGraph CLI to allow specifying graphs in `langgraph.json` using a dictionary format: ```json { "dependencies": ["./my_agent"], "graphs": { "agent": { "path": "./my_agent/agent.py:graph", "description": "this is my agent description" } }, "env": ".env" } ``` However, the `langgraph-api` package, specifically the `collect_graphs_from_env` function in `langgraph_api/graph.py`, was not updated to handle this new format. It still assumes the value for each graph is a string (`path:variable`). This leads to the following error when `langgraph-api` tries to parse a `langgraph.json` using the dictionary format: ``` Traceback (most recent call last): File ".../langgraph_api/lifespan.py", line 49, in lifespan await collect_graphs_from_env(True) File ".../langgraph_api/graph.py", line 198, in collect_graphs_from_env path_or_module, variable = value.rsplit(":", maxsplit=1) ^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'rsplit' ``` The `collect_graphs_from_env` function needs to be updated to check the type of the value and extract the `path` string if it's a dictionary. Here's a suggested implementation for the relevant part of the function: ```python async def collect_graphs_from_env(register: bool = False) -> None: # ... (previous code) ... if paths_str: specs = [] for key, value in json.loads(paths_str).items(): # Check if value is a dictionary (new format) or string (old format) if isinstance(value, dict): path_string = value.get("path") if not path_string or not isinstance(path_string, str): raise ValueError( f"Invalid dictionary format for graph '{key}'. Missing or invalid 'path' key." ) elif isinstance(value, str): path_string = value else: raise ValueError( f"Invalid format for graph '{key}'. Expected string or dictionary, got {type(value)}." ) try: path_or_module, variable = path_string.rsplit(":", maxsplit=1) except ValueError as e: raise ValueError( f"Invalid path string '{path_string}' for graph '{key}'." " Did you miss a variable name?\n" " Expected format: 'path/to/file.py:variable_name' or 'my.module:variable_name'" ) from e # Determine if it's a module path or file path based on the presence of '/' is_module_path = "/" not in path_or_module specs.append( GraphSpec( key, module=path_or_module if is_module_path else None, path=None if is_module_path else path_or_module, variable=variable, config=config_per_graph.get(key), ) ) # ... (rest of the function) ... ``` Could you please update `langgraph-api` to align with the CLI changes? Thanks!
yindo closed this issue 2026-02-20 17:40:43 -05:00
Author
Owner

@hinthornw commented on GitHub (Apr 29, 2025):

^ I think this was just happening on this particular day because we released the docs right before cutting the API release

@hinthornw commented on GitHub (Apr 29, 2025): ^ I think this was just happening on this particular day because we released the docs right before cutting the API release
Author
Owner

@magallardo commented on GitHub (Jun 9, 2025):

Is there any documentation for the new format?

Thanks

@magallardo commented on GitHub (Jun 9, 2025): Is there any documentation for the new format? Thanks
Author
Owner

@sydney-runkle commented on GitHub (Jun 11, 2025):

I believe this is resolved now, docs: https://langchain-ai.github.io/langgraph/cloud/reference/sdk/python_sdk_ref/

@sydney-runkle commented on GitHub (Jun 11, 2025): I believe this is resolved now, docs: https://langchain-ai.github.io/langgraph/cloud/reference/sdk/python_sdk_ref/
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#559