后端: 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 前端:无 仓库:无
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package newagenttools
|
||
|
||
import (
|
||
"fmt"
|
||
"sort"
|
||
"strings"
|
||
)
|
||
|
||
// validateToolArgsStrict 校验工具参数是否全部命中 schema 白名单。
|
||
//
|
||
// 职责边界:
|
||
// 1. 只做“字段名是否允许”的校验,不校验字段值合法性;
|
||
// 2. 发现未知字段时直接报错,避免静默忽略导致范围漂移;
|
||
// 3. 该函数不做别名兼容,调用方应自行传入 schema 中允许的字段。
|
||
func validateToolArgsStrict(args map[string]any, allowedKeys []string) error {
|
||
if len(args) == 0 {
|
||
return nil
|
||
}
|
||
allowed := make(map[string]struct{}, len(allowedKeys))
|
||
for _, key := range allowedKeys {
|
||
allowed[strings.TrimSpace(key)] = struct{}{}
|
||
}
|
||
|
||
unknown := make([]string, 0, len(args))
|
||
for key := range args {
|
||
trimmed := strings.TrimSpace(key)
|
||
if trimmed == "" {
|
||
continue
|
||
}
|
||
if _, ok := allowed[trimmed]; ok {
|
||
continue
|
||
}
|
||
unknown = append(unknown, trimmed)
|
||
}
|
||
if len(unknown) == 0 {
|
||
return nil
|
||
}
|
||
|
||
sort.Strings(unknown)
|
||
hint := "请仅使用当前工具 schema 中声明的参数字段。"
|
||
if containsAnyUnknownArg(unknown, "day_from", "day_to") {
|
||
hint = "请仅使用当前工具 schema 中声明的参数字段;day_from/day_to 不受支持,请改用 day_start/day_end。"
|
||
}
|
||
return fmt.Errorf("参数非法:%s。%s", strings.Join(unknown, "、"), hint)
|
||
}
|
||
|
||
func containsAnyUnknownArg(keys []string, targets ...string) bool {
|
||
if len(keys) == 0 || len(targets) == 0 {
|
||
return false
|
||
}
|
||
targetSet := make(map[string]struct{}, len(targets))
|
||
for _, target := range targets {
|
||
targetSet[strings.TrimSpace(target)] = struct{}{}
|
||
}
|
||
for _, key := range keys {
|
||
if _, ok := targetSet[strings.TrimSpace(key)]; ok {
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
}
|