Files
smartmate/backend/newAgent/HANDOFF_execute_history_reform.md
LoveLosita e77d42fce5 Version: 0.9.19.dev.260415
后端:
1. 移除 list_tasks 读工具,消除与 query_target_tasks 的功能重叠
- 删除backend/newAgent/tools/registry.go 中 list_tools 注册
- 删除 backend/newAgent/tools/schedule/read_tools.go 中 ListTasks 函数及 6个独有辅助函数(formatExistingList / formatSuggestedList / formatPendingList / formatListTasksEmptyResult / looksLikeTaskClassIDList / validateListTasksStatus)
- 更新 backend/newAgent/prompt/execute.go:清理全部 list_tasks 相关规则约束并重新编号,统一工具引用为query_target_tasks
- 更新 backend/newAgent/prompt/execute_context.go:删除 list_tasks 返回值示例 case 分支
- 更新backend/newAgent/tools/schedule/read_helpers.go / status.go:清理注释中的 list_tasks 引用 2. 新增 execute 历史消息注入改造 handoff 文档
-新建 backend/newAgent/HANDOFF_execute_history_reform.md:记录 msg1 从人工摘要改为真实对话流(user + assistant speak)的改造方案,待后续实施
前端:无
仓库:无
2026-04-15 11:52:50 +08:00

3.4 KiB
Raw Blame History

Execute 阶段历史消息注入改造 Handoff

背景

execute 阶段给 LLM 的 4 条消息msg0-msg3全部是人工构造的摘要原始对话历史从未被直接注入。 导致断连恢复后 "继续" 成为孤立的 currentGoalLLM 无法从上下文推断原始意图。

现状

消息结构 (execute_context.go:50-67)

msg0 (System):     规则 + 工具简表
msg1 (Assistant):  历史摘要 — 用 pickExecuteUserInputs 提取 firstUser/lastUser 拼成一行
msg2 (Assistant):  当轮 ReAct Loop 窗口 — thought/tool_call/observation 详细记录
msg3 (System):     执行状态 + 锚点 — 又用 firstUser/lastUser 拼 "当前用户诉求"/"首轮目标来源"

History 存储方式 (execute.go)

每一轮 ReAct loop 往 ConversationContext.History 写 3 条消息:

  1. assistant + speak自然语言如 "我先查看当前安排。"
  2. assistant + ToolCalls工具调用 JSONcontent 为空)
  3. tool + observation工具返回可能很长

问题函数

  • pickExecuteUserInputs() (execute_context.go:772) — 从全量 history 取第一条和最后一条 user message
  • extractExecuteGoalAnchors() (execute_context.go:751) — 用上面的结果作为 initial/current goal
  • buildExecuteMessage1V3() (execute_context.go:269) — 把 goal 拼成摘要行
  • buildExecuteMessage3() (execute_context.go:351) — 把 goal 拼成执行锚点

改造方案

核心思路

msg1 从"人工提炼的摘要"变成"真实对话流"。只注入 user + assistant speak,不含 tool_call / observation这些已由 msg2 承载)。

改造后的消息结构

msg0 (System):     规则 + 工具简表(不变)
msg1 (Assistant):  真实对话历史user + assistant speak 交替)
msg2 (Assistant):  当轮 ReAct Loop 窗口(不变)
msg3 (System):     执行状态(删掉 goal 锚点,因为 msg1 已包含完整意图链)

msg1 改造示例

现在:

历史上下文(仅供参考):
- 用户目标:帮我排一下这些任务类;最近补充:继续
- 历史归档 ReAct 摘要:已折叠 15 条旧记录...

改造后:

对话历史:
user: "帮我把周末的课整到工作日"
assistant: "好的,我来查看当前安排。"
assistant: "已找到6个周末任务开始逐个移动。"
assistant: "第一个任务已移动完成。"
user: "继续"
assistant: "继续处理剩余任务。"

历史归档 ReAct 摘要:已折叠 15 条旧记录...

msg3 改造

删掉以下由 firstUser/lastUser 驱动的锚点:

  • 当前用户诉求xxx
  • 首轮目标来源xxx

保留其他锚点轮次、模式、plan 步骤、任务类等)。

上下文开销

speak 都是短句1-2 句60 轮 execute 约 60 条 speak远小于 msg2 里的工具结果 JSON。 可考虑加条数上限(如最近 30 条 user+assistant超出部分走归档摘要。

涉及文件

文件 改动
prompt/execute_context.go 重写 buildExecuteMessage1V3,新增从 history 提取 user+speak 的函数;删 pickExecuteUserInputs / extractExecuteGoalAnchors;简化 buildExecuteMessage3
prompt/execute.go 无改动(系统规则不含 list_tasks 相关内容,已清理)
node/execute.go 无改动history 写入逻辑已经存了 speak无需修改

已完成的前置工作

  • list_tasks 工具已删除registry / prompt / context 全部清理干净,编译通过)