fix: 会商席位与总控角色隔离,编排能力只归总控
This commit is contained in:
1 parent
ff80cc110d
commit
3384f2e51c
10 files changed
+488
-125
No files matched your search
@@ -16,11 +16,10 @@ BROWSER_ACT_TOOL_USE = "deerflow.tools.builtins.browser_act_tool:browser_act_too
|
||||
BROWSER_CONTEXT_TOOL_USES = {BROWSER_CONTEXT_TOOL_USE, BROWSER_ACT_TOOL_USE}
|
||||
BROWSER_CONTEXT_TOOL_NAMES = {"browser_fetch_page", "browser_act"}
|
||||
|
||||
BUILTIN_TOOLS = [
|
||||
present_file_tool,
|
||||
ask_clarification_tool,
|
||||
agent_orchestration_tool,
|
||||
]
|
||||
BUILTIN_TOOLS = [
|
||||
present_file_tool,
|
||||
ask_clarification_tool,
|
||||
]
|
||||
|
||||
SUBAGENT_TOOLS = [
|
||||
task_tool,
|
||||
@@ -39,24 +38,36 @@ def _is_host_bash_tool(tool: object) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def _is_browser_context_tool(tool: object) -> bool:
|
||||
def _is_browser_context_tool(tool: object) -> bool:
|
||||
"""Return True if the tool config represents the browser extension bridge."""
|
||||
|
||||
use = getattr(tool, "use", None)
|
||||
name = getattr(tool, "name", None)
|
||||
return use in BROWSER_CONTEXT_TOOL_USES or name in BROWSER_CONTEXT_TOOL_NAMES
|
||||
return use in BROWSER_CONTEXT_TOOL_USES or name in BROWSER_CONTEXT_TOOL_NAMES
|
||||
|
||||
|
||||
def _enforce_agent_orchestration_scope(
|
||||
tools: list[BaseTool],
|
||||
*,
|
||||
allow_agent_orchestration: bool,
|
||||
) -> list[BaseTool]:
|
||||
"""Fail closed: only an explicitly authorized coordinator may receive orchestration."""
|
||||
if allow_agent_orchestration:
|
||||
return tools
|
||||
return [tool for tool in tools if tool.name != "agent_orchestration"]
|
||||
|
||||
|
||||
def get_available_tools(
|
||||
def get_available_tools(
|
||||
groups: list[str] | None = None,
|
||||
include_mcp: bool = True,
|
||||
model_name: str | None = None,
|
||||
subagent_enabled: bool = False,
|
||||
is_scheduled_run: bool = False,
|
||||
excluded_tools: list[str] | None = None,
|
||||
*,
|
||||
app_config: AppConfig | None = None,
|
||||
) -> list[BaseTool]:
|
||||
excluded_tools: list[str] | None = None,
|
||||
*,
|
||||
allow_agent_orchestration: bool = False,
|
||||
app_config: AppConfig | None = None,
|
||||
) -> list[BaseTool]:
|
||||
"""Get all available tools from config.
|
||||
|
||||
Note: MCP tools should be initialized at application startup using
|
||||
@@ -67,9 +78,11 @@ def get_available_tools(
|
||||
include_mcp: Whether to include tools from MCP servers (default: True).
|
||||
model_name: Optional model name to determine if vision tools should be included.
|
||||
subagent_enabled: Whether to include subagent tools (task, task_status).
|
||||
excluded_tools: Optional list of tool names to exclude from the result
|
||||
(applied AFTER all other resolution). Takes precedence over
|
||||
``app_config.excluded_tools``.
|
||||
excluded_tools: Optional list of tool names to exclude from the result
|
||||
(applied AFTER all other resolution). Takes precedence over
|
||||
``app_config.excluded_tools``.
|
||||
allow_agent_orchestration: Explicit coordinator-only capability gate. Defaults to
|
||||
``False`` so ordinary agents and all indirect callers fail closed.
|
||||
|
||||
Returns:
|
||||
List of available tools.
|
||||
@@ -114,8 +127,10 @@ def get_available_tools(
|
||||
|
||||
loaded_tools = [t for _, t in loaded_tools_raw]
|
||||
|
||||
# Conditionally add tools based on config
|
||||
builtin_tools = BUILTIN_TOOLS.copy()
|
||||
# Conditionally add tools based on config
|
||||
builtin_tools = BUILTIN_TOOLS.copy()
|
||||
if allow_agent_orchestration:
|
||||
builtin_tools.append(agent_orchestration_tool)
|
||||
if not is_scheduled_run:
|
||||
builtin_tools.append(scheduled_task_tool)
|
||||
|
||||
@@ -292,4 +307,8 @@ def get_available_tools(
|
||||
)
|
||||
unique_tools = filtered_tools
|
||||
|
||||
return unique_tools
|
||||
# Defense in depth: a config/MCP tool with the reserved name must not bypass the builtin gate.
|
||||
return _enforce_agent_orchestration_scope(
|
||||
unique_tools,
|
||||
allow_agent_orchestration=allow_agent_orchestration,
|
||||
)
|
||||
Reference in new issue
Block a user