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

Function sequentialExample

examples/workflow-agents/main.go:44–75  ·  view source on GitHub ↗

sequentialExample 顺序工作流示例

(ctx context.Context)

Source from the content-addressed store, hash-verified

42
43// sequentialExample 顺序工作流示例
44func sequentialExample(ctx context.Context) {
45 // 创建子 Agent
46 agents := []workflow.Agent{
47 NewMockAgent("DataCollector", "收集数据"),
48 NewMockAgent("Analyzer", "分析数据"),
49 NewMockAgent("Reporter", "生成报告"),
50 }
51
52 // 创建 SequentialAgent
53 sequential, err := workflow.NewSequentialAgent(workflow.SequentialConfig{
54 Name: "DataPipeline",
55 SubAgents: agents,
56 })
57 if err != nil {
58 log.Fatal(err)
59 }
60
61 // 执行
62 fmt.Println("开始顺序执行:")
63 reader := sequential.Execute(ctx, "处理用户数据")
64 for {
65 event, err := reader.Recv()
66 if err != nil {
67 if errors.Is(err, io.EOF) {
68 break
69 }
70 log.Printf("错误: %v", err)
71 break
72 }
73 printEvent(event)
74 }
75}
76
77// parallelExample 并行执行示例
78func parallelExample(ctx context.Context) {

Callers 1

mainFunction · 0.85

Calls 6

ExecuteMethod · 0.95
NewSequentialAgentFunction · 0.92
NewMockAgentFunction · 0.85
printEventFunction · 0.85
RecvMethod · 0.80
PrintfMethod · 0.80

Tested by

no test coverage detected