Version: 0.9.10.dev.260409

后端:
1. newAgent 运行态重置双保险落地,并补齐写工具后的实时排程预览刷新
   - 更新 model/common_state.go:新增 ResetForNextRun,统一清理 round/plan/rough_build/allow_reorder/terminal 等执行期临时状态
   - 更新 node/chat.go + service/agentsvc/agent_newagent.go:在“无 pending 且上一轮已 done”时分别于 chat 主入口与 loadOrCreateRuntimeState 冷加载处执行兜底重置,覆盖正常新一轮对话与断线恢复场景
   - 更新 model/graph_run_state.go + node/agent_nodes.go + node/execute.go:写工具执行后立即刷新 Redis 排程预览,Deliver 继续保留最终覆盖写,保证前端能及时看到最新操作结果
2. 顺序守卫从“直接中止”改为“优先自动复原 suggested 相对顺序”
   - 更新 node/order_guard.go:检测到 suggested 顺序被打乱后,不再直接 abort;改为复用当前坑位按 baseline 自动回填,并在复原失败时仅记录诊断日志后继续交付
   - 更新 tools/state.go:ScheduleState 新增 RuntimeQueue 运行态快照字段,支持队列化处理与断线恢复
3. 多任务微调工具链升级:新增筛选/队列工具并替换首空位查询口径
   - 新建 tools/read_filter_tools.go + tools/runtime_queue.go + tools/queue_tools.go:新增 query_available_slots / query_target_tasks / queue_pop_head / queue_apply_head_move / queue_skip_head / queue_status,支持“先筛选目标,再逐项处理”的稳定微调链路
   - 更新 tools/registry.go + tools/write_tools.go + tools/read_helpers.go:移除 find_first_free 注册口径;batch_move 限制为最多 2 条,超过时引导改走队列逐项处理;queue_apply_head_move 纳入写工具集合
4. 复合规划工具扩充,并改为在 newAgent/tools 本地实现以规避循环导入
   - 更新 tools/compound_tools.go + tools/registry.go:spread_even 正式接入,并与 min_context_switch 一起作为复合写工具保留在 newAgent/tools 内部实现,不再依赖外层 logic
5. prompt 与工具文档同步升级,明确当前用户诉求锚点与队列化执行约束
   - 更新 prompt/execute.go + prompt/execute_context.go + prompt/plan.go:执行提示默认引导 query_target_tasks(enqueue=true) → queue_pop_head → query_available_slots → queue_apply_head_move / queue_skip_head;补齐 batch_move 上限、spread_even 使用边界、顺序策略与工具 JSON 返回示例
   - 更新 prompt/execute_context.go:将“初始用户目标”改为“当前用户诉求”,并保留首轮目标来源;旧 observation 折叠文案改为“当前工具调用结果已经被使用过,当前无需使用,为节省上下文空间,已折叠”
   - 更新 tools/SCHEDULE_TOOLS.md:同步补齐 query_* / queue_* / spread_even / min_context_switch 的说明、限制与返回示例
6. 同步更新调试日志文件
前端:无
仓库:无
This commit is contained in:
LoveLosita
2026-04-09 16:17:56 +08:00
parent 21b864390b
commit 821c2cde5d
20 changed files with 5809 additions and 2685 deletions

View File

