sequentialExample 顺序工作流示例
(ctx context.Context)
| 42 | |
| 43 | // sequentialExample 顺序工作流示例 |
| 44 | func 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 并行执行示例 |
| 78 | func parallelExample(ctx context.Context) { |
no test coverage detected