NewLoopAgent 创建循环 Agent
(cfg LoopConfig)
| 46 | |
| 47 | // NewLoopAgent 创建循环 Agent |
| 48 | func NewLoopAgent(cfg LoopConfig) (*LoopAgent, error) { |
| 49 | if cfg.Name == "" { |
| 50 | return nil, errors.New("agent name is required") |
| 51 | } |
| 52 | |
| 53 | if len(cfg.SubAgents) == 0 { |
| 54 | return nil, errors.New("at least one sub-agent is required") |
| 55 | } |
| 56 | |
| 57 | if cfg.MaxIterations == 0 && cfg.StopCondition == nil { |
| 58 | return nil, errors.New("either MaxIterations or StopCondition must be specified") |
| 59 | } |
| 60 | |
| 61 | // 默认停止条件:检查 Escalate 标志 |
| 62 | stopCondition := cfg.StopCondition |
| 63 | if stopCondition == nil { |
| 64 | stopCondition = func(event *session.Event) bool { |
| 65 | return event != nil && event.Actions.Escalate |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return &LoopAgent{ |
| 70 | name: cfg.Name, |
| 71 | subAgents: cfg.SubAgents, |
| 72 | maxIterations: cfg.MaxIterations, |
| 73 | shouldStop: stopCondition, |
| 74 | }, nil |
| 75 | } |
| 76 | |
| 77 | // Name 返回 Agent 名称 |
| 78 | func (a *LoopAgent) Name() string { |
no outgoing calls
no test coverage detected