Version: 0.9.9.dev.260408

后端:
1. 粗排后分流与顺序守卫落地,支持“无明确微调偏好时粗排后直接收口”,并新增 allow_reorder / needs_refine_after_rough_build 语义,打通 chat→rough_build→execute/order_guard→deliver 路由。
2. execute 工具执行链路修复:清理乱码坏块与重复分支;新增 min_context_switch 未授权拦截;补齐 suggested 顺序基线初始化与顺序守卫联动。
3. 新增复合写工具 min_context_switch(减少上下文切换)并接入注册、参数解析、写工具白名单、提示词与文档;仅在用户明确允许打乱顺序时可用。
4. 工具口径升级:find_first_free 支持 day/day_start/day_end 范围参数并统一文案;移除 find_free 兼容别名;读写工具输出统一到“第N天(星期X)”格式。
5. prompt 同步升级:chat/execute/execute_context 增加粗排后是否继续微调、顺序授权、min_context_switch 使用边界与返回示例约束。
6. handoff 文档重命名并重写下班交接重点:下一步聚焦“工具收敛能力研究 + 运行态必要参数重置(不丢运行态)”。
7. 同步更新调试日志文件。
前端:无
仓库:无
This commit is contained in:
Losita
2026-04-08 23:55:09 +08:00
parent 4195e65cba
commit 21b864390b
21 changed files with 3546 additions and 1009 deletions

View File

