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

Method Execute

pkg/agent/workflow/sequential.go:68–108  ·  view source on GitHub ↗

Execute 顺序执行所有子 Agent(仅一次)

(ctx context.Context, message string)

Source from the content-addressed store, hash-verified

66
67// Execute 顺序执行所有子 Agent(仅一次)
68func (a *SequentialAgent) Execute(ctx context.Context, message string) *stream.Reader[*session.Event] {
69 reader, writer := stream.Pipe[*session.Event](10)
70
71 go func() {
72 defer writer.Close()
73
74 // 顺序执行所有子 Agent
75 for i, subAgent := range a.subAgents {
76 branch := fmt.Sprintf("%s.%s", a.name, subAgent.Name())
77
78 subReader := subAgent.Execute(ctx, message)
79 for {
80 event, err := subReader.Recv()
81 if err != nil {
82 if errors.Is(err, io.EOF) {
83 break
84 }
85 // 传递错误
86 writer.Send(nil, err)
87 return // 遇到错误停止
88 }
89
90 // 丰富事件信息
91 enrichedEvent := a.enrichSequentialEvent(event, branch, i)
92
93 // 传递事件
94 if writer.Send(enrichedEvent, nil) {
95 return // 客户端取消
96 }
97 }
98
99 // 检查上下文取消
100 if ctx.Err() != nil {
101 writer.Send(nil, ctx.Err())
102 return
103 }
104 }
105 }()
106
107 return reader
108}
109
110// enrichSequentialEvent 丰富顺序执行事件信息
111func (a *SequentialAgent) enrichSequentialEvent(event *session.Event, branch string, index int) *session.Event {

Callers 3

sequentialExampleFunction · 0.95
nestedExampleFunction · 0.95
mainFunction · 0.95

Calls 6

enrichSequentialEventMethod · 0.95
RecvMethod · 0.80
CloseMethod · 0.65
NameMethod · 0.65
ExecuteMethod · 0.65
SendMethod · 0.45

Tested by

no test coverage detected