fix: 会商席位与总控角色隔离,编排能力只归总控
This commit is contained in:
1 parent
ff80cc110d
commit
3384f2e51c
10 files changed
+488
-125
No files matched your search
+31
-3
@@ -9,6 +9,21 @@ from langchain.tools import ToolRuntime, tool
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_ROUNDTABLE_COORDINATOR_AGENT_ID = "roundtable-coordinator"
|
||||
COORDINATOR_ONLY_SKILL_NAMES = frozenset({"agent_orchestration", "agent-orchestration"})
|
||||
|
||||
|
||||
def can_access_coordinator_only_skill(agent_id: str | None, skill_name: str) -> bool:
|
||||
"""Return whether this runtime identity may discover/read a reserved orchestration skill."""
|
||||
normalized = (skill_name or "").strip().lower()
|
||||
return normalized not in COORDINATOR_ONLY_SKILL_NAMES or agent_id == _ROUNDTABLE_COORDINATOR_AGENT_ID
|
||||
|
||||
|
||||
def is_coordinator_only_skill_path(path: str) -> bool:
|
||||
"""Recognize reserved skill directories in virtual/container paths."""
|
||||
parts = {part.strip().lower() for part in (path or "").replace("\\", "/").split("/") if part}
|
||||
return bool(parts & COORDINATOR_ONLY_SKILL_NAMES)
|
||||
|
||||
|
||||
def _resolve_active_agent_id(runtime: ToolRuntime | None) -> str | None:
|
||||
"""Extract the agent_id under which the current tool call is running.
|
||||
@@ -22,12 +37,13 @@ def _resolve_active_agent_id(runtime: ToolRuntime | None) -> str | None:
|
||||
return None
|
||||
try:
|
||||
if getattr(runtime, "context", None):
|
||||
ctx_id = runtime.context.get("agent_id")
|
||||
ctx_id = runtime.context.get("agent_id") or runtime.context.get("agent_name")
|
||||
if ctx_id:
|
||||
return str(ctx_id)
|
||||
cfg = getattr(runtime, "config", None)
|
||||
if isinstance(cfg, dict):
|
||||
cid = cfg.get("configurable", {}).get("agent_id")
|
||||
configurable = cfg.get("configurable", {})
|
||||
cid = configurable.get("agent_id") or configurable.get("agent_name")
|
||||
if cid:
|
||||
return str(cid)
|
||||
except Exception:
|
||||
@@ -61,7 +77,11 @@ def _load_agent_skill_whitelist(agent_id: str | None, extra_skills: list[str] |
|
||||
cfg = load_agent_config(agent_id)
|
||||
if cfg is None:
|
||||
return None
|
||||
allowed = set(cfg.skills or [])
|
||||
allowed = {
|
||||
name
|
||||
for name in (cfg.skills or [])
|
||||
if can_access_coordinator_only_skill(agent_id, name)
|
||||
}
|
||||
except Exception:
|
||||
logger.debug("Failed to load agent config for skill_list filter", exc_info=True)
|
||||
return None
|
||||
@@ -137,6 +157,9 @@ def skill_view_impl(name: str, agent_id: str | None, extra_skills: list[str] | N
|
||||
guessing skill names. Replies "not found" rather than "forbidden" to
|
||||
avoid leaking which skills exist.
|
||||
"""
|
||||
if not can_access_coordinator_only_skill(agent_id, name):
|
||||
return f"Skill '{name}' not found."
|
||||
|
||||
from deerflow.skills.storage import get_or_new_skill_storage
|
||||
from deerflow.skills.usage import bump_view
|
||||
|
||||
@@ -151,6 +174,7 @@ def skill_view_impl(name: str, agent_id: str | None, extra_skills: list[str] | N
|
||||
elif storage.public_skill_exists(name):
|
||||
skill_file = storage.get_skills_root_path()
|
||||
from pathlib import Path
|
||||
|
||||
from deerflow.skills.types import SKILL_MD_FILE
|
||||
|
||||
path = Path(skill_file) / "public" / name / SKILL_MD_FILE
|
||||
@@ -241,6 +265,8 @@ def search_skills_impl(query: str, agent_id: str | None, top_n: int = 5, extra_s
|
||||
base_path = _resolve_skills_container_base_path()
|
||||
scored: list[tuple[int, dict]] = []
|
||||
for skill in skills:
|
||||
if not can_access_coordinator_only_skill(agent_id, skill.name):
|
||||
continue
|
||||
entry = usage.get(skill.name, {})
|
||||
if allowed is not None:
|
||||
if skill.name not in allowed:
|
||||
@@ -331,6 +357,8 @@ def skill_list_impl(agent_id: str | None, extra_skills: list[str] | None = None)
|
||||
usage = all_entries()
|
||||
result = []
|
||||
for skill in skills:
|
||||
if not can_access_coordinator_only_skill(agent_id, skill.name):
|
||||
continue
|
||||
entry = usage.get(skill.name, {})
|
||||
if allowed is not None:
|
||||
# 自定义 agent:严格按 config.yaml 的 skills 白名单过滤。
|
||||
|
||||
Reference in new issue
Block a user