Sequential Agent is an important component in the Blades framework for implementing sequential execution logic, which breaks down complex tasks into simpler, more manageable subtasks.

The core function of the Sequential Agent is NewSequentialAgent, used to build a sequential workflow. When initializing a sequential workflow, it requires the configuration SequentialConfig as input:
type SequentialConfig struct { Name string Description string SubAgents []blades.Agent}The way to build a Sequential Agent is as follows:
sequentialAgent := flow.NewSequentialAgent( flow.SequentialConfig{ Name: "WritingReviewFlow", SubAgents: []blades.Agent{ writerAgent, reviewerAgent, },})The blades.NewRunner method can directly accept sequentialAgent as an input parameter:
input := blades.UserMessage("Please write a short paragraph about climate change.")runner := blades.NewRunner(sequentialAgent)stream := runner.RunStream(context.Background(), input)for message, err := range stream { if err != nil { log.Fatal(err) } log.Println(message.Author, message.Text())}package main
import ( "context" "log" "os"
"github.com/go-kratos/blades" "github.com/go-kratos/blades/contrib/openai" "github.com/go-kratos/blades/flow")
func main() { model := openai.NewModel(os.Getenv("OPENAI_MODEL"), openai.Config{ APIKey: os.Getenv("OPENAI_API_KEY"), }) writerAgent, err := blades.NewAgent( "WriterAgent", blades.WithModel(model), blades.WithInstruction("Draft a short paragraph on climate change."), blades.WithOutputKey("draft"), ) if err != nil { log.Fatal(err) } reviewerAgent, err := blades.NewAgent( "ReviewerAgent", blades.WithModel(model), blades.WithInstruction(`Review the draft and suggest improvements. Draft: {{.draft}}`), ) if err != nil { log.Fatal(err) } sequentialAgent := flow.NewSequentialAgent( flow.SequentialConfig{ Name: "WritingReviewFlow", SubAgents: []blades.Agent{ writerAgent, reviewerAgent, }, }) if err != nil { log.Fatal(err) } input := blades.UserMessage("Please write a short paragraph about climate change.") runner := blades.NewRunner(sequentialAgent) stream := runner.RunStream(context.Background(), input) for message, err := range stream { if err != nil { log.Fatal(err) } log.Println(message.Author, message.Text()) }}