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

Function main

examples/workflow_router/main.go:14–192  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12)
13
14func main() {
15 fmt.Println("=== Aster Router 流式执行示例 ===")
16
17 ctx := context.Background()
18
19 // 创建一些步骤
20 step1 := workflow.NewFunctionStep("analyze", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
21 fmt.Println(" 🔍 Analyzing input...")
22 return &workflow.StepOutput{
23 Content: map[string]any{"analysis": "complex", "priority": "high"},
24 Metadata: make(map[string]any),
25 }, nil
26 })
27
28 step2 := workflow.NewFunctionStep("process_complex", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
29 fmt.Println(" ⚙️ Processing complex case...")
30 return &workflow.StepOutput{
31 Content: "Processed with advanced algorithm",
32 Metadata: make(map[string]any),
33 }, nil
34 })
35
36 step3 := workflow.NewFunctionStep("process_simple", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
37 fmt.Println(" ⚡ Processing simple case...")
38 return &workflow.StepOutput{
39 Content: "Processed with basic algorithm",
40 Metadata: make(map[string]any),
41 }, nil
42 })
43
44 step4 := workflow.NewFunctionStep("finalize", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
45 fmt.Println(" ✅ Finalizing...")
46 return &workflow.StepOutput{
47 Content: fmt.Sprintf("Final result: %v", input.PreviousStepContent),
48 Metadata: make(map[string]any),
49 }, nil
50 })
51
52 // 创建链式路由器 - 根据分析结果选择不同的处理链
53 router := workflow.ChainRouter("smart_processor",
54 func(input *workflow.StepInput) []string {
55 // 根据前一步的分析结果决定执行路径
56 if input.PreviousStepContent != nil {
57 if analysis, ok := input.PreviousStepContent.(map[string]any); ok {
58 if analysis["analysis"] == "complex" {
59 fmt.Println("\n📍 Router 选择: complex 路径 (2步)")
60 return []string{"process_complex", "finalize"}
61 }
62 }
63 }
64 fmt.Println("\n📍 Router 选择: simple 路径 (2步)")
65 return []string{"process_simple", "finalize"}
66 },
67 map[string]workflow.Step{
68 "process_complex": step2,
69 "process_simple": step3,
70 "finalize": step4,
71 },

Callers

nothing calls this directly

Calls 10

NewFunctionStepFunction · 0.92
ChainRouterFunction · 0.92
NewFunction · 0.92
SimpleRouterFunction · 0.92
WithStreamMethod · 0.80
PrintfMethod · 0.80
RecvMethod · 0.80
ValidateMethod · 0.65
ExecuteMethod · 0.65
AddStepMethod · 0.45

Tested by

no test coverage detected