@@ -0,0 +1,177 @@
package newagenttools
// TaskProcessingQueue 表示 execute 阶段的“逐项处理队列”运行态。
//
// 职责边界:
// 1. PendingTaskIDs尚未开始处理的候选任务
// 2. CurrentTaskID当前正在处理的队首任务0 表示暂无);
// 3. CompletedTaskIDs / SkippedTaskIDs本轮处理结果归档
// 4. LastError最近一次 apply 失败的原因,供 LLM 下一轮决策参考。
type TaskProcessingQueue struct {
PendingTaskIDs []int `json:"pending_task_ids,omitempty"`
CurrentTaskID int `json:"current_task_id,omitempty"`
CurrentAttempts int `json:"current_attempts,omitempty"`
CompletedTaskIDs []int `json:"completed_task_ids,omitempty"`
SkippedTaskIDs []int `json:"skipped_task_ids,omitempty"`
LastError string `json:"last_error,omitempty"`
}
// ensureTaskProcessingQueue 确保 state 上有可用队列容器。
func ensureTaskProcessingQueue(state *ScheduleState) *TaskProcessingQueue {
if state == nil {
return nil
}
if state.RuntimeQueue == nil {
state.RuntimeQueue = &TaskProcessingQueue{}
}
return state.RuntimeQueue
}
// ResetTaskProcessingQueue 清空本轮临时队列,供“新一轮执行开始”时调用。
func ResetTaskProcessingQueue(state *ScheduleState) {
if state == nil {
return
}
state.RuntimeQueue = nil
}
// ReplaceTaskProcessingQueue 用新的任务 ID 列表覆盖队列。
//
// 步骤化说明:
// 1. 先重置队列,避免上一次处理结果残留;
// 2. 对输入任务 ID 去重,防止 LLM 重复筛选造成同任务重复入队;
// 3. 不自动弹出当前任务,保持“显式 queue_pop_head 才开始处理”的流程约束。
func ReplaceTaskProcessingQueue(state *ScheduleState, taskIDs []int) int {
queue := ensureTaskProcessingQueue(state)
if queue == nil {
return 0
}
queue.PendingTaskIDs = nil
queue.CurrentTaskID = 0
queue.CurrentAttempts = 0
queue.CompletedTaskIDs = nil
queue.SkippedTaskIDs = nil
queue.LastError = ""
return appendTaskIDsToQueue(state, taskIDs)
}
// appendTaskIDsToQueue 将任务追加到队列尾部并做去重,返回本次实际入队数量。
//
// 去重规则:
// 1. 与当前正在处理的任务去重;
// 2. 与 pending / completed / skipped 去重;
// 3. task_id<=0 直接忽略,避免无效数据污染队列。
func appendTaskIDsToQueue(state *ScheduleState, taskIDs []int) int {
queue := ensureTaskProcessingQueue(state)
if queue == nil || len(taskIDs) == 0 {
return 0
}
exists := make(map[int]struct{}, len(queue.PendingTaskIDs)+len(queue.CompletedTaskIDs)+len(queue.SkippedTaskIDs)+1)
if queue.CurrentTaskID > 0 {
exists[queue.CurrentTaskID] = struct{}{}
}
for _, id := range queue.PendingTaskIDs {
exists[id] = struct{}{}
}
for _, id := range queue.CompletedTaskIDs {
exists[id] = struct{}{}
}
for _, id := range queue.SkippedTaskIDs {
exists[id] = struct{}{}
}
added := 0
for _, id := range taskIDs {
if id <= 0 {
continue
}
if _, ok := exists[id]; ok {
continue
}
queue.PendingTaskIDs = append(queue.PendingTaskIDs, id)
exists[id] = struct{}{}
added++
}
return added
}
// popOrGetCurrentTaskID 返回当前可处理任务。
//
// 规则:
// 1. 若已有 CurrentTaskID直接复用保证 apply/skip 前不切换对象);
// 2. 若 current 为空且 pending 非空,则弹出队首并设为 current
// 3. 若队列为空,返回 0。
func popOrGetCurrentTaskID(state *ScheduleState) int {
queue := ensureTaskProcessingQueue(state)
if queue == nil {
return 0
}
if queue.CurrentTaskID > 0 {
return queue.CurrentTaskID
}
if len(queue.PendingTaskIDs) == 0 {
return 0
}
queue.CurrentTaskID = queue.PendingTaskIDs[0]
queue.PendingTaskIDs = queue.PendingTaskIDs[1:]
queue.CurrentAttempts = 0
queue.LastError = ""
return queue.CurrentTaskID
}
// markCurrentTaskCompleted 将 current 任务标记为完成并清空 current。
func markCurrentTaskCompleted(state *ScheduleState) {
queue := ensureTaskProcessingQueue(state)
if queue == nil || queue.CurrentTaskID <= 0 {
return
}
queue.CompletedTaskIDs = append(queue.CompletedTaskIDs, queue.CurrentTaskID)
queue.CurrentTaskID = 0
queue.CurrentAttempts = 0
queue.LastError = ""
}
// markCurrentTaskSkipped 将 current 任务标记为跳过并清空 current。
func markCurrentTaskSkipped(state *ScheduleState) {
queue := ensureTaskProcessingQueue(state)
if queue == nil || queue.CurrentTaskID <= 0 {
return
}
queue.SkippedTaskIDs = append(queue.SkippedTaskIDs, queue.CurrentTaskID)
queue.CurrentTaskID = 0
queue.CurrentAttempts = 0
queue.LastError = ""
}
// bumpCurrentTaskAttempt 记录 current 任务一次失败尝试。
func bumpCurrentTaskAttempt(state *ScheduleState, errText string) {
queue := ensureTaskProcessingQueue(state)
if queue == nil || queue.CurrentTaskID <= 0 {
return
}
queue.CurrentAttempts++
queue.LastError = errText
}
// cloneTaskProcessingQueue 深拷贝 RuntimeQueue。
func cloneTaskProcessingQueue(src *TaskProcessingQueue) *TaskProcessingQueue {
if src == nil {
return nil
}
dst := &TaskProcessingQueue{
CurrentTaskID: src.CurrentTaskID,
CurrentAttempts: src.CurrentAttempts,
LastError: src.LastError,
}
if len(src.PendingTaskIDs) > 0 {
dst.PendingTaskIDs = append([]int(nil), src.PendingTaskIDs...)
}
if len(src.CompletedTaskIDs) > 0 {
dst.CompletedTaskIDs = append([]int(nil), src.CompletedTaskIDs...)
}
if len(src.SkippedTaskIDs) > 0 {
dst.SkippedTaskIDs = append([]int(nil), src.SkippedTaskIDs...)
}
return dst
}