Version: 0.9.12.dev.260410

后端:
1. chat 路由新增“二次粗排硬闸门”,避免粗排完成后的微调请求误触发再次 rough_build
   - 更新 node/chat.go:当上下文已存在 rough_build_done 且用户未明确要求“重新粗排/从头重排”时,强制关闭 needs_rough_build / needs_refine_after_rough_build;补充路由调试日志维度(needs_rough_build、allow_reorder、has_rough_build_done 等)
   - 更新 prompt/chat.go:补齐二次粗排强约束,明确“移动/微调/优化/均匀化/调顺序”默认走 refine,不再次触发 rough build
2. execute 历史分层与工具调用写回链路增强
   - 更新 node/execute.go:next_plan 推进后写入 execute_step_advanced marker,供 prompt 按步骤边界归档 loop;新增统一 appendToolCallResultHistory,标准化 assistant tool_call + tool observation 配对写回
   - 更新 node/execute.go:confirm accept 路径补齐 min_context_switch 顺序护栏,避免通过确认链路绕过“未授权打乱顺序”限制
   - 更新 prompt/execute_context.go:ReAct 边界识别从 loop_closed 扩展到 loop_closed/step_advanced;执行态文案收敛为“existing 仅作事实参考不作为可移动目标”,并新增参数纪律提示
   - 更新 service/agentsvc/agent_newagent.go:冷恢复重置时仅在 completed 场景补写 execute_loop_closed marker,保证下一轮上下文归档一致
3. 工具参数严格校验落地(禁止自造字段)
   - 新建 tools/arg_guard.go:新增 validateToolArgsStrict 白名单校验,未知字段直接报错(含 day_from/day_to -> day_start/day_end 提示)
   - 更新 tools/read_filter_tools.go:query_available_slots / query_target_tasks 接入参数白名单校验
   - 更新 tools/compound_tools.go:spread_even 接入参数白名单校验
   - 更新 prompt/execute.go:系统提示补齐“参数必须严格使用 schema 字段”强约束与非法别名示例
4. execute 范围护栏辅助能力预埋
   - 更新 node/execute.go:新增步骤范围解析与日历参数解析辅助(周/天/周几提取、候选 day 估算、batch_move new_day 提取等),为后续步骤级范围拦截提供基础能力
5. 记忆模块方案文档升级(吸收 Mem0 机制)
   - 更新 memory/记忆模块实施计划.md:补充 Mem0 借鉴与取舍,新增 ADD/UPDATE/DELETE/NONE 决策状态机、UUID 映射防幻觉、JSON 容错链、threshold->reranker->fallback、三维隔离过滤与对应指标/测试项
6. 同步更新调试日志文件
   - 更新 newAgent/Log.txt
前端:无
仓库:无
This commit is contained in:
Losita
2026-04-10 00:38:02 +08:00
parent 574d44c332
commit ee34d5f111
11 changed files with 3543 additions and 2585 deletions

View File

@@ -29,6 +29,9 @@ const chatRoutingSystemPrompt = `
- plan用户明确要求先制定计划或涉及多阶段复杂规划。speak 写确认语。
粗排判断:当用户意图包含"批量安排/排课/把任务类排进日程",且上下文中有任务类 ID 时,设置 needs_rough_build=true。
二次粗排约束(强约束):
- 若上下文已出现 rough_build_done且用户未明确要求“重新粗排/从头重排”,必须设置 needs_rough_build=false。
- “移动/微调/优化/均匀化/调顺序”等请求默认视为 refine不得再次触发 rough build。
粗排后微调判断:
- 仅当 needs_rough_build=true 时才判断 needs_refine_after_rough_build。
- 若用户明确提出优化目标/偏好(如"尽量均衡""周三别太满""某门课往后挪"),设 needs_refine_after_rough_build=true。

View File

@@ -33,6 +33,7 @@ const executeSystemPromptWithPlan = `
11. 若当前顺序策略是“默认保持顺序”,禁止调用 min_context_switch。
12. 不要把超过 2 条任务打包到 batch_move大批量调整请改走队列逐项处理。
13. 不要在未获取队首queue_pop_head时直接调用 queue_apply_head_move。
14. 工具参数必须严格使用 schema 字段,禁止自造别名;例如 day_from/day_to 非法,必须改用 day_start/day_end。
执行规则:
1. 只输出严格 JSON不要输出 markdown不要在 JSON 外补充文本。
@@ -73,6 +74,7 @@ const executeSystemPromptReAct = `
10. 若顺序策略为“保持顺序”,禁止调用 min_context_switch。
11. 不要在同一轮构造大规模 batch_movebatch_move 最多 2 条,超过请走队列逐项处理。
12. 未调用 queue_pop_head 获取 current 前,不要调用 queue_apply_head_move。
13. 工具参数必须严格使用 schema 字段,禁止自造别名;例如 day_from/day_to 非法,必须改用 day_start/day_end。
执行规则:
1. 只输出严格 JSON不要输出 markdown不要在 JSON 外补充文本。

View File

@@ -15,6 +15,7 @@ const (
executeHistoryKindKey = "newagent_history_kind"
executeHistoryKindCorrectionUser = "llm_correction_prompt"
executeHistoryKindLoopClosed = "execute_loop_closed"
executeHistoryKindStepAdvanced = "execute_step_advanced"
// executeLoopWindowLimit 控制“当轮 ReAct Loop 窗口”最多保留多少条记录。
// 采用固定窗口能避免上下文无上限增长,且可保持“最近行为”可追踪。
@@ -217,7 +218,7 @@ func splitExecuteLoopRecordsByBoundary(history []*schema.Message) (archived []ex
return nil, nil
}
boundary := findLatestExecuteLoopClosedMarker(history)
boundary := findLatestExecuteBoundaryMarker(history)
if boundary < 0 {
return nil, collectExecuteLoopRecords(history)
}
@@ -231,7 +232,7 @@ func splitExecuteLoopRecordsByBoundary(history []*schema.Message) (archived []ex
return archived, active
}
func findLatestExecuteLoopClosedMarker(history []*schema.Message) int {
func findLatestExecuteBoundaryMarker(history []*schema.Message) int {
for i := len(history) - 1; i >= 0; i-- {
msg := history[i]
if msg == nil || msg.Extra == nil {
@@ -241,7 +242,8 @@ func findLatestExecuteLoopClosedMarker(history []*schema.Message) int {
if !ok {
continue
}
if strings.TrimSpace(kind) == executeHistoryKindLoopClosed {
switch strings.TrimSpace(kind) {
case executeHistoryKindLoopClosed, executeHistoryKindStepAdvanced:
return i
}
}
@@ -407,8 +409,9 @@ func buildExecuteMessage3(state *newagentmodel.CommonState, ctx *newagentmodel.C
lines = append(lines, "- 啥时候结束Loop你可以根据工具调用记录自行判断。")
lines = append(lines, "- 非目标:不重新粗排、不修改无关任务类。")
if hasExecuteRoughBuildDone(ctx) {
lines = append(lines, "- 阶段约束:粗排已完成,本轮只微调 suggestedexisting 仅作已安排事实参考,不做 move/batch_move/spread_even。")
lines = append(lines, "- 阶段约束:粗排已完成,本轮只微调 suggestedexisting 仅作已安排事实参考,不作为可移动目标。")
}
lines = append(lines, "- 参数纪律:工具参数必须严格使用 schema 字段;若返回“参数非法”,需先改参再继续。")
if state != nil {
if state.AllowReorder {
lines = append(lines, "- 顺序策略:用户已明确允许打乱顺序,可在必要时使用 min_context_switch。")