Swarm Type: SequentialWorkflow

Overview

The SequentialWorkflow swarm type executes tasks in a strict, predefined order where each step depends on the completion of the previous one. This architecture is perfect for workflows that require a linear progression of tasks, ensuring that each agent builds upon the work of the previous agent. Key features:
  • Ordered Execution: Agents execute in a specific, predefined sequence
  • Step Dependencies: Each step builds upon previous results
  • Predictable Flow: Clear, linear progression through the workflow
  • Quality Control: Each agent can validate and enhance previous work

Use Cases

  • Document processing pipelines
  • Multi-stage analysis workflows
  • Content creation and editing processes
  • Data transformation and validation pipelines

API Usage

Basic SequentialWorkflow Example

curl -X POST "https://api.swarms.world/v1/swarm/completions" \
  -H "x-api-key: $SWARMS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Content Creation Pipeline",
    "description": "Sequential content creation from research to final output",
    "swarm_type": "SequentialWorkflow",
    "task": "Create a comprehensive blog post about the future of renewable energy",
    "agents": [
      {
        "agent_name": "Research Specialist",
        "description": "Conducts thorough research on the topic",
        "system_prompt": "You are a research specialist. Gather comprehensive, accurate information on the given topic from reliable sources.",
        "model_name": "gpt-4o",
        "max_loops": 1,
        "temperature": 0.3
      },
      {
        "agent_name": "Content Writer",
        "description": "Creates engaging written content",
        "system_prompt": "You are a skilled content writer. Transform research into engaging, well-structured articles that are informative and readable.",
        "model_name": "gpt-4o",
        "max_loops": 1,
        "temperature": 0.6
      },
      {
        "agent_name": "Editor",
        "description": "Reviews and polishes the content",
        "system_prompt": "You are a professional editor. Review content for clarity, grammar, flow, and overall quality. Make improvements while maintaining the author's voice.",
        "model_name": "gpt-4o",
        "max_loops": 1,
        "temperature": 0.4
      },
      {
        "agent_name": "SEO Optimizer",
        "description": "Optimizes content for search engines",
        "system_prompt": "You are an SEO expert. Optimize content for search engines while maintaining readability and quality.",
        "model_name": "gpt-4o",
        "max_loops": 1,
        "temperature": 0.2
      }
    ],
    "max_loops": 1
  }'
Example Response:
{
    "job_id": "swarms-S17nZFDesmLHxCRoeyF3NVYvPaXk",
    "status": "success",
    "swarm_name": "Content Creation Pipeline",
    "description": "Sequential content creation from research to final output",
    "swarm_type": "SequentialWorkflow",
    "output": [
        {
            "role": "Research Specialist",
            "content": "Based on my research on renewable energy, here are the key findings about the future of this sector..."
        },
        {
            "role": "Content Writer",
            "content": "Building on the research, here's a comprehensive blog post about the future of renewable energy..."
        },
        {
            "role": "Editor",
            "content": "After reviewing the content, I've made the following improvements for clarity and flow..."
        },
        {
            "role": "SEO Optimizer",
            "content": "I've optimized the content with the following SEO improvements while maintaining quality..."
        }
    ],
    "number_of_agents": 4,
    "service_tier": "standard",
    "execution_time": 45.2,
    "usage": {
        "input_tokens": 35,
        "output_tokens": 3200,
        "total_tokens": 3235,
        "billing_info": {
            "cost_breakdown": {
                "agent_cost": 0.04,
                "input_token_cost": 0.000105,
                "output_token_cost": 0.048,
                "token_counts": {
                    "total_input_tokens": 35,
                    "total_output_tokens": 3200,
                    "total_tokens": 3235
                },
                "num_agents": 4,
                "service_tier": "standard",
                "night_time_discount_applied": true
            },
            "total_cost": 0.088105,
            "discount_active": true,
            "discount_type": "night_time",
            "discount_percentage": 75
        }
    }
}

Best Practices

  • Design workflows with clear dependencies between steps
  • Use for tasks that require sequential processing
  • Ensure each agent builds upon previous results effectively
  • Ideal for quality control and validation workflows