Agent Workflow Management

Overview

The Agent Workflow Management module implements a set of specialized agents designed to orchestrate complex AI workflows by composing and managing multiple sub-agents with different execution patterns. This module provides workflow agents that support:

These workflow agents enable the construction of sophisticated AI workflows by coordinating multiple sub-agents, each potentially with distinct behaviors or goals, and managing their execution lifecycle within a unified framework. This orchestration capability is essential for building multi-step, multi-agent AI processes, such as pipelines, ensemble models, or iterative refinement loops.

The module is implemented primarily under the agent/workflowagents/ directory with sub-packages for sequentialagent, parallelagent, and loopagent.


Core Concepts and Purpose

Why Workflow Agents?

While individual AI agents can handle simple tasks, complex applications often require:

This module addresses these needs by providing workflow agents that control sub-agent invocation patterns:

These patterns enhance modularity and reuse, allowing developers to compose complex behaviors from simpler agents.

Interaction with Other System Components

Workflow agents are fully integrated with the broader agent framework:


Detailed Functionality and Architecture

SequentialAgent

The SequentialAgent runs its list of sub-agents strictly one after another, waiting for each to complete before starting the next. This ensures deterministic ordering of execution, useful when later steps depend on outputs from earlier steps.

// SequentialAgent is implemented by wrapping LoopAgent with MaxIterations=1.
func New(cfg Config) (agent.Agent, error) {
	sequentialAgent, err := loopagent.New(loopagent.Config{
		AgentConfig:   cfg.AgentConfig,
		MaxIterations: 1,
	})
	// Further internal state initialization omitted for brevity...
	return sequentialAgent, nil
}

ParallelAgent

The ParallelAgent runs all its sub-agents concurrently in isolated invocation contexts and merges their outputs.

func run(ctx agent.InvocationContext) iter.Seq2[*session.Event, error] {
	// For each sub-agent, run concurrently in separate goroutine
	// Collect results in resultsChan and yield to caller in order received.
}

LoopAgent

The LoopAgent repeatedly executes its sub-agents in sequence for a configured number of iterations (MaxIterations), or indefinitely if zero.

func (a *loopAgent) Run(ctx agent.InvocationContext) iter.Seq2[*session.Event, error] {
	count := a.maxIterations
	return func(yield func(*session.Event, error) bool) {
		for {
			// Run all sub-agents sequentially
			// Exit if escalate action detected or iteration count exhausted
		}
	}
}

Design Patterns and Important Concepts

Composability and Agent Trees

Workflow agents rely on the core agent composition model where agents can have sub-agents forming a tree. This design enables:

The tests in sequentialagent/agent_test.go emphasize strict validation of agent trees to prevent duplicate sub-agent instances or conflicting names.

Invocation Context Branching

ParallelAgent maintains distinct "branches" in the invocation context for each sub-agent execution. This supports tracing and isolation of execution state, facilitating debugging and telemetry.

Yield-Based Event Streaming

All workflow agents expose their execution as an iterator (iter.Seq2) streaming session.Events asynchronously. This design supports:


Interactions Between Workflow Agents

The workflow agents can be combined to create complex execution patterns. For example:


Visual Representation of Agent Workflow Management

flowchart TD
UserInput[User Input]
SequentialAgent[Sequential Agent]
ParallelAgent[Parallel Agent]
LoopAgent[Loop Agent]
SubAgent1[Sub-Agent 1]
SubAgent2[Sub-Agent 2]
SubAgent3[Sub-Agent 3]
EventStream[Session Event Stream]
UserInput --> SequentialAgent
UserInput --> ParallelAgent
UserInput --> LoopAgent
SequentialAgent --> SubAgent1
SequentialAgent --> SubAgent2
SequentialAgent --> SubAgent3
ParallelAgent --> SubAgent1
ParallelAgent --> SubAgent2
ParallelAgent --> SubAgent3
LoopAgent --> SubAgent1
LoopAgent --> SubAgent2
LoopAgent --> SubAgent3
SubAgent1 --> EventStream
SubAgent2 --> EventStream
SubAgent3 --> EventStream

This flowchart illustrates how each workflow agent receives user input and orchestrates the execution of its sub-agents, whose events are streamed back to the session for consumption.


References to Related Topics


This detailed explanation of Agent Workflow Management provides insight into the purpose, design, and internals of the workflow agents enabling complex AI orchestrations within the agent framework.