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

@@ -126,8 +126,26 @@ func RunChatNode(ctx context.Context, input ChatNodeInput) error {
return nil
}
log.Printf("[DEBUG] chat routing chat=%s route=%s reason=%s",
flowState.ConversationID, decision.Route, decision.Reason)
// 1. 二次粗排硬闸门:若上下文已存在 rough_build_done 且用户未明确要求“重新粗排”,
// 则强制关闭 needs_rough_build避免“微调请求被误判成再次粗排”。
// 2. 该闸门只收紧粗排开关,不改路由 route确保 execute 微调链路仍可继续。
// 3. 一旦用户明确表达“从头重排/重新粗排”,仍允许 needs_rough_build=true 生效。
if shouldDisableRoughBuildForRefine(conversationContext, input.UserInput, decision) {
decision.NeedsRoughBuild = false
decision.NeedsRefineAfterRoughBuild = false
}
log.Printf(
"[DEBUG] chat routing chat=%s route=%s needs_rough_build=%v needs_refine_after_rough_build=%v allow_reorder=%v has_rough_build_done=%v task_class_count=%d reason=%s",
flowState.ConversationID,
decision.Route,
decision.NeedsRoughBuild,
decision.NeedsRefineAfterRoughBuild,
decision.AllowReorder,
hasRoughBuildDoneMarker(conversationContext),
len(flowState.TaskClassIDs),
decision.Reason,
)
flowState.AllowReorder = resolveAllowReorder(input.UserInput, decision.AllowReorder)
// 3. 按路由决策推进。
@@ -314,6 +332,62 @@ func containsAnyPhrase(text string, phrases []string) bool {
return false
}
// shouldDisableRoughBuildForRefine 判断是否应在 chat 路由阶段关闭“再次粗排”。
//
// 判定规则:
// 1. 当前决策未请求粗排时,直接不干预;
// 2. 上下文不存在 rough_build_done 时,不干预(首次粗排仍可走);
// 3. 若用户未明确要求“重新粗排/从头重排”,则关闭粗排开关,避免误触发。
func shouldDisableRoughBuildForRefine(
conversationContext *newagentmodel.ConversationContext,
userInput string,
decision *newagentmodel.ChatRoutingDecision,
) bool {
if decision == nil || !decision.NeedsRoughBuild {
return false
}
if !hasRoughBuildDoneMarker(conversationContext) {
return false
}
return !isExplicitRoughBuildRequest(userInput)
}
func hasRoughBuildDoneMarker(conversationContext *newagentmodel.ConversationContext) bool {
if conversationContext == nil {
return false
}
for _, block := range conversationContext.PinnedBlocksSnapshot() {
if strings.TrimSpace(block.Key) == "rough_build_done" {
return true
}
}
return false
}
// isExplicitRoughBuildRequest 识别用户是否明确要求“重新粗排/从头重排”。
func isExplicitRoughBuildRequest(userInput string) bool {
text := strings.ToLower(strings.TrimSpace(userInput))
if text == "" {
return false
}
keywords := []string{
"重新粗排",
"重做粗排",
"从头排",
"从头重排",
"重新排一遍",
"重新排课",
"重排全部",
"全部重排",
"重置排程",
"重置后重排",
"重新生成初稿",
"rebuild",
"from scratch",
}
return containsAnyPhrase(text, keywords)
}
// handleDeepAnswer 处理复杂问答:推送过渡语 → 原地开 thinking 再调一次 LLM → 输出深度回答。
func handleDeepAnswer(
ctx context.Context,