@@ -29,17 +29,29 @@ const chatRoutingSystemPrompt = `
- plan用户明确要求先制定计划或涉及多阶段复杂规划。speak 写确认语。
粗排判断:当用户意图包含"批量安排/排课/把任务类排进日程",且上下文中有任务类 ID 时,设置 needs_rough_build=true。
粗排后微调判断:
- 仅当 needs_rough_build=true 时才判断 needs_refine_after_rough_build。
- 若用户明确提出优化目标/偏好(如"尽量均衡""周三别太满""某门课往后挪"),设 needs_refine_after_rough_build=true。
- 若用户只要求"先排进去/给初稿",未提出微调目标,设 needs_refine_after_rough_build=false。
顺序授权判断:
- allow_reorder 仅在用户明确说明“允许打乱顺序/顺序不重要”时才为 true。
- 用户明确要求“保持顺序/不要打乱”时必须为 false。
- 若用户未明确提及顺序,一律为 false。
输出协议(严格 JSON
{"route":"direct_reply / execute / deep_answer / plan","speak":"给用户看的话","needs_rough_build":false,"reason":"简短判断依据"}
{"route":"direct_reply / execute / deep_answer / plan","speak":"给用户看的话","needs_rough_build":false,"needs_refine_after_rough_build":false,"allow_reorder":false,"reason":"简短判断依据"}
合法示例:
{"route":"direct_reply","speak":"你好!我是 SmartFlow 助手,有什么可以帮你的?","reason":"用户打招呼"}
{"route":"execute","speak":"好的,我来帮你看看今天的安排。","reason":"需要调用工具查询日程","needs_rough_build":false}
{"route":"execute","speak":"好的,我来帮你看看今天的安排。","reason":"需要调用工具查询日程","needs_rough_build":false,"needs_refine_after_rough_build":false,"allow_reorder":false}
{"route":"execute","speak":"好的,我来帮你排课。","reason":"批量排课需求,有任务类 ID","needs_rough_build":true}
{"route":"execute","speak":"好的,我来帮你排课。","reason":"批量排课需求,有任务类 ID,未给微调偏好","needs_rough_build":true,"needs_refine_after_rough_build":false,"allow_reorder":false}
{"route":"execute","speak":"好的,我来帮你排课并按你的偏好做微调。","reason":"批量排课需求,有任务类 ID且给出明确微调偏好","needs_rough_build":true,"needs_refine_after_rough_build":true,"allow_reorder":false}
{"route":"execute","speak":"好的,我按你的要求重排。","reason":"用户明确允许打乱顺序","needs_rough_build":false,"needs_refine_after_rough_build":false,"allow_reorder":true}
{"route":"deep_answer","speak":"这是个好问题,让我仔细想想。","reason":"需要深度分析但不需要工具"}
@@ -65,6 +77,9 @@ func BuildChatRoutingUserPrompt(ctx *newagentmodel.ConversationContext, userInpu
var sb strings.Builder
sb.WriteString("请判断用户本轮意图的复杂度,并选择最合适的路由。\n")
sb.WriteString("若 route=execute 且 needs_rough_build=true请同时判断 needs_refine_after_rough_build")
sb.WriteString("只有用户明确提出微调目标时才为 true。\n")
sb.WriteString("请同时输出 allow_reorder只有用户明确授权打乱顺序时才为 true默认 false。\n")
// 注入任务类上下文(供粗排判断参考)。
if state != nil && len(state.TaskClassIDs) > 0 {

View File

@@ -15,16 +15,21 @@ const executeSystemPromptWithPlan = `
1. 只围绕当前步骤推进,先读后写,逐步完成当前步骤。
2. 可调用读工具补充事实,再决定下一步。
3. 需要写操作时输出 action=confirm 并附带 tool_call等待用户确认。
4. 若用户给出了“二次微调方向”(如负载均衡、某天减负、某类任务后移),优先围绕该方向推进,并在 goal_check 说明满足情况。
5. 只有在用户明确允许打乱顺序时,才可使用 min_context_switch 做重排。
你不要做什么:
1. 不要跳到其他 plan 步骤,不要越级执行。
2. 不要伪造工具结果。
3. 如果上下文明确“粗排已完成/rough_build_done”不要把任务当成未排入不要重新逐个手动 place。
4. 不要连续重复同类查询而没有推进连续两轮同类读查询后必须转入执行、ask_user或明确阻塞原因
5. list_tasks 的 status 只允许单值all / existing / suggested / pending。禁止使用 "existing,suggested" 这类拼接值
6. 若工具结果与已知事实明显冲突如无写操作却从“有任务”变成“0任务”先自我纠错并重查一次不要直接 ask_user
7. 不要连续两轮调用“同一读工具 + 等价 arguments”若上一轮已成功返回下一轮必须换工具或进入 confirm
8. list_tasks.category 只接受任务类名称,不接受 task_class_ids如 "1,2,3"
4. 如果上下文明确“当前未收到明确微调偏好/本轮先收口”,不要继续微调,直接输出 action=done
5. 不要连续重复同类查询而没有推进连续两轮同类读查询后必须转入执行、ask_user或明确阻塞原因
6. list_tasks 的 status 只允许单值all / existing / suggested / pending。禁止使用 "existing,suggested" 这类拼接值
7. 若工具结果与已知事实明显冲突如无写操作却从“有任务”变成“0任务”先自我纠错并重查一次不要直接 ask_user
8. 不要连续两轮调用“同一读工具 + 等价 arguments”若上一轮已成功返回下一轮必须换工具或进入 confirm
9. list_tasks.category 只接受任务类名称,不接受 task_class_ids如 "1,2,3")。
10. 不要忽略用户最新补充的微调方向;若与旧目标冲突,以最新用户要求为准。
11. 若当前顺序策略是“默认保持顺序”,禁止调用 min_context_switch。
执行规则:
1. 只输出严格 JSON不要输出 markdown不要在 JSON 外补充文本。
@@ -41,12 +46,15 @@ const executeSystemPromptReAct = `
阶段事实(强约束):
1. 若上下文给出“粗排已完成/rough_build_done”表示目标任务类已经进入 suggested/existing不是待排入状态。
2. 当前阶段目标是“微调”,不是“重新粗排”。
3. 若上下文明确“当前未收到明确微调偏好/本轮先收口”,应直接结束而不是继续优化循环。
4. 若用户提出了二次微调方向,本轮优先目标就是满足该方向。
你可以做什么:
1. 你可以基于科学排程原则(负载均衡、学习连贯性、冲突最小化)对 suggested 做微调。
1. 你可以基于用户给定的二次微调方向,对 suggested 做定向微调。
2. existing 属于已安排事实层,可用于冲突判断和参考,不作为 move/batch_move 的目标。
3. 你可以先调用读工具补充必要事实(例如 get_overview/list_tasks/find_first_free/get_task_info
4. 你可以在需要改动时提出 confirmmove/swap/unplace/batch_move
5. 只有用户明确允许打乱顺序时,才可使用 min_context_switch。
你不要做什么:
1. 不要假设任务还没排进去,然后改成逐个手动 place。
@@ -56,6 +64,9 @@ const executeSystemPromptReAct = `
5. 若工具结果与已知事实明显冲突如无写操作却从“有任务”变成“0任务”先自我纠错并重查一次不要直接 ask_user。
6. 不要连续两轮调用“同一读工具 + 等价 arguments”若上一轮已成功返回下一轮必须换工具或进入 confirm。
7. list_tasks.category 只接受任务类名称,不接受 task_class_ids如 "1,2,3")。
8. 若已明确“本轮先收口”,不要继续调用 list_tasks/find_first_free/move 做无目标微调。
9. 若用户明确了微调方向,不要只做“局部看起来更空”的随机调整;每次改动都要能对应到该方向。
10. 若顺序策略为“保持顺序”,禁止调用 min_context_switch。
执行规则:
1. 只输出严格 JSON不要输出 markdown不要在 JSON 外补充文本。
@@ -353,6 +364,9 @@ func buildExecuteStrictJSONUserPrompt() string {
- list_tasks.arguments.category 仅接受任务类名称,不要传 task_class_ids如 "1,2,3"
- 若读工具结果与已知事实明显冲突,先修正参数并重查一次,再决定是否 ask_user
- 不要连续两轮调用“同一读工具 + 等价 arguments”若上一轮已成功返回下一轮必须换工具或进入 confirm
- 若用户本轮给了二次微调方向,优先满足该方向,再考虑通用均衡优化
- 若上下文已明确“当前未收到微调偏好,本轮先收口”,请直接输出 action=done
- 仅当顺序策略明确允许打乱顺序时,才可以调用 min_context_switch
`)
}

View File

@@ -174,6 +174,13 @@ func buildExecuteMessage3(state *newagentmodel.CommonState, ctx *newagentmodel.C
if hasExecuteRoughBuildDone(ctx) {
lines = append(lines, "- 阶段约束:粗排已完成,本轮只微调 suggestedexisting 仅作已安排事实参考,不做 move/batch_move。")
}
if state != nil {
if state.AllowReorder {
lines = append(lines, "- 顺序策略:用户已明确允许打乱顺序,可在必要时使用 min_context_switch。")
} else {
lines = append(lines, "- 顺序策略:默认保持 suggested 相对顺序,禁止调用 min_context_switch。")
}
}
// 兼容上层传入的执行指令;若为空则使用固定收口指令。
instruction := strings.TrimSpace(runtimeUserPrompt)
@@ -236,8 +243,6 @@ func renderExecuteToolReturnHint(toolName string) (returnType string, sample str
return returnType, "[35]第一章随机事件与概率 | 状态:已预排(suggested) | 占用时段第3天第5-6节"
case "find_first_free":
return returnType, "首个可用位置第5天第1-2节可直接放置| 当日负载总占6/12..."
case "find_free":
return returnType, "兼容别名,返回同 find_first_free。"
case "query_range":
return returnType, "第5天第3-6节第3节空、第4节空..."
case "place":
@@ -248,6 +253,8 @@ func renderExecuteToolReturnHint(toolName string) (returnType string, sample str
return returnType, "交换完成:[35]... ↔ [36]..."
case "batch_move":
return returnType, "批量移动完成2个任务全部成功。"
case "min_context_switch":
return returnType, "最少上下文切换重排完成:共处理 6 个任务,上下文切换次数 5 -> 2。"
case "unplace":
return returnType, "已将 [35]... 移除,恢复为待安排状态。"
default: