NewSequentialAgent 创建顺序 Agent
(cfg SequentialConfig)
| 37 | |
| 38 | // NewSequentialAgent 创建顺序 Agent |
| 39 | func NewSequentialAgent(cfg SequentialConfig) (*SequentialAgent, error) { |
| 40 | if cfg.Name == "" { |
| 41 | return nil, errors.New("agent name is required") |
| 42 | } |
| 43 | |
| 44 | if len(cfg.SubAgents) == 0 { |
| 45 | return nil, errors.New("at least one sub-agent is required") |
| 46 | } |
| 47 | |
| 48 | // SequentialAgent 是 LoopAgent 迭代 1 次的特例 |
| 49 | loopAgent, err := NewLoopAgent(LoopConfig{ |
| 50 | Name: cfg.Name, |
| 51 | SubAgents: cfg.SubAgents, |
| 52 | MaxIterations: 1, |
| 53 | StopCondition: func(event *session.Event) bool { |
| 54 | // Sequential 不依赖 Escalate,总是执行完所有子 Agent |
| 55 | return false |
| 56 | }, |
| 57 | }) |
| 58 | if err != nil { |
| 59 | return nil, fmt.Errorf("failed to create sequential agent: %w", err) |
| 60 | } |
| 61 | |
| 62 | return &SequentialAgent{ |
| 63 | LoopAgent: loopAgent, |
| 64 | }, nil |
| 65 | } |
| 66 | |
| 67 | // Execute 顺序执行所有子 Agent(仅一次) |
| 68 | func (a *SequentialAgent) Execute(ctx context.Context, message string) *stream.Reader[*session.Event] { |
no test coverage detected