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

Method Execute

pkg/workflow/router.go:49–181  ·  view source on GitHub ↗

Execute 执行 Router - 选择步骤并顺序链接执行

(ctx context.Context, input *StepInput)

Source from the content-addressed store, hash-verified

47
48// Execute 执行 Router - 选择步骤并顺序链接执行
49func (r *Router) Execute(ctx context.Context, input *StepInput) *stream.Reader[*StepOutput] {
50 reader, writer := stream.Pipe[*StepOutput](1)
51
52 go func() {
53 defer writer.Close()
54 startTime := time.Now()
55
56 // 调用选择器函数
57 stepsToExecute := r.selector(input)
58
59 if len(stepsToExecute) == 0 {
60 // 没有选中任何步骤
61 output := &StepOutput{
62 StepID: r.id,
63 StepName: r.name,
64 StepType: StepTypeRouter,
65 Content: fmt.Sprintf("Router %s: no steps selected", r.name),
66 StartTime: startTime,
67 EndTime: time.Now(),
68 NestedSteps: []*StepOutput{},
69 Metadata: map[string]any{
70 "selected_steps": 0,
71 },
72 Metrics: &StepMetrics{ExecutionTime: time.Since(startTime).Seconds()},
73 }
74 output.Duration = output.EndTime.Sub(output.StartTime).Seconds()
75 writer.Send(output, nil)
76 return
77 }
78
79 // 收集所有执行结果
80 allResults := make([]*StepOutput, 0, len(stepsToExecute))
81 currentInput := input
82 routerStepOutputs := make(map[string]*StepOutput)
83
84 // 顺序执行选中的步骤(链接模式)
85 for i, step := range stepsToExecute {
86 // 更新输入:使用前一步的输出
87 if i > 0 && len(allResults) > 0 {
88 lastOutput := allResults[len(allResults)-1]
89 currentInput = &StepInput{
90 Input: input.Input,
91 PreviousStepContent: lastOutput.Content,
92 PreviousStepOutputs: routerStepOutputs,
93 AdditionalData: input.AdditionalData,
94 SessionState: input.SessionState,
95 Images: input.Images,
96 Videos: input.Videos,
97 Audio: input.Audio,
98 Files: input.Files,
99 WorkflowSession: input.WorkflowSession,
100 }
101 }
102
103 // 执行步骤
104 var stepOutput *StepOutput
105 var stepError error
106

Callers

nothing calls this directly

Implementers 1

StaticRouterpkg/router/router.go

Calls 7

getStepNamesFunction · 0.85
RecvMethod · 0.80
CloseMethod · 0.65
ExecuteMethod · 0.65
NameMethod · 0.65
ErrorMethod · 0.65
SendMethod · 0.45

Tested by

no test coverage detected