Sequential Agent

Purpose

The Sequential Agent addresses the need within the broader Agent Workflow Management topic to execute multiple sub-agents in a strict, predefined order exactly once. This pattern is essential for pipeline-style workflows where each agent performs a step that depends on the previous step's output. Unlike the other workflow agents—such as the Parallel Agent which runs sub-agents concurrently, or the Loop Agent which repeats execution—the Sequential Agent guarantees a linear, predictable progression through its sub-agent sequence.

This deterministic ordering simplifies error handling, debugging, and reasoning about the workflow, making it ideal for scenarios where each step must complete successfully before the next begins.

Functionality

The Sequential Agent is implemented as a specialized wrapper around the more generic Loop Agent configured to run exactly one iteration (MaxIterations=1). This reuse leverages the Loop Agent’s iteration and sub-agent orchestration logic while constraining execution to a single pass through the sub-agent list.

Key Behaviors:

Workflow Overview:

  1. The Sequential Agent receives an invocation request.

  2. It triggers execution of the first sub-agent.

  3. Once the first sub-agent completes, the second sub-agent is invoked.

  4. This process continues until all sub-agents have run once.

  5. The collected events from all sub-agents are aggregated and returned in sequence.

This behavior ensures a linear pipeline effect where the output or side effects of one sub-agent can influence the next.

Code Interaction Example

The core creation function New demonstrates how the Sequential Agent is constructed by wrapping a Loop Agent configured for one iteration:

func New(cfg Config) (agent.Agent, error) {
	sequentialAgent, err := loopagent.New(loopagent.Config{
		AgentConfig:   cfg.AgentConfig,
		MaxIterations: 1, // Ensures a single pass over sub-agents
	})
	// type assertion and internal state tagging omitted for brevity
	return sequentialAgent, nil
}

This design choice simplifies the implementation by reusing the Loop Agent's machinery while restricting execution to a one-time sequence.

Error Handling and Validation

Tests enforce strict constraints on sub-agent composition, including:

These validations prevent runtime ambiguity and ensure the pipeline integrity.

Integration

The Sequential Agent integrates tightly with the other workflow agents under the Agent Workflow Management umbrella. It complements the Parallel Agent and Loop Agent by providing the simplest linear execution pattern:

The Sequential Agent also interoperates with:

Diagram

flowchart TD
Start[Start Sequential Agent]
SubAgent1[Run Sub-Agent 1]
SubAgent2[Run Sub-Agent 2]
SubAgent3[Run Sub-Agent N]
End[End Sequential Agent]
Start --> SubAgent1 --> SubAgent2 --> SubAgent3 --> End

This flowchart visualizes the core process: each sub-agent executes strictly after the previous completes, forming a linear pipeline. The number of sub-agents (N) is configurable as part of the agent setup, but the sequence is always fixed and runs once.


This linear, single-pass execution approach makes the Sequential Agent an essential building block for orchestrating complex AI workflows where ordered processing is required.