feat: add strategy selection workbench
This commit is contained in:
1 parent
60e2c72514
commit
5fd2e8302c
34 files changed
+3188
-9
No files matched your search
@@ -0,0 +1,115 @@
|
||||
"""Regression tests for the strategy-selection built-in agent seed."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from app.gateway.routers import _strategy_selection_seed as seed
|
||||
from deerflow.config.paths import Paths
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def tmp_paths(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Paths:
|
||||
paths = Paths(tmp_path)
|
||||
monkeypatch.setattr(seed, "get_paths", lambda: paths)
|
||||
return paths
|
||||
|
||||
|
||||
def _asset(agent_id: str, filename: str) -> Path:
|
||||
return seed._ASSETS_DIR / agent_id / filename
|
||||
|
||||
|
||||
def test_seed_assets_define_all_nine_functional_agents() -> None:
|
||||
agent_ids = tuple(seed.required_agent_ids())
|
||||
|
||||
assert len(agent_ids) == 9
|
||||
assert len(set(agent_ids)) == 9
|
||||
assert agent_ids[0] == seed.STRATEGY_INTENT_AGENT_ID
|
||||
assert agent_ids[-2:] == (
|
||||
seed.STRATEGY_JUDGE_AGENT_ID,
|
||||
seed.STRATEGY_SOLUTION_AGENT_ID,
|
||||
)
|
||||
assert len(seed.STRATEGY_ANGLE_AGENT_IDS) == 6
|
||||
|
||||
for agent_id in agent_ids:
|
||||
config_path = _asset(agent_id, "config.yaml")
|
||||
soul_path = _asset(agent_id, "SOUL.md")
|
||||
assert config_path.is_file(), agent_id
|
||||
assert soul_path.is_file(), agent_id
|
||||
config = yaml.safe_load(config_path.read_text(encoding="utf-8"))
|
||||
soul = soul_path.read_text(encoding="utf-8")
|
||||
assert config["id"] == agent_id
|
||||
assert config["name"].strip()
|
||||
assert config["description"].strip()
|
||||
assert "作战战术" in soul
|
||||
assert "定向政治说服" in soul
|
||||
assert "降级" in soul
|
||||
|
||||
|
||||
def test_seed_assets_use_role_appropriate_existing_skills_and_tools() -> None:
|
||||
intent = yaml.safe_load(
|
||||
_asset(seed.STRATEGY_INTENT_AGENT_ID, "config.yaml").read_text(encoding="utf-8")
|
||||
)
|
||||
assert intent["skills"] == ["intent-clarification-policy"]
|
||||
assert intent["tool_groups"] == []
|
||||
|
||||
for agent_id in seed.STRATEGY_ANGLE_AGENT_IDS:
|
||||
config = yaml.safe_load(_asset(agent_id, "config.yaml").read_text(encoding="utf-8"))
|
||||
assert config["skills"] == ["policy-knowledge"]
|
||||
assert config["tool_groups"] == ["web", "file:read"]
|
||||
|
||||
judge = yaml.safe_load(
|
||||
_asset(seed.STRATEGY_JUDGE_AGENT_ID, "config.yaml").read_text(encoding="utf-8")
|
||||
)
|
||||
solution = yaml.safe_load(
|
||||
_asset(seed.STRATEGY_SOLUTION_AGENT_ID, "config.yaml").read_text(encoding="utf-8")
|
||||
)
|
||||
assert judge["skills"] == []
|
||||
assert judge["tool_groups"] == []
|
||||
assert solution["skills"] == []
|
||||
assert solution["tool_groups"] == ["file:write"]
|
||||
|
||||
|
||||
def test_seed_assets_define_machine_readable_handoff_contracts() -> None:
|
||||
intent_soul = _asset(seed.STRATEGY_INTENT_AGENT_ID, "SOUL.md").read_text(encoding="utf-8")
|
||||
judge_soul = _asset(seed.STRATEGY_JUDGE_AGENT_ID, "SOUL.md").read_text(encoding="utf-8")
|
||||
solution_soul = _asset(seed.STRATEGY_SOLUTION_AGENT_ID, "SOUL.md").read_text(encoding="utf-8")
|
||||
|
||||
assert "[INTENT_READY]" in intent_soul
|
||||
for field in (
|
||||
"name",
|
||||
"detail",
|
||||
"objective",
|
||||
"prerequisites",
|
||||
"constraints",
|
||||
"deliverables",
|
||||
"acceptanceCriteria",
|
||||
"horizon",
|
||||
"selectedAngleIds",
|
||||
):
|
||||
assert f'"{field}"' in intent_soul
|
||||
assert "[JUDGEMENT_READY]" in judge_soul
|
||||
for field in ("agentId", "score", "conclusion", "comment", "strengths", "risks"):
|
||||
assert f'"{field}"' in judge_soul
|
||||
assert '"recommendedAgentIds"' in judge_soul
|
||||
assert "/mnt/user-data/outputs/综合策略方案.md" in solution_soul
|
||||
|
||||
|
||||
def test_seed_creates_once_and_never_overwrites_admin_changes(tmp_paths: Paths) -> None:
|
||||
expected = set(seed.required_agent_ids())
|
||||
assert set(seed.ensure_strategy_selection_agents()) == expected
|
||||
|
||||
for agent_id in expected:
|
||||
agent_dir = tmp_paths.agent_dir(agent_id)
|
||||
assert (agent_dir / "config.yaml").is_file()
|
||||
assert (agent_dir / "SOUL.md").is_file()
|
||||
|
||||
customized_agent = seed.STRATEGY_SECURITY_AGENT_ID
|
||||
customized_soul = tmp_paths.agent_dir(customized_agent) / "SOUL.md"
|
||||
customized_soul.write_text("管理员现场修改", encoding="utf-8")
|
||||
|
||||
assert seed.ensure_strategy_selection_agents() == []
|
||||
assert customized_soul.read_text(encoding="utf-8") == "管理员现场修改"
|
||||
Reference in new issue
Block a user