MCPcopy Create free account
hub / github.com/astercloud/aster / NewLoopAgent

Function NewLoopAgent

pkg/agent/workflow/loop.go:48–75  ·  view source on GitHub ↗

NewLoopAgent 创建循环 Agent

(cfg LoopConfig)

Source from the content-addressed store, hash-verified

46
47// NewLoopAgent 创建循环 Agent
48func 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 名称
78func (a *LoopAgent) Name() string {

Callers 3

buildLoopDemoMethod · 0.92
loopExampleFunction · 0.92
NewSequentialAgentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected