🐛 fix(agent/schedulerefine): 修复复合微调分支链路问题,并将 MinContextSwitch 重构为固定坑位重排语义 - 🔧 修复 `schedulerefine` 复合路由中参数透传不完整、缺少 deterministic objective 时错误降级,以及“复合工具执行成功”与“终审通过”语义混淆的问题 - ✅ 保证新的独立复合分支能够正确执行、正确出站,并统一交由 `hard_check` 裁决最终结果 - 🔍 排查时发现 `MinContextSwitch` 上游 `context_tag` 存在整体退化为 `General` 的风险,影响MinContextSwitch - 🛡️ 为 `MinContextSwitch` 增加兜底策略:当标签整体退化时,按任务名关键词推断学科分组,避免分组能力失效 - ♻️ 将 `MinContextSwitch` 从“整周重新寻找新坑位”调整为“坑位不变,任务顺序改变” - 🎯 将落地方式从顺序 `BatchMove` 改为固定坑位原子重写,避免出现远距离跳位、跨天错迁、异常嵌入课位及循环换位冲突 - 🧹 修复 `hard_check` 在 `MinContextSwitch` 成功后仍执行 `origin_rank` 顺序归位、并导致逆序终审误判的问题 - 🚦 命中该分支后跳过顺序归位与顺序硬校验,避免 `summary` / `hard_check` 将有效重排结果误判为失败 📈 当前连续微调规划涉及的全部功能已可以稳定运行;下一步将继续扩展能力边界,并进一步优化 `schedule_plan` 流程 ♻️ refactor: 重整 agent2 架构,并迁移 quicknote/chat 新链路,目前还剩3个模块未迁移,后续迁移完成后会删除原agent并将此目录命名为agent - 🏗️ 明确 `agent2` 采用“统一分层目录 + 文件分层 + 依赖注入”的重构方案,不再沿用模块目录多层嵌套结构 - 🧩 完善 `agent2` 基础骨架,统一收口 `entrance` / `router` / `llm` / `stream` / `shared` / `model` / `prompt` / `node` / `graph` 等层级职责 - 🚚 将通用路由能力迁移至 `agent2/router`,沉淀统一的 `Action`、`RoutingDecision`、控制码解析,以及 `Dispatcher` / `Resolver` 抽象 - 💬 将普通聊天链路迁移至 `agent2/chat`,复用 `stream` 的 OpenAI 兼容输出协议与 LLM usage 聚合能力 - 📝 将 `quicknote` 链路迁移到 `agent2` 新结构,拆分为 `model` / `prompt` / `llm` / `node` / `graph` 多层实现,替换对旧 `agent/quicknote` 的直接依赖 - 🔌 调整 `agentsvc` 对 `agent2` 的引用,普通聊天、通用分流与 `quicknote` 全部切换到新链路 - ✂️ 去除 graph 内部 `runner` 转接层,改为由 node 层直接持有请求级依赖,并向 graph 暴露节点方法 - 🧹 合并 `graph/quicknote` 与 `graph/quicknote_run`,删除冗余骨架文件,收敛为单一 `quicknote graph` 文件 - 📚 新增 `agent2`《通用能力接入文档》,明确公共能力边界、接入方式以及 graph/node 协作约定 - 📝 更新 `AGENTS.md`,要求后续扩展 `agent2` 通用能力时必须同步维护接入文档 ♻️ refactor: 删除了现Agent目录内Chat模块的两条冗余Prompt
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package agentrouter
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
"fmt"
|
||
)
|
||
|
||
// Dispatcher 是 agent2 的统一分发器。
|
||
type Dispatcher struct {
|
||
resolver Resolver
|
||
handlers map[Action]SkillHandler
|
||
}
|
||
|
||
// NewDispatcher 创建统一分发器。
|
||
func NewDispatcher(resolver Resolver) *Dispatcher {
|
||
return &Dispatcher{
|
||
resolver: resolver,
|
||
handlers: make(map[Action]SkillHandler),
|
||
}
|
||
}
|
||
|
||
// Register 注册某个动作的处理函数。
|
||
func (d *Dispatcher) Register(action Action, handler SkillHandler) error {
|
||
if d == nil {
|
||
return errors.New("dispatcher is nil")
|
||
}
|
||
if action == "" {
|
||
return errors.New("route action is empty")
|
||
}
|
||
if handler == nil {
|
||
return fmt.Errorf("handler for action %s is nil", action)
|
||
}
|
||
if _, exists := d.handlers[action]; exists {
|
||
return fmt.Errorf("handler for action %s already registered", action)
|
||
}
|
||
d.handlers[action] = handler
|
||
return nil
|
||
}
|
||
|
||
// Dispatch 执行“分流 -> skill handler”完整入口。
|
||
func (d *Dispatcher) Dispatch(ctx context.Context, req *AgentRequest) (*AgentResponse, error) {
|
||
if d == nil || d.resolver == nil {
|
||
return nil, errors.New("route dispatcher is not ready")
|
||
}
|
||
if req == nil {
|
||
return nil, errors.New("agent request is nil")
|
||
}
|
||
|
||
// 1. 调用目的:统一先走一级路由,让入口层只关心“请求来了”,
|
||
// 不需要提前知道这是普通聊天、随口记、任务查询还是后续排程。
|
||
decision, err := d.resolver.Resolve(ctx, req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
if decision == nil {
|
||
return nil, errors.New("route decision is nil")
|
||
}
|
||
|
||
// 2. 路由结果出来后,只根据 action 查找对应 handler。
|
||
// 这里故意不做 skill 级 fallback,避免路由层和 skill 内部职责再次缠在一起。
|
||
handler, exists := d.handlers[decision.Action]
|
||
if !exists {
|
||
return nil, fmt.Errorf("no handler registered for action %s", decision.Action)
|
||
}
|
||
return handler(ctx, req)
|
||
}
|