sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)
This commit is contained in:
1 parent
4f7f07504a
commit
8bc8b0e082
1651 files changed
+278599
-11416
No files matched your search
@@ -2,8 +2,10 @@ import logging
|
||||
|
||||
from langchain.tools import BaseTool
|
||||
|
||||
from deerflow.config import get_app_config
|
||||
from deerflow.config.app_config import AppConfig
|
||||
from deerflow.config import get_app_config
|
||||
from deerflow.config.app_config import AppConfig
|
||||
from deerflow.config.model_config import WriteFileTransport
|
||||
from deerflow.config.system_settings import get_write_file_compatibility_settings
|
||||
from deerflow.reflection import resolve_variable
|
||||
from deerflow.sandbox.security import is_host_bash_allowed
|
||||
from deerflow.tools.builtins import agent_orchestration_tool, ask_clarification_tool, memory_tool, present_file_tool, scheduled_task_tool, task_tool, view_image_tool
|
||||
@@ -15,6 +17,7 @@ BROWSER_CONTEXT_TOOL_USE = "deerflow.tools.builtins.browser_context_tool:browser
|
||||
BROWSER_ACT_TOOL_USE = "deerflow.tools.builtins.browser_act_tool:browser_act_tool"
|
||||
BROWSER_CONTEXT_TOOL_USES = {BROWSER_CONTEXT_TOOL_USE, BROWSER_ACT_TOOL_USE}
|
||||
BROWSER_CONTEXT_TOOL_NAMES = {"browser_fetch_page", "browser_act"}
|
||||
_BEGIN_WRITE_FILE_TOOL_NAME = "begin_write_file"
|
||||
|
||||
BUILTIN_TOOLS = [
|
||||
present_file_tool,
|
||||
@@ -88,11 +91,37 @@ def get_available_tools(
|
||||
List of available tools.
|
||||
"""
|
||||
config = app_config or get_app_config()
|
||||
if model_name is None and config.models:
|
||||
model_name = config.models[0].name
|
||||
selected_model = config.get_model_config(model_name) if model_name else None
|
||||
# Only the two legacy handshake transports need the internal
|
||||
# ``begin_write_file`` tool. ``buffered_gateway`` keeps the original
|
||||
# write_file as the sole graph/runtime tool and performs its two provider
|
||||
# requests entirely inside PatchedChatOpenAI.
|
||||
global_write_file_compatibility_enabled = (
|
||||
get_write_file_compatibility_settings().enabled
|
||||
)
|
||||
write_renderer_enabled = (
|
||||
not global_write_file_compatibility_enabled
|
||||
and getattr(
|
||||
selected_model,
|
||||
"write_file_transport",
|
||||
WriteFileTransport.NATIVE,
|
||||
)
|
||||
in {
|
||||
WriteFileTransport.ARTIFACT_RENDERER,
|
||||
WriteFileTransport.TEXT_BRIDGE,
|
||||
}
|
||||
)
|
||||
selected_tool_configs = [tool for tool in config.tools if groups is None or tool.group in groups]
|
||||
disabled_tool_names = [tool.name for tool in selected_tool_configs if not tool.enabled]
|
||||
if disabled_tool_names:
|
||||
logger.info("Skipping disabled configured tool(s): %s", disabled_tool_names)
|
||||
tool_configs = [tool for tool in selected_tool_configs if tool.enabled]
|
||||
tool_configs = [
|
||||
tool
|
||||
for tool in selected_tool_configs
|
||||
if tool.enabled and (tool.name != _BEGIN_WRITE_FILE_TOOL_NAME or write_renderer_enabled)
|
||||
]
|
||||
|
||||
browser_context_config = getattr(config, "browser_context", None)
|
||||
if not getattr(browser_context_config, "enabled", False):
|
||||
@@ -135,8 +164,14 @@ def get_available_tools(
|
||||
builtin_tools.append(scheduled_task_tool)
|
||||
|
||||
# Memory V2:记忆与 builtin provider 都启用时,暴露 memory 工具给 LLM 主动写入
|
||||
memory_config = getattr(config, "memory", None)
|
||||
if memory_config is not None and getattr(memory_config, "enabled", False):
|
||||
memory_config = getattr(config, "memory", None)
|
||||
try:
|
||||
from deerflow.config.system_settings import get_memory_runtime_settings
|
||||
|
||||
memory_runtime_enabled = get_memory_runtime_settings().enabled
|
||||
except Exception: # noqa: BLE001 - settings failure must keep memory off
|
||||
memory_runtime_enabled = False
|
||||
if memory_runtime_enabled and memory_config is not None:
|
||||
builtin_config = getattr(memory_config, "builtin", None)
|
||||
if builtin_config is not None and getattr(builtin_config, "enabled", False):
|
||||
builtin_tools.append(memory_tool)
|
||||
@@ -177,15 +212,23 @@ def get_available_tools(
|
||||
|
||||
builtin_tools.append(read_peer_delivery_tool)
|
||||
|
||||
# Conditional LLMWiki mode: the tool is absent when no effective WeKnora
|
||||
# address is configured, keeping legacy deployments behavior-identical.
|
||||
# Unified selected-space retrieval is available for local Wiki snapshots,
|
||||
# WeKnora, or the assistant Wiki repository.
|
||||
try:
|
||||
from deerflow.integrations.weknora.runtime import get_resolved_llmwiki_runtime
|
||||
from deerflow.persistence.assistant_knowledge import get_assistant_knowledge_store
|
||||
|
||||
if get_resolved_llmwiki_runtime(config).weknora_enabled:
|
||||
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)
|
||||
|
||||
@@ -209,10 +252,6 @@ def get_available_tools(
|
||||
builtin_tools.extend(SUBAGENT_TOOLS)
|
||||
logger.info("Including subagent tools (task)")
|
||||
|
||||
# If no model_name specified, use the first model (default)
|
||||
if model_name is None and config.models:
|
||||
model_name = config.models[0].name
|
||||
|
||||
# Add view_image_tool when vision is available — either the main model
|
||||
# supports vision natively, or a dedicated vision model is configured
|
||||
# (vision.model_name) so recognition can be delegated to it.
|
||||
@@ -293,6 +332,13 @@ def get_available_tools(
|
||||
t.name,
|
||||
)
|
||||
|
||||
# ``begin_write_file`` is a reserved compatibility handshake, not a
|
||||
# generally useful file tool. Filter by the resolved tool name as defense
|
||||
# in depth so a mismatched config name or an MCP tool cannot expose it to a
|
||||
# native model accidentally.
|
||||
if not write_renderer_enabled:
|
||||
unique_tools = [tool for tool in unique_tools if tool.name != _BEGIN_WRITE_FILE_TOOL_NAME]
|
||||
|
||||
# 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 []
|
||||
@@ -307,6 +353,12 @@ def get_available_tools(
|
||||
)
|
||||
unique_tools = filtered_tools
|
||||
|
||||
# Keep the control tool inseparable from the real writer after *all*
|
||||
# request/config filters. In particular, excluding write_file must never
|
||||
# leave a callable handshake that cannot be committed.
|
||||
if write_renderer_enabled and not any(tool.name == "write_file" for tool in unique_tools):
|
||||
unique_tools = [tool for tool in unique_tools if tool.name != _BEGIN_WRITE_FILE_TOOL_NAME]
|
||||
|
||||
# Defense in depth: a config/MCP tool with the reserved name must not bypass the builtin gate.
|
||||
return _enforce_agent_orchestration_scope(
|
||||
unique_tools,
|
||||
|
||||
Reference in new issue
Block a user