sync update from LAN repo (source master-nj @ 067eb808)

This commit is contained in:
gozeros committed 2026-11-10 14:04:09 +08:00
1 parent 1244fb1f2f
commit 1d5dd8fc90
182 files changed
+18973 -769

No files matched your search

@@ -180,6 +180,8 @@ def build_writing_research_config(
focus: str | None = None,
thinking_enabled: bool = False,
model_name: str | None = None,
project_mode: str | None = None,
project_report_config: dict | None = None,
) -> DeepResearchConfig:
"""组装聊天写作模式的研究配置:basic + 通用分析结构 + adaptive。
@@ -191,12 +193,23 @@ def build_writing_research_config(
parts: list[str] = []
if focus and focus.strip():
parts.append(focus.strip())
parts.append(_KNOWLEDGE_WRITE_INSTRUCTION)
from deerflow.agents.analysis_project import SOLUTION_OUTLINE
fixed_solution = project_mode == "solution"
project_report_config = project_report_config or {}
outline = project_report_config.get("custom_outline") or SOLUTION_OUTLINE
structure_mode = project_report_config.get("structure_mode", "fixed") if fixed_solution else "adaptive"
parts.append(
"遵循项目所选报告结构及固定/弹性约束。引用本项目对话资料;缺失事实、预算、责任人标注待补充,不得编造。"
if fixed_solution else _KNOWLEDGE_WRITE_INSTRUCTION
)
return DeepResearchConfig(
mode="basic",
collection_mode="legacy",
custom_outline=GENERAL_OUTLINE,
structure_mode="adaptive",
custom_outline=outline if fixed_solution else GENERAL_OUTLINE,
structure_mode=structure_mode,
retrieval_directions=project_report_config.get("retrieval_directions", []) if fixed_solution else [],
retrieval_skills=project_report_config.get("retrieval_skills", []) if fixed_solution else [],
generate_images=False,
thinking_enabled=thinking_enabled,
fast_model=model_name,
@@ -434,7 +447,9 @@ async def deep_research_report_tool(
query = topic.strip()
state = getattr(runtime, "state", None) or {}
conversation_messages = state.get("messages") or []
harvested, _agent_summary = harvest_messages_materials(conversation_messages, query=query)
project_context = (runtime.context or {}).get("analysis_project") or {}
harvest_options = {"include_rag_sources": True} if project_context.get("mode") == "solution" else {}
harvested, _agent_summary = harvest_messages_materials(conversation_messages, query=query, **harvest_options)
# 课题请求之后的检索结果整批保留(那是模型为本课题检索的);只有课题
# 切换前的旧检索才按词面强过滤(旧课题资料不得凑门槛、不得入报告)。
anchor_index = topic_anchor_index(conversation_messages, topic=query)
@@ -476,6 +491,8 @@ async def deep_research_report_tool(
focus=focus,
thinking_enabled=thinking_enabled,
model_name=model_name,
project_mode=project_context.get("mode"),
project_report_config=project_context.get("report_config"),
)
llm_backend = DeerFlowCompletionBackend(
research_config,
@@ -135,8 +135,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)