Documentation Index
Fetch the complete documentation index at: https://docs.swarms.world/llms.txt
Use this file to discover all available pages before exploring further.
A SequentialWorkflow executes tasks in a strict order, forming a pipeline where each agent builds upon the work of the previous one. This architecture is ideal for processes that have clear, ordered steps and ensures that tasks with dependencies are handled correctly.
How Sequential Workflow Works
In a sequential workflow:
- Linear Execution: Agents execute tasks one after another in a defined order
- Output Chaining: The output of one agent becomes the input for the next agent
- Dependency Management: Ensures tasks with dependencies are handled correctly
- Sequential Processing: Each agent must complete before the next one starts
Basic Example: Researcher to Writer Pipeline
This example demonstrates a two-agent workflow for researching and writing a blog post:
from swarms import Agent, SequentialWorkflow
# Agent 1: The Researcher
researcher = Agent(
agent_name="Researcher",
system_prompt="Your job is to research the provided topic and provide a detailed summary.",
model_name="gpt-5.4",
)
# Agent 2: The Writer
writer = Agent(
agent_name="Writer",
system_prompt="Your job is to take the research summary and write a beautiful, engaging blog post about it.",
model_name="gpt-5.4",
)
# Create a sequential workflow where the researcher's output feeds into the writer's input
workflow = SequentialWorkflow(agents=[researcher, writer])
# Run the workflow on a task
final_post = workflow.run("The history and future of artificial intelligence")
print(final_post)
How This Example Works
- Task Assignment: The initial task “The history and future of artificial intelligence” is sent to the first agent (Researcher)
- Research Phase: The Researcher agent processes the task and produces a detailed summary
- Handoff: The Researcher’s output automatically becomes the input for the Writer agent
- Writing Phase: The Writer agent takes the research summary and creates an engaging blog post
- Final Output: The workflow returns the final blog post from the Writer agent
Common Use Cases
SequentialWorkflow is ideal for:
- Content Creation Pipelines: Research → Writing → Editing → Publishing
- Data Processing: Collection → Cleaning → Analysis → Reporting
- Software Development: Design → Implementation → Testing → Deployment
- Document Processing: Extraction → Transformation → Validation → Storage
- Report Generation: Data gathering → Analysis → Visualization → Summary
Variations
Three-Stage Content Pipeline
Add an editor to review and polish the content:
from swarms import Agent, SequentialWorkflow
# Define three agents for a complete content pipeline
researcher = Agent(
agent_name="Researcher",
system_prompt="Research the topic thoroughly and provide comprehensive findings.",
model_name="gpt-5.4",
)
writer = Agent(
agent_name="Writer",
system_prompt="Transform research into an engaging, well-structured article.",
model_name="gpt-5.4",
)
editor = Agent(
agent_name="Editor",
system_prompt="Review the article for clarity, grammar, and style. Polish the final content.",
model_name="gpt-5.4",
)
# Create sequential workflow with three stages
workflow = SequentialWorkflow(agents=[researcher, writer, editor])
# Run the complete pipeline
polished_article = workflow.run("The impact of quantum computing on cybersecurity")
print(polished_article)
Multi-Step Data Processing
Process data through multiple transformation stages:
from swarms import Agent, SequentialWorkflow
# Define agents for data processing pipeline
data_collector = Agent(
agent_name="DataCollector",
system_prompt="Gather and collect data from various sources on the given topic.",
model_name="gpt-5.4",
)
data_cleaner = Agent(
agent_name="DataCleaner",
system_prompt="Clean and normalize the collected data, removing inconsistencies.",
model_name="gpt-5.4",
)
data_analyzer = Agent(
agent_name="DataAnalyzer",
system_prompt="Analyze the cleaned data and extract meaningful insights.",
model_name="gpt-5.4",
)
report_generator = Agent(
agent_name="ReportGenerator",
system_prompt="Generate a comprehensive report based on the analysis.",
model_name="gpt-5.4",
)
# Create the data processing workflow
workflow = SequentialWorkflow(
agents=[data_collector, data_cleaner, data_analyzer, report_generator]
)
# Process data through the pipeline
final_report = workflow.run("Analyze customer feedback trends from Q1 2024")
print(final_report)
Code Development Pipeline
Build a complete software development workflow:
from swarms import Agent, SequentialWorkflow
# Define agents for software development
designer = Agent(
agent_name="Designer",
system_prompt="Design the architecture and structure for the requested feature.",
model_name="gpt-5.4",
)
developer = Agent(
agent_name="Developer",
system_prompt="Implement the feature based on the design specifications.",
model_name="gpt-5.4",
)
tester = Agent(
agent_name="Tester",
system_prompt="Test the implementation and identify any bugs or issues.",
model_name="gpt-5.4",
)
deployer = Agent(
agent_name="Deployer",
system_prompt="Create deployment instructions and documentation for the feature.",
model_name="gpt-5.4",
)
# Create the development workflow
workflow = SequentialWorkflow(agents=[designer, developer, tester, deployer])
# Run the development pipeline
deployment_package = workflow.run("Create a user authentication system with JWT tokens")
print(deployment_package)
Best Practices
- Clear Agent Roles: Define specific, focused responsibilities for each agent
- Appropriate Ordering: Arrange agents in logical sequence based on task dependencies
- Detailed System Prompts: Provide clear instructions about input expectations and output format
- Error Handling: Consider what happens if an intermediate agent fails
- Pipeline Length: Keep workflows manageable; very long pipelines may benefit from breaking into sub-workflows
Key Benefits
- Maintainability: Easy to understand and modify the workflow sequence
- Reliability: Deterministic execution order ensures consistent results
- Debugging: Simple to identify and fix issues at specific stages
- Reusability: Individual agents can be reused in different workflows
- Scalability: Easy to add or remove stages from the pipeline
Learn More