-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathconfig.py
More file actions
89 lines (78 loc) · 2.97 KB
/
config.py
File metadata and controls
89 lines (78 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Simple loader for langgraph.json configuration."""
import json
import os
from typing import Any
class LangGraphConfig:
"""Simple loader for langgraph.json configuration."""
def __init__(self, config_path: str = "langgraph.json"):
"""
Initialize configuration loader.
Args:
config_path: Path to langgraph.json file
"""
self.config_path = config_path
self._raw: dict[str, Any] | None = None
@property
def exists(self) -> bool:
"""Check if langgraph.json exists."""
return os.path.exists(self.config_path)
def _load(self) -> dict[str, Any]:
if self._raw is not None:
return self._raw
if not self.exists:
raise FileNotFoundError(f"Config file not found: {self.config_path}")
try:
with open(self.config_path, "r") as f:
self._raw = json.load(f)
except json.JSONDecodeError as e:
raise ValueError(f"Invalid JSON in {self.config_path}: {e}") from e
return self._raw
@property
def graphs(self) -> dict[str, str]:
"""
Get graph name -> path mapping from config.
Returns:
Dictionary mapping graph names to file paths (e.g., {"agent": "agent.py:graph"})
"""
config = self._load()
if "graphs" not in config:
raise ValueError("Missing required 'graphs' field in langgraph.json")
graphs = config["graphs"]
if not isinstance(graphs, dict):
raise ValueError("'graphs' must be a dictionary")
return graphs
@property
def allowed_msgpack_modules(self) -> list[tuple[str, str]] | None:
"""Read `checkpointer.serde.allowed_msgpack_modules` from langgraph.json."""
config = self._load()
checkpointer = config.get("checkpointer")
if not isinstance(checkpointer, dict):
return None
serde = checkpointer.get("serde")
if not isinstance(serde, dict):
return None
modules = serde.get("allowed_msgpack_modules")
if modules is None:
return None
if not isinstance(modules, list):
raise ValueError(
"'checkpointer.serde.allowed_msgpack_modules' must be a list "
"of [module, class_name] pairs"
)
result: list[tuple[str, str]] = []
for entry in modules:
if (
not isinstance(entry, list)
or len(entry) != 2
or not all(isinstance(part, str) for part in entry)
):
raise ValueError(
f"Invalid entry in checkpointer.serde.allowed_msgpack_modules: "
f"{entry!r} (expected [module, class_name])"
)
result.append((entry[0], entry[1]))
return result
@property
def entrypoints(self) -> list[str]:
"""Get list of available graph entrypoints."""
return list(self.graphs.keys())