From e16b988300c8bba1bc7ebddbec56e1ad65345362 Mon Sep 17 00:00:00 2001 From: Yulong Zhang Date: Wed, 28 Jan 2026 20:53:52 +0000 Subject: pkg/aflow: adding sliding window summary feature This adds a flow feature (and creates a new flow using it) called "sliding window summary". It works by asking the AI to always summarize the latest knowledge, and then we toss the old messages if they fall outside the context sliding window. --- pkg/aflow/flow/patching/patching.go | 107 ++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 47 deletions(-) (limited to 'pkg/aflow/flow/patching/patching.go') diff --git a/pkg/aflow/flow/patching/patching.go b/pkg/aflow/flow/patching/patching.go index 9ec36ec3f..7c82e77d4 100644 --- a/pkg/aflow/flow/patching/patching.go +++ b/pkg/aflow/flow/patching/patching.go @@ -50,58 +50,71 @@ type Recipient struct { To bool // whether the recipient should be on the To or Cc line } -func init() { +func createPatchingFlow(name string, summaryWindow int) *aflow.Flow { commonTools := slices.Clip(append([]aflow.Tool{codeexpert.Tool}, codesearcher.Tools...)) + return &aflow.Flow{ + Name: name, + Root: aflow.Pipeline( + baseCommitPicker, + kernel.Checkout, + kernel.Build, + // Ensure we can reproduce the crash (and the build boots). + crash.Reproduce, + codesearcher.PrepareIndex, + &aflow.LLMAgent{ + Name: "debugger", + Model: aflow.BestExpensiveModel, + Reply: "BugExplanation", + Temperature: 1, + Instruction: debuggingInstruction, + Prompt: debuggingPrompt, + Tools: commonTools, + SummaryWindow: summaryWindow, + }, + kernel.CheckoutScratch, + &aflow.DoWhile{ + Do: aflow.Pipeline( + &aflow.LLMAgent{ + Name: "patch-generator", + Model: aflow.BestExpensiveModel, + Reply: "PatchExplanation", + Temperature: 1, + Instruction: patchInstruction, + Prompt: patchPrompt, + Tools: append(commonTools, codeeditor.Tool), + SummaryWindow: summaryWindow, + }, + crash.TestPatch, // -> PatchDiff or TestError + ), + While: "TestError", + MaxIterations: 10, + }, + getMaintainers, + &aflow.LLMAgent{ + Name: "description-generator", + Model: aflow.BestExpensiveModel, + Reply: "PatchDescription", + Temperature: 1, + Instruction: descriptionInstruction, + Prompt: descriptionPrompt, + Tools: commonTools, + SummaryWindow: summaryWindow, + }, + ), + } +} +func init() { aflow.Register[Inputs, Outputs]( ai.WorkflowPatching, "generate a kernel patch fixing a provided bug reproducer", - &aflow.Flow{ - Root: aflow.Pipeline( - baseCommitPicker, - kernel.Checkout, - kernel.Build, - // Ensure we can reproduce the crash (and the build boots). - crash.Reproduce, - codesearcher.PrepareIndex, - &aflow.LLMAgent{ - Name: "debugger", - Model: aflow.BestExpensiveModel, - Reply: "BugExplanation", - Temperature: 1, - Instruction: debuggingInstruction, - Prompt: debuggingPrompt, - Tools: commonTools, - }, - kernel.CheckoutScratch, - &aflow.DoWhile{ - Do: aflow.Pipeline( - &aflow.LLMAgent{ - Name: "patch-generator", - Model: aflow.BestExpensiveModel, - Reply: "PatchExplanation", - Temperature: 1, - Instruction: patchInstruction, - Prompt: patchPrompt, - Tools: append(commonTools, codeeditor.Tool), - }, - crash.TestPatch, // -> PatchDiff or TestError - ), - While: "TestError", - MaxIterations: 10, - }, - getMaintainers, - &aflow.LLMAgent{ - Name: "description-generator", - Model: aflow.BestExpensiveModel, - Reply: "PatchDescription", - Temperature: 1, - Instruction: descriptionInstruction, - Prompt: descriptionPrompt, - Tools: commonTools, - }, - ), - }, + createPatchingFlow("", 0), + ) + + aflow.Register[Inputs, Outputs]( + ai.WorkflowPatching, + "generate a kernel patch fixing a provided bug reproducer, with the summary feature", + createPatchingFlow("summary", 10), ) } -- cgit mrf-deployment