fix: 写作管线整批接收对话检索结果,不再自己检索

- 相关性过滤新增位置通道:收割器给每条材料标记来源消息位置,课题
  请求之后的检索结果整批入池(与语言/词面无关)——线上中文课题 +
  英文检索结果被纯词面匹配误杀 31/35 条,报告只带着 4 条残料在写
- 课题切换保护保留:新请求之前的旧课题检索仍按词面强过滤,不凑
  门槛、不入报告;对话里找不到课题消息时退化为原词面过滤
- 删除死代码 HarvestPlusSearchMaterialProvider(retrieve=True 的
  自检索补充分支,早已被显式忽略):写作管线只负责写文件,检索
  全部由对话完成成为结构保证
- 测试:锚点规则(澄清回答不充当新课题)、中文课题+英文资料整批
  保留、课题切换旧检索过滤等场景,25 个用例入库(此前该测试文件
  一直被 tests/* 忽略规则挡在版本库外)
This commit is contained in:
董宏凯 committed 2026-08-30 16:20:55 +08:00
1 parent f7e6ed65bd
commit 2ab3ab8444
4 files changed
+757 -73

No files matched your search

@@ -72,9 +72,7 @@ async def harvest_thread_materials(
visible text (its collection小结) and doubles as a fallback material when
the thread produced no harvestable tool results.
"""
checkpoint_tuple = await checkpointer.aget_tuple(
{"configurable": {"thread_id": runtime_thread_id, "checkpoint_ns": ""}}
)
checkpoint_tuple = await checkpointer.aget_tuple({"configurable": {"thread_id": runtime_thread_id, "checkpoint_ns": ""}})
if checkpoint_tuple is None:
logger.warning("deep-research harvest: no checkpoint for thread %s", runtime_thread_id)
return [], ""
@@ -121,9 +119,14 @@ def harvest_messages_materials(
def _harvest_tool_messages(messages: list[Any], *, query: str) -> list[ResearchMaterial]:
"""Convert every harvestable tool result in the thread into materials."""
"""Convert every harvestable tool result in the thread into materials.
每条材料在 ``metadata["message_index"]`` 记录其来源工具消息在对话中的
位置——写作管线据此区分「课题请求之后检索的(属于当前课题)」与
「课题切换前的旧检索」(后者才做词面相关度过滤)。
"""
materials: list[ResearchMaterial] = []
for message in messages:
for message_index, message in enumerate(messages):
if _message_type(message) != "tool":
continue
tool_name = str(_message_name(message) or "")
@@ -140,15 +143,20 @@ def _harvest_tool_messages(messages: list[Any], *, query: str) -> list[ResearchM
if isinstance(item, dict):
material = result_to_material(item, query=envelope_query)
material.metadata["retrieval_channel"] = "chat_web_search"
material.metadata["message_index"] = message_index
materials.append(material)
continue
materials.extend(
_harvest_generic_payload(payload, tool_name=tool_name, query=query)
)
materials.extend(_harvest_generic_payload(payload, tool_name=tool_name, query=query, message_index=message_index))
return materials
def _harvest_generic_payload(payload: Any, *, tool_name: str, query: str) -> list[ResearchMaterial]:
def _harvest_generic_payload(
payload: Any,
*,
tool_name: str,
query: str,
message_index: int | None = None,
) -> list[ResearchMaterial]:
"""Normalize a non-web_search tool payload (skill/knowledge/bash/MCP)."""
source_type = _TOOL_SOURCE_TYPES.get(tool_name, "other")
materials: list[ResearchMaterial] = []
@@ -177,6 +185,7 @@ def _harvest_generic_payload(payload: Any, *, tool_name: str, query: str) -> lis
metadata={
"retrieval_channel": "chat_tool",
"tool_name": tool_name,
**({"message_index": message_index} if message_index is not None else {}),
},
)
)