sync update from LAN repo (source master @ ca48c4ec)

This commit is contained in:
gozeros committed 2026-11-05 10:53:54 +08:00
1 parent 8bc8b0e082
commit ea9dcff9c0
873 files changed
+107866 -14011

No files matched your search

@@ -58,6 +58,41 @@ def _enforce_agent_orchestration_scope(
if allow_agent_orchestration:
return tools
return [tool for tool in tools if tool.name != "agent_orchestration"]
async def get_available_tools_async(
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,
*,
allowed_tools: list[str] | None = None,
allow_agent_orchestration: bool = False,
app_config: AppConfig | None = None,
write_file_compatibility: bool | None = None,
) -> list[BaseTool]:
"""Load tools without blocking the caller loop or its MCP discovery.
Share bounded initialization with agent construction and restore the
resulting deferred-tool registry into the calling task before execution.
"""
from deerflow.utils.background_init import run_background_init
return await run_background_init(
get_available_tools,
groups=groups,
include_mcp=include_mcp,
model_name=model_name,
subagent_enabled=subagent_enabled,
is_scheduled_run=is_scheduled_run,
excluded_tools=excluded_tools,
allowed_tools=allowed_tools,
allow_agent_orchestration=allow_agent_orchestration,
app_config=app_config,
write_file_compatibility=write_file_compatibility,
)
def get_available_tools(
@@ -68,8 +103,10 @@ def get_available_tools(
is_scheduled_run: bool = False,
excluded_tools: list[str] | None = None,
*,
allowed_tools: list[str] | None = None,
allow_agent_orchestration: bool = False,
app_config: AppConfig | None = None,
write_file_compatibility: bool | None = None,
) -> list[BaseTool]:
"""Get all available tools from config.
@@ -84,6 +121,10 @@ def get_available_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``.
allowed_tools: Optional request-scoped allowlist applied after all tools
have been resolved. ``None`` keeps the normal tool surface; an empty
list disables every ordinary tool. Exclusions are applied afterwards
and therefore still win.
allow_agent_orchestration: Explicit coordinator-only capability gate. Defaults to
``False`` so ordinary agents and all indirect callers fail closed.
@@ -100,6 +141,8 @@ def get_available_tools(
# requests entirely inside PatchedChatOpenAI.
global_write_file_compatibility_enabled = (
get_write_file_compatibility_settings().enabled
if write_file_compatibility is None
else write_file_compatibility
)
write_renderer_enabled = (
not global_write_file_compatibility_enabled
@@ -339,6 +382,22 @@ def get_available_tools(
if not write_renderer_enabled:
unique_tools = [tool for tool in unique_tools if tool.name != _BEGIN_WRITE_FILE_TOOL_NAME]
# Security-sensitive internal runs (notably the roundtable coordinator)
# must fail closed when new configured/builtin/MCP tools are added. A
# denylist cannot provide that guarantee: every new tool would otherwise be
# exposed until each caller remembered to exclude it.
if allowed_tools is not None:
allowed_set = {str(name).strip() for name in allowed_tools if str(name).strip()}
filtered_tools = [tool for tool in unique_tools if tool.name in allowed_set]
if len(filtered_tools) < len(unique_tools):
logger.info(
"Allowed request tool surface contains %d of %d resolved tool(s): %s",
len(filtered_tools),
len(unique_tools),
sorted(allowed_set),
)
unique_tools = filtered_tools
# Drop tools the caller (or config) wants excluded. Request-level
# ``excluded_tools`` wins; the config-level list is the static fallback.
effective_excluded = excluded_tools if excluded_tools else getattr(config, "excluded_tools", None) or []