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

@@ -23,6 +23,7 @@ const (
executeStatusBlockID = "execute.status"
executeSpeakBlockID = "execute.speak"
executePinnedKey = "execution_context"
toolMinContextSwitch = "min_context_switch"
// maxConsecutiveCorrections 是 Execute 节点连续修正次数上限。
// 超过此阈值后终止执行,防止 LLM 陷入无限修正循环。
@@ -102,6 +103,14 @@ func RunExecuteNode(ctx context.Context, input ExecuteNodeInput) error {
return executePendingTool(ctx, runtimeState, conversationContext, input.ToolRegistry, input.ScheduleState, input.SchedulePersistor, input.OriginalScheduleState, emitter)
}
// 1.6. 顺序守卫基线初始化:
// 1) 仅在未授权打乱顺序时记录 suggested 顺序基线;
// 2) 只在基线为空时初始化,避免执行循环中反复覆盖;
// 3) 后续由 order_guard 节点基于该基线做相对顺序校验。
if !flowState.AllowReorder && len(flowState.SuggestedOrderBaseline) == 0 {
flowState.SuggestedOrderBaseline = buildSuggestedOrderSnapshot(input.ScheduleState)
}
// 2. 推送执行阶段状态,让前端知道当前进度。
if flowState.HasCurrentPlanStep() {
// 有 plan显示步骤进度。
@@ -592,6 +601,54 @@ func executeToolCall(
}
// 2. 执行工具。
// 顺序护栏:未授权打乱顺序时,拒绝执行 min_context_switch并写回工具观察结果。
if shouldBlockMinContextSwitch(flowState, toolName) {
blockedResult := "已拒绝执行 min_context_switch当前未授权打乱顺序。如需使用该工具请先由用户明确说明“允许打乱顺序”。"
log.Printf(
"[WARN] execute tool blocked chat=%s round=%d tool=%s allow_reorder=%v",
flowState.ConversationID,
flowState.RoundUsed,
toolName,
flowState.AllowReorder,
)
_ = emitter.EmitStatus(
executeStatusBlockID,
executeStageName,
"tool_blocked",
blockedResult,
false,
)
toolCallID := uuid.NewString()
argsJSON := "{}"
if toolCall.Arguments != nil {
if raw, marshalErr := json.Marshal(toolCall.Arguments); marshalErr == nil {
argsJSON = string(raw)
}
}
conversationContext.AppendHistory(&schema.Message{
Role: schema.Assistant,
Content: "",
ToolCalls: []schema.ToolCall{
{
ID: toolCallID,
Type: "function",
Function: schema.FunctionCall{
Name: toolName,
Arguments: argsJSON,
},
},
},
})
conversationContext.AppendHistory(&schema.Message{
Role: schema.Tool,
Content: blockedResult,
ToolCallID: toolCallID,
ToolName: toolName,
})
return nil
}
beforeDigest := summarizeScheduleStateForDebug(scheduleState)
result := registry.Execute(scheduleState, toolName, toolCall.Arguments)
afterDigest := summarizeScheduleStateForDebug(scheduleState)
@@ -646,6 +703,19 @@ func executeToolCall(
return nil
}
// shouldBlockMinContextSwitch 判断是否要拦截 min_context_switch 工具。
//
// 说明:
// 1. 仅当工具名为 min_context_switch 且未授权打乱顺序时返回 true
// 2. 其余场景统一放行;
// 3. nil flowState 视为未命中拦截条件,避免因状态缺失导致误阻断。
func shouldBlockMinContextSwitch(flowState *newagentmodel.CommonState, toolName string) bool {
if flowState == nil {
return false
}
return !flowState.AllowReorder && strings.EqualFold(strings.TrimSpace(toolName), toolMinContextSwitch)
}
// executePendingTool 执行用户已确认的写工具。
//
// 职责边界: