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
@@ -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
|
||||
@@ -220,9 +263,15 @@ def get_available_tools(
|
||||
|
||||
local_wiki = getattr(getattr(config.llmwiki, "local_wiki_index", None), "enabled", False)
|
||||
if get_resolved_llmwiki_runtime(config).weknora_enabled or local_wiki or get_assistant_knowledge_store() is not None:
|
||||
from deerflow.tools.builtins.llmwiki_reasoning_tools import (
|
||||
CLASSIC_LLMWIKI_TOOLS,
|
||||
SMART_REASONING_TOOLS,
|
||||
)
|
||||
from deerflow.tools.builtins.llmwiki_search_tool import llmwiki_search_tool
|
||||
|
||||
builtin_tools.append(llmwiki_search_tool)
|
||||
builtin_tools.extend(CLASSIC_LLMWIKI_TOOLS)
|
||||
builtin_tools.extend(SMART_REASONING_TOOLS)
|
||||
except Exception: # noqa: BLE001 - configuration/store failures must not block agent creation
|
||||
logger.debug("Failed to evaluate the conditional LLMWiki search tool", exc_info=True)
|
||||
|
||||
@@ -333,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 []
|
||||
|
||||
Reference in new issue
Block a user