后端: 1.彻底删除原agent文件夹,并将现agent2文件夹全量重命名为agent(包括全部涉及到的文件以及文档、注释),迁移工作完美结束 2.修复了重试消息的相关逻辑问题 前端: 1.改善了一些交互体验,修复了一些bug,现在只剩少的功能了,现存的bug基本都修复完毕 全仓库: 1.更新了决策记录和README文档
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package agent
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
|
||
agentrouter "github.com/LoveLosita/smartflow/backend/agent/router"
|
||
)
|
||
|
||
// Service 是 agent 模块的总入口。
|
||
//
|
||
// 职责边界:
|
||
// 1. 负责接住一次完整的 Agent 请求,并把请求交给统一路由器分流;
|
||
// 2. 负责维护“路由器 + 各 skill handler”的装配关系;
|
||
// 3. 不负责具体 skill 的 graph 连线,也不负责节点内部业务实现。
|
||
type Service struct {
|
||
dispatcher *agentrouter.Dispatcher
|
||
}
|
||
|
||
// NewService 创建 agent 总入口服务。
|
||
func NewService(resolver agentrouter.Resolver) *Service {
|
||
return &Service{
|
||
dispatcher: agentrouter.NewDispatcher(resolver),
|
||
}
|
||
}
|
||
|
||
// RegisterHandler 注册某个 skill 的执行入口。
|
||
func (s *Service) RegisterHandler(action agentrouter.Action, handler agentrouter.SkillHandler) error {
|
||
if s == nil || s.dispatcher == nil {
|
||
return errors.New("agent service is not initialized")
|
||
}
|
||
return s.dispatcher.Register(action, handler)
|
||
}
|
||
|
||
// Handle 是 agent 的统一处理入口。
|
||
func (s *Service) Handle(ctx context.Context, req *agentrouter.AgentRequest) (*agentrouter.AgentResponse, error) {
|
||
if s == nil || s.dispatcher == nil {
|
||
return nil, errors.New("agent service is not initialized")
|
||
}
|
||
return s.dispatcher.Dispatch(ctx, req)
|
||
}
|