Overview
TheSequentialWorkflow class orchestrates the execution of a sequence of agents in a defined workflow. This class enables the construction and execution of a workflow where multiple agents (or callables) are executed in a specified order, passing tasks and optional data through the chain.
Key Features
- Sequential Execution: Agents execute one after another in a defined order
- Synchronous and Asynchronous Support: Both blocking and non-blocking execution modes
- Batched Processing: Execute multiple tasks through the same workflow
- Concurrent Task Processing: Run multiple tasks concurrently using thread pools
- Team Awareness: Agents can be aware of their position in the team structure
- Auto-save Support: Automatically save conversation history to workspace
- Flexible Output Types: Support for various output formats (dict, list, string)
Installation
Class Definition
Parameters
Unique identifier for the workflow instance
Human-readable name for the workflow
Description of the workflow’s purpose
List of agents or callables to execute in sequence. Cannot be None or empty.
Maximum number of times to execute the workflow. Must be greater than 0.
Format of the output from the workflow. Options include “dict”, “list”, “str”, etc.
Optional callable for managing shared memory between agents
If True, appends a collaborative prompt to each agent’s system prompt
Whether agents are aware of the team structure and their position
Whether to enable autosaving of conversation history to workspace
Whether to enable verbose logging
Methods
run(task, img=None, imgs=None, *args, **kwargs)
Executes a specified task through the agents in the dynamically constructed flow.
The task for the agents to execute
An optional image input for the agents
Optional list of images for the agents
The final result after processing through all agents
run_batched(tasks)
Executes a batch of tasks through the agents sequentially.
A list of tasks for the agents to execute. Must be a non-empty list of strings.
A list of final results after processing through all agents
run_async(task)
Executes the specified task through the agents asynchronously.
The task for the agents to execute. Must be a non-empty string.
The final result after processing through all agents
run_concurrent(tasks)
Executes a batch of tasks through the agents concurrently using ThreadPoolExecutor.
A list of tasks for the agents to execute. Must be a non-empty list of strings.
A list of final results after processing through all agents
sequential_flow()
Constructs a string representation of the agent execution order.
A string showing the order of agent execution (e.g., “AgentA -> AgentB -> AgentC”)
reliability_check()
Validates the workflow configuration and prepares agents for execution.
Raises:
ValueError: If the agents list is None or empty, or if max_loops is set to 0
Attributes
| Attribute | Type | Description |
|---|---|---|
id | str | Unique identifier for the workflow instance |
name | str | Human-readable name for the workflow |
description | str | Description of the workflow’s purpose |
agents | List[Union[Agent, Callable]] | List of agents or callables to execute in sequence |
max_loops | int | Maximum number of times to execute the workflow |
output_type | OutputType | Format of the output from the workflow |
flow | str | String representation of the agent execution order |
agent_rearrange | AgentRearrange | Internal helper for managing agent execution |
Usage Examples
Basic Sequential Workflow
Batched Task Processing
Concurrent Task Execution
Async Execution
With Team Awareness
Custom Output Types
With Autosave
Error Handling
Best Practices
- Agent Design: Ensure each agent has a clear, specific role in the sequence
- Error Handling: Use try-except blocks around workflow execution
- Verbose Mode: Enable verbose logging during development for debugging
- Autosave: Enable autosave for important workflows to preserve conversation history
- Task Clarity: Provide clear, specific tasks to get the best results
- Resource Management: Use
run_concurrentfor I/O-bound tasks to improve performance - Team Awareness: Enable team awareness for complex workflows where context matters
Common Use Cases
- Content Creation Pipelines: Research -> Write -> Edit workflows
- Data Processing: Extract -> Transform -> Load (ETL) pipelines
- Analysis Workflows: Collect -> Analyze -> Report sequences
- Quality Assurance: Create -> Review -> Approve chains
- Multi-Stage Reasoning: Break complex problems into sequential steps
Related Classes
- AgentRearrange: For more complex, non-linear agent orchestration
- ConcurrentWorkflow: For parallel agent execution
- GraphWorkflow: For DAG-based agent workflows
- Agent: The base agent class used in workflows