sync update from LAN repo (source xuhd-new @ 61fc2949)

This commit is contained in:
gozeros committed 2026-11-17 11:29:05 +08:00
1 parent bbe365429d
commit 7951fb983a
855 files changed
+132201 -6120

No files matched your search

@@ -812,6 +812,12 @@ def make_lead_agent(config: RunnableConfig):
return _make_lead_agent(config, app_config=runtime_app_config or get_app_config())
# The Gateway may build this synchronous graph in its dedicated initializer.
# It restores ContextVar changes and keeps MCP discovery on the request loop;
# graph execution/checkpoint operations still run in the original async task.
make_lead_agent._deerflow_background_build = True
def _make_lead_agent(config: RunnableConfig, *, app_config: AppConfig):
# Lazy import to avoid circular dependency
from deerflow.tools import get_available_tools
@@ -943,6 +949,12 @@ def _make_lead_agent(config: RunnableConfig, *, app_config: AppConfig):
agent_display_name = agent_config.name if agent_config else agent_id
# Custom agent model from agent config (if any), or None to let _resolve_model_name pick the default
agent_model_name = agent_config.model if agent_config and agent_config.model else None
# The global prompt suffix remains on unless this particular custom agent
# explicitly opts out. ``getattr`` preserves compatibility with callers
# that supply lightweight agent-config test doubles.
model_prompt_suffix_enabled = bool(
getattr(agent_config, "model_prompt_suffix_enabled", True)
) if agent_config else True
# Final model name resolution: request → agent config → global default, with fallback for unknown names
model_name = _resolve_model_name(requested_model_name or agent_model_name, app_config=resolved_app_config)
@@ -1002,6 +1014,7 @@ def _make_lead_agent(config: RunnableConfig, *, app_config: AppConfig):
"agent_id": agent_id,
"agent_name": agent_display_name or "default",
"model_name": model_name or "default",
"model_prompt_suffix_enabled": model_prompt_suffix_enabled,
"thinking_enabled": thinking_enabled,
"reasoning_effort": reasoning_effort,
"is_plan_mode": is_plan_mode,
@@ -1134,6 +1147,7 @@ def _make_lead_agent(config: RunnableConfig, *, app_config: AppConfig):
allow_agent_orchestration=agent_id in _COORDINATOR_AGENT_IDS,
app_config=resolved_app_config,
write_file_compatibility=write_file_compatibility,
browser_skill_requested=bool(cfg.get("browser_skill_enabled", False)),
)
)
if agent_id == FORCED_RESEARCH_AGENT_ID:
@@ -1146,7 +1160,12 @@ def _make_lead_agent(config: RunnableConfig, *, app_config: AppConfig):
# 模型手工 write_file。续写轮(已有 report.md)不挂,保持原有「直接编辑
# 该文件」行为。不受 tool_groups/excluded_tools 过滤——它是写作模式合约
# 的核心交付手段。
if writing_mode and not writing_artifact_path and not classic_knowledge_space_strict:
# Workbench delivery writes only from collected materials; it does not
# expand the selected knowledge scope or enable external search tools.
workbench_report_delivery = workbench_write_now and bool(cfg.get("workbench_session_id"))
if writing_mode and not writing_artifact_path and (
not classic_knowledge_space_strict or workbench_report_delivery
):
from deerflow.tools.builtins.deep_research_report_tool import deep_research_report_tool
default_tools = [*default_tools, deep_research_report_tool]
@@ -1239,6 +1258,14 @@ def _make_lead_agent(config: RunnableConfig, *, app_config: AppConfig):
system_prompt += project_system_prompt(cfg)
if cfg.get("knowledge_research_session_id") and disable_tools:
from deerflow.agents.lead_agent.knowledge_research_prompt import KNOWLEDGE_RESEARCH_PROMPT
# Research is an inline document editor. Generic file/tool contracts
# contradict this server-enforced tool-free mode.
system_prompt = KNOWLEDGE_RESEARCH_PROMPT
_log_es_query_routing_registration(
system_prompt=system_prompt,
app_config=resolved_app_config,
@@ -1247,7 +1274,15 @@ def _make_lead_agent(config: RunnableConfig, *, app_config: AppConfig):
)
return create_agent(
model=create_chat_model(name=model_name, thinking_enabled=thinking_enabled, reasoning_effort=reasoning_effort, force_disable_thinking=thinking_force_disabled, write_file_compatibility=write_file_compatibility, app_config=resolved_app_config),
model=create_chat_model(
name=model_name,
thinking_enabled=thinking_enabled,
reasoning_effort=reasoning_effort,
force_disable_thinking=thinking_force_disabled,
write_file_compatibility=write_file_compatibility,
prompt_suffix_enabled=model_prompt_suffix_enabled,
app_config=resolved_app_config,
),
tools=default_tools,
middleware=_build_middlewares(config, model_name=model_name, agent_name=agent_id, app_config=resolved_app_config),
system_prompt=system_prompt,