Version: 0.9.8.dev.260408

后端:
1.execute 上下文瘦身第一版落地(固定 4 消息骨架 + ReAct 窗口压缩 + JSON 输出约束)
  - 新建 prompt/execute_context.go:
    execute 阶段改为 message[0..3] 固定结构;
    加入历史摘要、当轮 ReAct 绑定展示、同工具 observation 压缩(保留最新)与工具简表返回示例提示
  - 更新 prompt/execute.go:
    重写 plan/ReAct 执行提示词;
    补齐“可做/不可做”约束;
    统一严格 JSON 指令;
    补充 tool_call.arguments/abort/speak 非空等格式护栏
  - 更新 model/execute_contract.go:
    新增 ExecuteDecision/ToolCallIntent 自定义 Unmarshal;
    兼容空字符串占位与 tool_call.parameters→arguments 回退解析
  - 更新 node/correction.go:
    为 correction 注入 history kind 标记,避免被当作真实用户输入污染摘要
  - 更新 node/execute.go:
    补齐 continue/ask_user/confirm 的 speak 兜底;
    移除工具结果写入前 3000 字截断

2.工具层微调语义重构(任务视角概览 + 首个空位查询 + 移动权限收紧)
  - 更新 tools/read_tools.go:
    get_overview 改为任务视角全量输出(课程仅占位统计);
    新增 find_first_free(首个命中位 + 当日负载明细);
    find_free 保留兼容别名;
    list_tasks 增加 status/category 校验与空结果纠偏文案
  - 更新 tools/registry.go:
    注册 find_first_free;
    find_free 改兼容别名;
    同步 get_overview/list_tasks/move/batch_move 描述语义
  - 更新 tools/write_tools.go:
    move/batch_move 仅允许 suggested,existing/pending 明确拒绝并返回可读错误
  - 更新 tools/SCHEDULE_TOOLS.md:
    同步 get_overview/find_first_free/list_tasks/move/batch_move 的最新入参与返回示例
  - 更新 prompt/plan.go:
    读工具示例由 find_free 调整为 find_first_free

3.交接文档与阶段说明同步
  - 更新 newAgent/HANDOFF_粗排修复与Prompt重构.md:
    更新为 2026-04-08;
    补充“最新增量交接”章节(当前主矛盾、P0/P1、验证清单)
  - 更新 newAgent/阶段3_上下文瘦身设计.md:
    同步 existing/suggested 的 move/batch_move 约束口径
  - 更新 newAgent/Log.txt:
    追加本轮 execute 调试日志快照

前端:无
仓库:无
This commit is contained in:
LoveLosita
2026-04-08 21:35:05 +08:00
parent d3f65609f0
commit 4195e65cba
13 changed files with 4692 additions and 332 deletions

View File

@@ -8,6 +8,11 @@ import (
"github.com/cloudwego/eino/schema"
)
const (
correctionHistoryKindKey = "newagent_history_kind"
correctionHistoryKindCorrectionUser = "llm_correction_prompt"
)
// AppendLLMCorrection 追加 LLM 修正提示到对话历史。
//
// 设计目的:
@@ -56,6 +61,9 @@ func AppendLLMCorrection(
conversationContext.AppendHistory(&schema.Message{
Role: schema.User,
Content: correctionContent,
Extra: map[string]any{
correctionHistoryKindKey: correctionHistoryKindCorrectionUser,
},
})
}
@@ -96,5 +104,8 @@ func AppendLLMCorrectionWithHint(
conversationContext.AppendHistory(&schema.Message{
Role: schema.User,
Content: correctionContent,
Extra: map[string]any{
correctionHistoryKindKey: correctionHistoryKindCorrectionUser,
},
})
}

View File

@@ -246,6 +246,10 @@ func RunExecuteNode(ctx context.Context, input ExecuteNodeInput) error {
// 决策合法,重置连续修正计数。
flowState.ConsecutiveCorrections = 0
// speak 兜底continue / ask_user / confirm 三类动作对前端可读文案是强依赖。
// 若模型漏填 speak这里回退到 reason 或默认短句,避免前端出现“静默一轮”。
decision.Speak = buildExecuteSpeakWithFallback(decision)
// speak 后处理:补列表序号换行 + 末尾加 \n 防止连续 speak 在前端粘连。
decision.Speak = normalizeSpeak(decision.Speak) // 末尾已含 \n
@@ -425,6 +429,42 @@ func resolveExecuteAskUserText(decision *newagentmodel.ExecuteDecision) string {
return "执行过程中遇到不确定的情况,需要向你确认。"
}
// buildExecuteSpeakWithFallback 统一为需要面向用户展示的动作补齐 speak 文案。
//
// 规则:
// 1. continue / ask_user / confirm 缺 speak 时,优先回退到 reason
// 2. 若 reason 也为空,再按动作使用最短默认文案;
// 3. next_plan / done / abort 不强制补 speak避免影响终止与收口语义。
func buildExecuteSpeakWithFallback(decision *newagentmodel.ExecuteDecision) string {
if decision == nil {
return ""
}
speak := strings.TrimSpace(decision.Speak)
if speak != "" {
return speak
}
switch decision.Action {
case newagentmodel.ExecuteActionContinue,
newagentmodel.ExecuteActionAskUser,
newagentmodel.ExecuteActionConfirm:
if reason := strings.TrimSpace(decision.Reason); reason != "" {
return reason
}
switch decision.Action {
case newagentmodel.ExecuteActionAskUser:
return "我还缺少一条关键信息,想先向你确认。"
case newagentmodel.ExecuteActionConfirm:
return "我先整理好这一步操作,等待你的确认。"
default:
return "我先继续这一步处理,马上给你结果。"
}
default:
return speak
}
}
// handleExecuteActionConfirm 处理 LLM 申报的写操作确认请求。
//
// 步骤:
@@ -566,12 +606,6 @@ func executeToolCall(
flattenForLog(result),
)
// 2.5 截断过大的工具结果,防止上下文膨胀导致后续 LLM 调用返回空或超限。
const maxToolResultLen = 3000
if len(result) > maxToolResultLen {
result = result[:maxToolResultLen] + fmt.Sprintf("\n...(结果已截断,原始长度 %d 字符)", len(result))
}
// 3. 将工具调用和结果以合法的 assistant+tool 消息对追加到对话历史。
//
// 修复说明: