refactor: 重构 config 目录结构,按领域分类静态配置

This commit is contained in:
qzl
2026-03-02 14:40:45 +08:00
parent 87b8727ca4
commit 6b32990986
17 changed files with 242 additions and 65 deletions
@@ -12,12 +12,11 @@ class CrewAITemplate:
agents: dict[str, Any]
tasks: dict[str, Any]
workflow: dict[str, Any]
prompts: dict[str, str]
tools_whitelist: set[str]
def _default_static_root() -> Path:
return Path(__file__).resolve().parents[3] / "config" / "static" / "agent"
return Path(__file__).resolve().parents[3] / "config" / "static" / "crewai"
def _read_yaml(file_path: Path) -> dict[str, Any]:
@@ -30,12 +29,6 @@ def _read_yaml(file_path: Path) -> dict[str, Any]:
return loaded
def _read_prompt(file_path: Path) -> str:
if not file_path.is_file():
raise FileNotFoundError(f"Required prompt file not found: {file_path}")
return file_path.read_text(encoding="utf-8").strip()
def validate_workflow_stages(stages: list[str]) -> None:
expected = ["intent", "execution", "organization"]
if stages != expected:
@@ -56,27 +49,19 @@ def load_tools_whitelist(static_root: Path | None = None) -> set[str]:
def load_crewai_template(static_root: Path | None = None) -> CrewAITemplate:
root = static_root or _default_static_root()
crewai_root = root / "crewai"
agents = _read_yaml(crewai_root / "agents.yaml")
tasks = _read_yaml(crewai_root / "tasks.yaml")
workflow = _read_yaml(crewai_root / "workflow.yaml")
agents = _read_yaml(root / "agents.yaml")
tasks = _read_yaml(root / "tasks.yaml")
workflow = _read_yaml(root / "workflow.yaml")
stages = workflow.get("stages")
if not isinstance(stages, list):
raise ValueError("workflow.yaml field 'stages' must be a list")
validate_workflow_stages([str(stage) for stage in stages])
prompts = {
"intent": _read_prompt(crewai_root / "prompts" / "intent.md"),
"execution": _read_prompt(crewai_root / "prompts" / "execution.md"),
"organization": _read_prompt(crewai_root / "prompts" / "organization.md"),
}
return CrewAITemplate(
agents=agents,
tasks=tasks,
workflow=workflow,
prompts=prompts,
tools_whitelist=load_tools_whitelist(root),
)