You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
asyncdefcollect_graphs_from_env(register: bool=False) ->None:
# ... (previous code) ...ifpaths_str:
specs= []
forkey, valueinjson.loads(paths_str).items():
# Check if value is a dictionary (new format) or string (old format)ifisinstance(value, dict):
path_string=value.get("path")
ifnotpath_stringornotisinstance(path_string, str):
raiseValueError(
f"Invalid dictionary format for graph '{key}'. Missing or invalid 'path' key."
)
elifisinstance(value, str):
path_string=valueelse:
raiseValueError(
f"Invalid format for graph '{key}'. Expected string or dictionary, got {type(value)}."
)
try:
path_or_module, variable=path_string.rsplit(":", maxsplit=1)
exceptValueErrorase:
raiseValueError(
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'"
) frome# Determine if it's a module path or file path based on the presence of '/'is_module_path="/"notinpath_or_modulespecs.append(
GraphSpec(
key,
module=path_or_moduleifis_module_pathelseNone,
path=Noneifis_module_pathelsepath_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!
The text was updated successfully, but these errors were encountered:
gfortaine
changed the title
langgraph-api doesn't support dict format for graph specification from PR #4164
langgraph-api doesn't support dict format for graph specification
Apr 5, 2025
Hi team,
PR #4164 updated the LangGraph CLI to allow specifying graphs in
langgraph.json
using a dictionary format:However, the
langgraph-api
package, specifically thecollect_graphs_from_env
function inlanggraph_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 alanggraph.json
using the dictionary format:The
collect_graphs_from_env
function needs to be updated to check the type of the value and extract thepath
string if it's a dictionary.Here's a suggested implementation for the relevant part of the function:
Could you please update
langgraph-api
to align with the CLI changes? Thanks!The text was updated successfully, but these errors were encountered: