The Sequential Agent is the core component in the Blades framework for implementing sequential execution logic. It allows multiple tasks to be executed in a predetermined order, where the output of the previous task serves as the input for the next. This pattern is particularly suitable for linear business processes that require step-by-step handling.
type Sequential struct { runners []blades.Runnable}The Sequential struct contains only one parameter: runners.
type Runnable interface { Run(context.Context, *Prompt, ...ModelOption) (*Message, error) RunStream(context.Context, *Prompt, ...ModelOption) (Streamable[*Message], error)}tasks := []blades.Runnable{ // step 1 flow.NewSequential(...), // step 2 flow.NewSequential(...), // step 3 flow.NewSequential(...),}sequential := flow.NewSequential(tasks...)result, err := sequential.Run(context.Background(), prompt)Before running this code, please ensure you have correctly configured your API key.
// define taskstasks := []blades.Runnable{ // step 1: data validation flow.NewSequential( // validation task implementation ), // step 2: data processing flow.NewSequential( // processing task implementation ), // step 3: result generation flow.NewSequential( // generation task implementation ),}
// create sequential agentsequential := flow.NewSequential(tasks...)
// sequential executionresult, err := sequential.Run(ctx, prompt)if err != nil { log.Printf("sequential execution error: %v", err) return}
log.Printf("sequential execution completed, final result: %s", result.Text())