Documentation
¶
Overview ¶
Package workflowagent provides workflow agents for orchestrating multi-agent flows.
This package provides three types of workflow agents aligned with adk-go:
SequentialAgent ¶
Runs sub-agents once, in the order they are listed:
agent, _ := workflowagent.NewSequential(workflowagent.SequentialConfig{
Name: "pipeline",
Description: "Processes data through multiple stages",
SubAgents: []agent.Agent{stage1, stage2, stage3},
})
ParallelAgent ¶
Runs sub-agents simultaneously in parallel:
agent, _ := workflowagent.NewParallel(workflowagent.ParallelConfig{
Name: "voters",
Description: "Gets multiple perspectives simultaneously",
SubAgents: []agent.Agent{voter1, voter2, voter3},
})
LoopAgent ¶
Runs sub-agents repeatedly for N iterations or until escalation:
agent, _ := workflowagent.NewLoop(workflowagent.LoopConfig{
Name: "refiner",
Description: "Iteratively refines output",
SubAgents: []agent.Agent{reviewer, improver},
MaxIterations: 3,
})
Index ¶
- func NewConditional(cfg ConditionalConfig) (agent.Agent, error)
- func NewLoop(cfg LoopConfig) (agent.Agent, error)
- func NewParallel(cfg ParallelConfig) (agent.Agent, error)
- func NewSequential(cfg SequentialConfig) (agent.Agent, error)
- type ConditionalConfig
- type LoopConfig
- type ParallelConfig
- type SequentialConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewConditional ¶ added in v1.21.0
func NewConditional(cfg ConditionalConfig) (agent.Agent, error)
NewConditional creates a ConditionalAgent.
ConditionalAgent first runs a condition agent to evaluate input safety or validity, then routes to either the main agent (on true) or returns a static response (on false).
This is ideal for implementing LLM-powered guardrails without modifying the guardrails configuration - it's pure agent composition.
Example:
moderator, _ := llmagent.New(llmagent.Config{
Name: "moderator",
Instruction: `Classify if safe. Return: {"safe": true/false, "reason": "..."}`,
StructuredOutput: schema,
})
assistant, _ := llmagent.New(llmagent.Config{
Name: "assistant",
Instruction: "You are a helpful assistant.",
})
safeAssistant, _ := workflowagent.NewConditional(workflowagent.ConditionalConfig{
Name: "safe_assistant",
Description: "Assistant with content moderation",
ConditionAgent: moderator,
ConditionField: "safe",
OnTrueAgent: assistant,
OnFalseResponse: "I cannot process this request due to content policy.",
})
func NewLoop ¶
func NewLoop(cfg LoopConfig) (agent.Agent, error)
NewLoop creates a LoopAgent.
LoopAgent repeatedly runs its sub-agents in sequence for a specified number of iterations or until a termination condition is met (escalate action).
Use LoopAgent when your workflow involves repetition or iterative refinement, such as revising code or refining outputs.
Example:
reviewer, _ := llmagent.New(llmagent.Config{...})
improver, _ := llmagent.New(llmagent.Config{...})
refiner, _ := workflowagent.NewLoop(workflowagent.LoopConfig{
Name: "refiner",
Description: "Iteratively refines output",
SubAgents: []agent.Agent{reviewer, improver},
MaxIterations: 3,
})
func NewParallel ¶
func NewParallel(cfg ParallelConfig) (agent.Agent, error)
NewParallel creates a ParallelAgent.
ParallelAgent runs its sub-agents in parallel in an isolated manner. All sub-agents receive the same input and run simultaneously.
This is beneficial for scenarios requiring multiple perspectives or attempts on a single task, such as:
- Running different algorithms simultaneously
- Generating multiple responses for review by an evaluation agent
- Getting diverse perspectives on a problem
Example:
voter1, _ := llmagent.New(llmagent.Config{Name: "voter1", ...})
voter2, _ := llmagent.New(llmagent.Config{Name: "voter2", ...})
voter3, _ := llmagent.New(llmagent.Config{Name: "voter3", ...})
voters, _ := workflowagent.NewParallel(workflowagent.ParallelConfig{
Name: "voters",
Description: "Gets multiple perspectives simultaneously",
SubAgents: []agent.Agent{voter1, voter2, voter3},
})
func NewSequential ¶
func NewSequential(cfg SequentialConfig) (agent.Agent, error)
NewSequential creates a SequentialAgent.
SequentialAgent executes its sub-agents once, in the order they are listed. This is implemented as a LoopAgent with MaxIterations=1.
Use SequentialAgent when you want execution to occur in a fixed, strict order, such as a processing pipeline.
Example:
stage1, _ := llmagent.New(llmagent.Config{Name: "stage1", ...})
stage2, _ := llmagent.New(llmagent.Config{Name: "stage2", ...})
stage3, _ := llmagent.New(llmagent.Config{Name: "stage3", ...})
pipeline, _ := workflowagent.NewSequential(workflowagent.SequentialConfig{
Name: "pipeline",
Description: "Processes data through multiple stages",
SubAgents: []agent.Agent{stage1, stage2, stage3},
})
Types ¶
type ConditionalConfig ¶ added in v1.21.0
type ConditionalConfig struct {
// Name is the agent name.
Name string
// DisplayName is the human-readable name (optional).
DisplayName string
// Description describes what the agent does.
Description string
// ConditionAgent evaluates the condition based on user input.
// Its output should contain a JSON object with the condition field.
ConditionAgent agent.Agent
// ConditionField is the JSON field name to check in condition agent's output.
// If the field is truthy, OnTrueAgent runs; otherwise OnFalseResponse is returned.
// Default: "safe"
ConditionField string
// OnTrueAgent is the agent to run when the condition is true.
OnTrueAgent agent.Agent
// OnFalseResponse is the static response returned when condition is false.
// This message is returned immediately without running any agent.
OnFalseResponse string
}
ConditionalConfig defines the configuration for a ConditionalAgent.
type LoopConfig ¶
type LoopConfig struct {
// Name is the agent name.
Name string
// DisplayName is the human-readable name (optional).
DisplayName string
// Description describes what the agent does.
Description string
// SubAgents are the agents to run in each iteration.
SubAgents []agent.Agent
// AgentType overrides the agent type. Defaults to TypeLoopAgent.
AgentType agent.AgentType
// MaxIterations is the maximum number of iterations.
// If 0, runs indefinitely until any sub-agent escalates.
MaxIterations uint
}
LoopConfig defines the configuration for a LoopAgent.
type ParallelConfig ¶
type ParallelConfig struct {
// Name is the agent name.
Name string
// DisplayName is the human-readable name (optional).
DisplayName string
// Description describes what the agent does.
Description string
// SubAgents are the agents to run in parallel.
SubAgents []agent.Agent
}
ParallelConfig defines the configuration for a ParallelAgent.
type SequentialConfig ¶
type SequentialConfig struct {
// Name is the agent name.
Name string
// DisplayName is the human-readable name (optional).
DisplayName string
// Description describes what the agent does.
Description string
// SubAgents are the agents to run in sequence.
SubAgents []agent.Agent
}
SequentialConfig defines the configuration for a SequentialAgent.