sync update from LAN repo (source dhk-1 @ 3b1ec5b4)
This commit is contained in:
1 parent
da6521b6cb
commit
264e2200d6
995 files changed
+148105
-13399
No files matched your search
@@ -8,11 +8,13 @@ import pytest
|
||||
|
||||
import app.gateway.roundtable_seat_skills as seat_skills
|
||||
import app.gateway.routers.multi_agent as multi_agent
|
||||
from app.gateway.roundtable_run_policy import roundtable_run_policy
|
||||
from deerflow.agents.lead_agent.agent import (
|
||||
_append_orchestration_capability_boundary,
|
||||
_enforce_coordinator_only_tool_exclusions,
|
||||
_filter_available_skills_for_excluded_tools,
|
||||
_knowledge_space_strict_exclusions,
|
||||
_runtime_tool_is_enabled,
|
||||
)
|
||||
from deerflow.tools.builtins.skill_tools import (
|
||||
_resolve_active_agent_id,
|
||||
@@ -107,11 +109,59 @@ def test_single_agent_tool_exclusions_fail_closed_but_coordinator_is_allowed() -
|
||||
assert _enforce_coordinator_only_tool_exclusions("task-analysis-coordinator", None) is None
|
||||
|
||||
|
||||
def test_tool_driving_middleware_respects_runtime_tool_policy() -> None:
|
||||
"""A text-only coordinator must never receive a synthetic write_file call."""
|
||||
assert _runtime_tool_is_enabled({}, "write_file") is True
|
||||
assert _runtime_tool_is_enabled({"allowed_tools": ["write_file"]}, "write_file") is True
|
||||
assert _runtime_tool_is_enabled({"allowed_tools": ["present_files"]}, "write_file") is False
|
||||
assert _runtime_tool_is_enabled({"excluded_tools": ["write_file"]}, "write_file") is False
|
||||
assert _runtime_tool_is_enabled(
|
||||
{"allowed_tools": ["write_file"], "excluded_tools": ["write_file"]},
|
||||
"write_file",
|
||||
) is False
|
||||
assert _runtime_tool_is_enabled({"disable_tools": True}, "write_file") is False
|
||||
|
||||
|
||||
def test_coordinator_guard_does_not_shrink_any_roundtable_runtime_budget() -> None:
|
||||
"""Tool isolation must not shorten the working runtime of any role."""
|
||||
for role in (
|
||||
"leader",
|
||||
"seat",
|
||||
"seat_parallel",
|
||||
"report",
|
||||
"summary",
|
||||
"action_plan",
|
||||
"dashboard",
|
||||
"ingest",
|
||||
):
|
||||
policy = roundtable_run_policy(role)
|
||||
assert policy.recursion_limit == 1000
|
||||
if role != "leader":
|
||||
assert policy.allowed_tools is None
|
||||
|
||||
seat = roundtable_run_policy("seat")
|
||||
for tool in (
|
||||
"web_fetch",
|
||||
"browser_fetch_page",
|
||||
"browser_act",
|
||||
"tool_search",
|
||||
"page_report_template",
|
||||
"scheduled_task",
|
||||
"skill_manage",
|
||||
):
|
||||
assert tool not in seat.excluded_tools
|
||||
|
||||
|
||||
def test_selected_knowledge_space_blocks_external_retrieval_surfaces() -> None:
|
||||
excluded = _knowledge_space_strict_exclusions(["custom_disabled"])
|
||||
assert "custom_disabled" in excluded
|
||||
assert {"web_search", "browser_fetch_page", "tool_search", "task"}.issubset(excluded)
|
||||
assert "llmwiki_search" not in excluded
|
||||
assert {"search_skills", "skill_list", "skill_view"}.isdisjoint(excluded)
|
||||
assert _filter_available_skills_for_excluded_tools(
|
||||
["data-analysis", "document-editing"],
|
||||
excluded,
|
||||
) == ["data-analysis", "document-editing"]
|
||||
|
||||
|
||||
def test_single_agent_system_prompt_forbids_orchestration_but_coordinator_prompt_does_not() -> None:
|
||||
@@ -232,8 +282,10 @@ async def test_leader_never_broadcasts_orchestration_prompts_to_seats(monkeypatc
|
||||
'"tool_calls":[{"name":"agent_orchestration","args":'
|
||||
'{"agent_name":"seat-a","task":"分析风险"}}]}]}'
|
||||
]
|
||||
seen_inputs = []
|
||||
|
||||
async def _fake_stream(*args, **kwargs):
|
||||
seen_inputs.append(args[4]["input"]["messages"][0]["content"][0]["text"])
|
||||
yield None, captured
|
||||
|
||||
def _unexpected_broadcast(*args, **kwargs):
|
||||
@@ -260,3 +312,82 @@ async def test_leader_never_broadcasts_orchestration_prompts_to_seats(monkeypatc
|
||||
]
|
||||
|
||||
assert frames[-1]["status"] == [["seat-a", "分析风险"]]
|
||||
assert "seat-a" in seen_inputs[0]
|
||||
assert "【本次圆桌" in seen_inputs[0]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_leader_final_closeout_is_tool_free_plain_text(monkeypatch) -> None:
|
||||
"""Final synthesis must not loop through writer/presenter/orchestration tools."""
|
||||
captured_bodies = []
|
||||
|
||||
async def _fake_delivery(*args, **kwargs):
|
||||
return {"seat-a": (True, "席位完整交付", 6, "席位完整交付")}
|
||||
|
||||
async def _fake_stream(*args, **kwargs):
|
||||
captured_bodies.append(args[4])
|
||||
yield None, ['data: {"messages":[{"type":"ai","content":"最终结论正文"}]}']
|
||||
|
||||
monkeypatch.setattr(multi_agent, "_collect_delivery_status", _fake_delivery)
|
||||
monkeypatch.setattr(multi_agent, "_stream_upstream", _fake_stream)
|
||||
monkeypatch.setattr(multi_agent, "fallback_model_chain", lambda model: [model])
|
||||
|
||||
frames = [
|
||||
frame
|
||||
async for frame in multi_agent._leader_run(
|
||||
client=object(),
|
||||
base="http://gateway",
|
||||
headers={},
|
||||
agent_threads={"roundtable-coordinator": "leader-thread", "seat-a": "seat-thread"},
|
||||
agent_name="roundtable-coordinator",
|
||||
new_message="请输出最终方案",
|
||||
skill_stop_names=[],
|
||||
model_name="test-model",
|
||||
synthesis_mode=True,
|
||||
finalize_only=True,
|
||||
)
|
||||
]
|
||||
|
||||
body = captured_bodies[0]
|
||||
assert body["context"]["allowed_tools"] == []
|
||||
assert "write_file" in body["excluded_tools"]
|
||||
assert "present_files" in body["excluded_tools"]
|
||||
assert "最终收口·纯正文" in body["input"]["messages"][0]["content"][0]["text"]
|
||||
assert frames[-1]["status"] == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_leader_final_closeout_switches_only_after_completed_empty_response(monkeypatch) -> None:
|
||||
"""最终收口完整结束仍无正文才换模;换模后仍以无工具正文完成。"""
|
||||
seen_models = []
|
||||
|
||||
async def _fake_stream(*args, **kwargs):
|
||||
body = args[4]
|
||||
model = body["context"]["model_name"]
|
||||
seen_models.append(model)
|
||||
content = "" if model == "model-a" else "换模后的最终结论"
|
||||
yield None, [f'data: {{"messages":[{{"type":"ai","content":"{content}"}}]}}']
|
||||
|
||||
monkeypatch.setattr(multi_agent, "_stream_upstream", _fake_stream)
|
||||
monkeypatch.setattr(multi_agent, "fallback_model_chain", lambda model: ["model-a", "model-b"])
|
||||
|
||||
frames = [
|
||||
frame
|
||||
async for frame in multi_agent._leader_run(
|
||||
client=object(),
|
||||
base="http://gateway",
|
||||
headers={},
|
||||
agent_threads={"roundtable-coordinator": "leader-thread"},
|
||||
agent_name="roundtable-coordinator",
|
||||
new_message="请输出最终方案",
|
||||
skill_stop_names=[],
|
||||
model_name="model-a",
|
||||
synthesis_mode=True,
|
||||
finalize_only=True,
|
||||
)
|
||||
]
|
||||
|
||||
assert seen_models == ["model-a", "model-b"]
|
||||
assert any(isinstance(frame, dict) and frame.get("status") == "model_switch" for frame in frames)
|
||||
assert frames[-1]["status"] == []
|
||||
assert frames[-1]["content"] == "换模后的最终结论"
|
||||
Reference in new issue
Block a user