后端: 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. 同步更新调试日志文件。 前端:无 仓库:无
126 lines
3.0 KiB
Go
126 lines
3.0 KiB
Go
package newagenttools
|
||
|
||
import "fmt"
|
||
|
||
// ==================== 参数解析辅助 ====================
|
||
// 这些函数专门用于从 LLM 输出的 map[string]any 中提取工具参数。
|
||
// JSON 反序列化后数字默认为 float64,字符串为 string,需要类型断言。
|
||
|
||
// argsInt 从 map 中提取 int 值。支持 float64(JSON 反序列化的默认类型)。
|
||
func argsInt(args map[string]any, key string) (int, bool) {
|
||
v, ok := args[key]
|
||
if !ok {
|
||
return 0, false
|
||
}
|
||
switch n := v.(type) {
|
||
case float64:
|
||
return int(n), true
|
||
case int:
|
||
return n, true
|
||
}
|
||
return 0, false
|
||
}
|
||
|
||
// argsString 从 map 中提取 string 值。
|
||
func argsString(args map[string]any, key string) (string, bool) {
|
||
v, ok := args[key]
|
||
if !ok {
|
||
return "", false
|
||
}
|
||
s, ok := v.(string)
|
||
return s, ok
|
||
}
|
||
|
||
// argsIntPtr 从 map 中提取可选 int 值,不存在返回 nil。
|
||
func argsIntPtr(args map[string]any, key string) *int {
|
||
v, ok := argsInt(args, key)
|
||
if !ok {
|
||
return nil
|
||
}
|
||
return &v
|
||
}
|
||
|
||
// argsStringPtr 从 map 中提取可选 string 值,不存在返回 nil。
|
||
func argsStringPtr(args map[string]any, key string) *string {
|
||
v, ok := argsString(args, key)
|
||
if !ok {
|
||
return nil
|
||
}
|
||
return &v
|
||
}
|
||
|
||
// argsIntSlice 从 map 中提取 int 数组,支持 []any / []int / []float64。
|
||
func argsIntSlice(args map[string]any, key string) ([]int, bool) {
|
||
v, ok := args[key]
|
||
if !ok {
|
||
return nil, false
|
||
}
|
||
switch arr := v.(type) {
|
||
case []int:
|
||
if len(arr) == 0 {
|
||
return []int{}, true
|
||
}
|
||
result := make([]int, len(arr))
|
||
copy(result, arr)
|
||
return result, true
|
||
case []float64:
|
||
result := make([]int, 0, len(arr))
|
||
for _, item := range arr {
|
||
result = append(result, int(item))
|
||
}
|
||
return result, true
|
||
case []any:
|
||
result := make([]int, 0, len(arr))
|
||
for _, item := range arr {
|
||
switch n := item.(type) {
|
||
case float64:
|
||
result = append(result, int(n))
|
||
case int:
|
||
result = append(result, n)
|
||
default:
|
||
return nil, false
|
||
}
|
||
}
|
||
return result, true
|
||
default:
|
||
return nil, false
|
||
}
|
||
}
|
||
|
||
// argsMoveList 从 map 中提取 batch_move 的 moves 数组。
|
||
func argsMoveList(args map[string]any) ([]MoveRequest, error) {
|
||
v, ok := args["moves"]
|
||
if !ok {
|
||
return nil, fmt.Errorf("缺少 moves 参数")
|
||
}
|
||
arr, ok := v.([]any)
|
||
if !ok {
|
||
return nil, fmt.Errorf("moves 参数必须是数组")
|
||
}
|
||
moves := make([]MoveRequest, 0, len(arr))
|
||
for i, item := range arr {
|
||
m, ok := item.(map[string]any)
|
||
if !ok {
|
||
return nil, fmt.Errorf("moves[%d] 不是有效对象", i)
|
||
}
|
||
taskID, ok := argsInt(m, "task_id")
|
||
if !ok {
|
||
return nil, fmt.Errorf("moves[%d].task_id 缺失或无效", i)
|
||
}
|
||
newDay, ok := argsInt(m, "new_day")
|
||
if !ok {
|
||
return nil, fmt.Errorf("moves[%d].new_day 缺失或无效", i)
|
||
}
|
||
newSlotStart, ok := argsInt(m, "new_slot_start")
|
||
if !ok {
|
||
return nil, fmt.Errorf("moves[%d].new_slot_start 缺失或无效", i)
|
||
}
|
||
moves = append(moves, MoveRequest{
|
||
TaskID: taskID,
|
||
NewDay: newDay,
|
||
NewSlotStart: newSlotStart,
|
||
})
|
||
}
|
||
return moves, nil
|
||
}
|