MCPcopy
hub / github.com/OpenBMB/ChatDev / load_config

Function load_config

check/check.py:51–96  ·  view source on GitHub ↗

Load, validate, and sanity-check a workflow file.

(
    config_path: Path,
    *,
    fn_module: Optional[str] = None,
    set_defaults: bool = True,
    vars_override: Optional[Dict[str, Any]] = None,
)

Source from the content-addressed store, hash-verified

49
50
51def load_config(
52 config_path: Path,
53 *,
54 fn_module: Optional[str] = None,
55 set_defaults: bool = True,
56 vars_override: Optional[Dict[str, Any]] = None,
57) -> DesignConfig:
58 """Load, validate, and sanity-check a workflow file."""
59
60 try:
61 raw_data = read_yaml(config_path)
62 except FileNotFoundError as exc:
63 raise DesignError(f"Design file not found: {config_path}") from exc
64
65 if not isinstance(raw_data, dict):
66 raise DesignError("YAML root must be a mapping")
67
68 if vars_override:
69 merged_vars = dict(raw_data.get("vars") or {})
70 merged_vars.update(vars_override)
71 raw_data = dict(raw_data)
72 raw_data["vars"] = merged_vars
73
74 data = prepare_design_mapping(raw_data, source=str(config_path))
75
76 schema_errors = validate_design(data, set_defaults=set_defaults, fn_module_ref=fn_module)
77 if schema_errors:
78 formatted = "\n".join(f"- {err}" for err in schema_errors)
79 raise DesignError(f"Design validation failed for '{config_path}':\n{formatted}")
80
81 try:
82 design = DesignConfig.from_dict(data, path="root")
83 except ConfigError as exc:
84 raise DesignError(f"Design parsing failed for '{config_path}': {exc}") from exc
85
86 logic_errors = check_workflow_structure(data)
87 if logic_errors:
88 formatted = "\n".join(f"- {err}" for err in logic_errors)
89 raise DesignError(f"Workflow logical issues detected for '{config_path}':\n{formatted}")
90 else:
91 print("Workflow OK.")
92
93 graph = data.get("graph") or {}
94 _ensure_supported(graph)
95
96 return design
97
98
99def check_config(yaml_content: Any) -> str:

Callers 5

mainFunction · 0.90
_run_single_taskMethod · 0.90
run_workflowFunction · 0.90

Calls 9

read_yamlFunction · 0.90
prepare_design_mappingFunction · 0.90
validate_designFunction · 0.90
check_workflow_structureFunction · 0.90
DesignErrorClass · 0.85
_ensure_supportedFunction · 0.85
getMethod · 0.45
updateMethod · 0.45
from_dictMethod · 0.45

Tested by

no test coverage detected