Skip to content

Commit 4d4acdf

Browse files
committed
pkg/aflow: unexport Pipeline type
I've added NewPipeline constructor for a bit nicer syntax, but failed to use it in actual workflows. Unexport Pipeline and rename NewPipeline to Pipeline. This slightly improves workflows definition syntax.
1 parent c852322 commit 4d4acdf

File tree

6 files changed

+80
-86
lines changed

6 files changed

+80
-86
lines changed

pkg/aflow/action.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@ type Action interface {
88
execute(*Context) error
99
}
1010

11-
type Pipeline struct {
11+
type pipeline struct {
1212
// These actions are invoked sequentially,
1313
// but dataflow across actions is specified by their use
1414
// of variables in args/instructions/prompts.
15-
Actions []Action
15+
actions []Action
1616
}
1717

18-
func NewPipeline(actions ...Action) *Pipeline {
19-
return &Pipeline{
20-
Actions: actions,
18+
func Pipeline(actions ...Action) *pipeline {
19+
return &pipeline{
20+
actions: actions,
2121
}
2222
}
2323

24-
func (p *Pipeline) execute(ctx *Context) error {
25-
for _, sub := range p.Actions {
24+
func (p *pipeline) execute(ctx *Context) error {
25+
for _, sub := range p.actions {
2626
if err := sub.execute(ctx); err != nil {
2727
return err
2828
}
2929
}
3030
return nil
3131
}
3232

33-
func (p *Pipeline) verify(ctx *verifyContext) {
34-
for _, a := range p.Actions {
33+
func (p *pipeline) verify(ctx *verifyContext) {
34+
for _, a := range p.actions {
3535
a.verify(ctx)
3636
}
3737
}

pkg/aflow/flow/assessment/kcsan.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,24 @@ func init() {
2323
ai.WorkflowAssessmentKCSAN,
2424
"assess if a KCSAN report is about a benign race that only needs annotations or not",
2525
&aflow.Flow{
26-
Root: &aflow.Pipeline{
27-
Actions: []aflow.Action{
28-
kernel.Checkout,
29-
kernel.Build,
30-
codesearcher.PrepareIndex,
31-
&aflow.LLMAgent{
32-
Name: "expert",
33-
Model: aflow.GoodBalancedModel,
34-
Reply: "Explanation",
35-
Outputs: aflow.LLMOutputs[struct {
36-
Confident bool `jsonschema:"If you are confident in the verdict of the analysis or not."`
37-
Benign bool `jsonschema:"If the data race is benign or not."`
38-
}](),
39-
Temperature: 1,
40-
Instruction: kcsanInstruction,
41-
Prompt: kcsanPrompt,
42-
Tools: codesearcher.Tools,
43-
},
26+
Root: aflow.Pipeline(
27+
kernel.Checkout,
28+
kernel.Build,
29+
codesearcher.PrepareIndex,
30+
&aflow.LLMAgent{
31+
Name: "expert",
32+
Model: aflow.GoodBalancedModel,
33+
Reply: "Explanation",
34+
Outputs: aflow.LLMOutputs[struct {
35+
Confident bool `jsonschema:"If you are confident in the verdict of the analysis or not."`
36+
Benign bool `jsonschema:"If the data race is benign or not."`
37+
}](),
38+
Temperature: 1,
39+
Instruction: kcsanInstruction,
40+
Prompt: kcsanPrompt,
41+
Tools: codesearcher.Tools,
4442
},
45-
},
43+
),
4644
},
4745
)
4846
}

pkg/aflow/flow/assessment/moderation.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,25 @@ func init() {
3333
ai.WorkflowModeration,
3434
"assess if a bug report is consistent and actionable or not",
3535
&aflow.Flow{
36-
Root: &aflow.Pipeline{
37-
Actions: []aflow.Action{
38-
aflow.NewFuncAction("extract-crash-type", extractCrashType),
39-
kernel.Checkout,
40-
kernel.Build,
41-
codesearcher.PrepareIndex,
42-
&aflow.LLMAgent{
43-
Name: "expert",
44-
Model: aflow.GoodBalancedModel,
45-
Reply: "Explanation",
46-
Outputs: aflow.LLMOutputs[struct {
47-
Confident bool `jsonschema:"If you are confident in the verdict of the analysis or not."`
48-
Actionable bool `jsonschema:"If the report is actionable or not."`
49-
}](),
50-
Temperature: 1,
51-
Instruction: moderationInstruction,
52-
Prompt: moderationPrompt,
53-
Tools: codesearcher.Tools,
54-
},
36+
Root: aflow.Pipeline(
37+
aflow.NewFuncAction("extract-crash-type", extractCrashType),
38+
kernel.Checkout,
39+
kernel.Build,
40+
codesearcher.PrepareIndex,
41+
&aflow.LLMAgent{
42+
Name: "expert",
43+
Model: aflow.GoodBalancedModel,
44+
Reply: "Explanation",
45+
Outputs: aflow.LLMOutputs[struct {
46+
Confident bool `jsonschema:"If you are confident in the verdict of the analysis or not."`
47+
Actionable bool `jsonschema:"If the report is actionable or not."`
48+
}](),
49+
Temperature: 1,
50+
Instruction: moderationInstruction,
51+
Prompt: moderationPrompt,
52+
Tools: codesearcher.Tools,
5553
},
56-
},
54+
),
5755
},
5856
)
5957
}

pkg/aflow/flow/patching/patching.go

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,40 @@ func init() {
4545
ai.WorkflowPatching,
4646
"generate a kernel patch fixing a provided bug reproducer",
4747
&aflow.Flow{
48-
Root: &aflow.Pipeline{
49-
Actions: []aflow.Action{
50-
baseCommitPicker,
51-
kernel.Checkout,
52-
kernel.Build,
53-
// Ensure we can reproduce the crash (and the build boots).
54-
crash.Reproduce,
55-
codesearcher.PrepareIndex,
56-
&aflow.LLMAgent{
57-
Name: "debugger",
58-
Model: aflow.BestExpensiveModel,
59-
Reply: "BugExplanation",
60-
Temperature: 1,
61-
Instruction: debuggingInstruction,
62-
Prompt: debuggingPrompt,
63-
Tools: tools,
64-
},
65-
&aflow.LLMAgent{
66-
Name: "diff-generator",
67-
Model: aflow.BestExpensiveModel,
68-
Reply: "PatchDiff",
69-
Temperature: 1,
70-
Instruction: diffInstruction,
71-
Prompt: diffPrompt,
72-
Tools: tools,
73-
},
74-
&aflow.LLMAgent{
75-
Name: "description-generator",
76-
Model: aflow.BestExpensiveModel,
77-
Reply: "PatchDescription",
78-
Temperature: 1,
79-
Instruction: descriptionInstruction,
80-
Prompt: descriptionPrompt,
81-
},
48+
Root: aflow.Pipeline(
49+
baseCommitPicker,
50+
kernel.Checkout,
51+
kernel.Build,
52+
// Ensure we can reproduce the crash (and the build boots).
53+
crash.Reproduce,
54+
codesearcher.PrepareIndex,
55+
&aflow.LLMAgent{
56+
Name: "debugger",
57+
Model: aflow.BestExpensiveModel,
58+
Reply: "BugExplanation",
59+
Temperature: 1,
60+
Instruction: debuggingInstruction,
61+
Prompt: debuggingPrompt,
62+
Tools: tools,
8263
},
83-
},
64+
&aflow.LLMAgent{
65+
Name: "diff-generator",
66+
Model: aflow.BestExpensiveModel,
67+
Reply: "PatchDiff",
68+
Temperature: 1,
69+
Instruction: diffInstruction,
70+
Prompt: diffPrompt,
71+
Tools: tools,
72+
},
73+
&aflow.LLMAgent{
74+
Name: "description-generator",
75+
Model: aflow.BestExpensiveModel,
76+
Reply: "PatchDescription",
77+
Temperature: 1,
78+
Instruction: descriptionInstruction,
79+
Prompt: descriptionPrompt,
80+
},
81+
),
8482
},
8583
)
8684
}

pkg/aflow/flow_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestWorkflow(t *testing.T) {
9090
"SwarmInt": []int{1, 2},
9191
"OutAggregator": "aggregated",
9292
},
93-
NewPipeline(
93+
Pipeline(
9494
NewFuncAction("func-action",
9595
func(ctx *Context, args firstFuncInputs) (firstFuncOutputs, error) {
9696
assert.Equal(t, args.InFoo, 10)
@@ -317,7 +317,7 @@ func TestToolMisbehavior(t *testing.T) {
317317
"Reply": "Finally done",
318318
"AdditionalOutput": 2,
319319
},
320-
NewPipeline(
320+
Pipeline(
321321
&LLMAgent{
322322
Name: "smarty",
323323
Model: "model",

pkg/aflow/llm_tool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestLLMTool(t *testing.T) {
2121
Something string `jsonschema:"something"`
2222
}
2323
testFlow[inputs, outputs](t, map[string]any{"Input": 42}, map[string]any{"Reply": "YES"},
24-
NewPipeline(
24+
Pipeline(
2525
&LLMAgent{
2626
Name: "smarty",
2727
Model: "model",

0 commit comments

Comments
 (0)