๐Ÿ”ฅ 0
โญ 0
Lesson 9 of 10 20 min +175 XP

Orchestration Patterns: Sequential vs Hierarchical

How your agents work together matters as much as what they do individually. CrewAI offers different orchestration patterns for different types of workflows. Choosing the right pattern can mean the difference between elegant automation and a tangled mess.

Understanding Process Types

CrewAI supports two main process types:

SEQUENTIAL PROCESS

Tasks execute one after another in a defined order. Output from each task flows to the next.

Task A โ†’ Task B โ†’ Task C โ†’ Result

HIERARCHICAL PROCESS

A manager agent delegates tasks to workers and coordinates their outputs.

Manager โ†’ [Workers] โ†’ Manager โ†’ Result

Sequential Process Deep Dive

Sequential is the default and most common pattern. It's like an assembly line.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    SEQUENTIAL PROCESS                           โ”‚
โ”‚                                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚Research  โ”‚โ”€โ”€โ”€โ–ถโ”‚  Write   โ”‚โ”€โ”€โ”€โ–ถโ”‚  Review  โ”‚โ”€โ”€โ”€โ–ถโ”‚ Publish  โ”‚  โ”‚
โ”‚  โ”‚  Agent   โ”‚    โ”‚  Agent   โ”‚    โ”‚  Agent   โ”‚    โ”‚  Agent   โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                                 โ”‚
โ”‚  Each agent receives output from the previous agent            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

When to Use Sequential

Use Sequential When:
  • Clear linear dependency
  • Each step builds on previous
  • Order is predictable
  • Pipeline-style workflows
Avoid Sequential When:
  • Tasks could run in parallel
  • Dynamic routing needed
  • Order depends on input
  • Manager oversight required

Sequential E-commerce Examples

from crewai import Crew, Process

# Product Listing Pipeline - Classic Sequential
product_listing_crew = Crew(
    agents=[researcher, copywriter, seo_specialist, reviewer],
    tasks=[research_task, writing_task, seo_task, review_task],
    process=Process.sequential  # Default
)

# Order Processing Pipeline - Sequential
order_processing_crew = Crew(
    agents=[validator, inventory_checker, payment_processor, fulfillment],
    tasks=[validate_order, check_inventory, process_payment, create_shipment],
    process=Process.sequential
)

# Customer Onboarding - Sequential
onboarding_crew = Crew(
    agents=[welcome_agent, profile_agent, recommendation_agent],
    tasks=[send_welcome, collect_preferences, generate_recommendations],
    process=Process.sequential
)

Hierarchical Process Deep Dive

Hierarchical process adds a manager layer that dynamically delegates work.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   HIERARCHICAL PROCESS                          โ”‚
โ”‚                                                                 โ”‚
โ”‚                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                             โ”‚
โ”‚                    โ”‚   MANAGER    โ”‚                             โ”‚
โ”‚                    โ”‚    Agent     โ”‚                             โ”‚
โ”‚                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                             โ”‚
โ”‚                           โ”‚                                     โ”‚
โ”‚          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                    โ”‚
โ”‚          โ–ผ                โ–ผ                โ–ผ                    โ”‚
โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                โ”‚
โ”‚    โ”‚ Pricing  โ”‚    โ”‚ Support  โ”‚    โ”‚Inventory โ”‚                โ”‚
โ”‚    โ”‚  Expert  โ”‚    โ”‚  Expert  โ”‚    โ”‚  Expert  โ”‚                โ”‚
โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                โ”‚
โ”‚                                                                 โ”‚
โ”‚  Manager decides who to involve based on the situation         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

When to Use Hierarchical

Use Hierarchical When:
  • Problem-solving, not pipeline
  • Dynamic routing needed
  • Complex coordination
  • Specialist consultation
Avoid Hierarchical When:
  • Simple linear workflows
  • Overhead isn't justified
  • Fixed process required
  • Predictability essential

Implementing a Hierarchical Crew

from crewai import Agent, Task, Crew, Process

# Define specialist agents
pricing_expert = Agent(
    role="Pricing Specialist",
    goal="Provide pricing expertise and recommendations",
    backstory="Expert in e-commerce pricing strategies",
    verbose=True
)

inventory_expert = Agent(
    role="Inventory Specialist",
    goal="Provide inventory status and availability information",
    backstory="Expert in supply chain and inventory management",
    verbose=True
)

support_expert = Agent(
    role="Customer Support Specialist",
    goal="Handle customer concerns with empathy and solutions",
    backstory="Expert in customer satisfaction and issue resolution",
    verbose=True
)

shipping_expert = Agent(
    role="Shipping Specialist",
    goal="Handle shipping and delivery inquiries",
    backstory="Expert in logistics and delivery optimization",
    verbose=True
)

# Define the manager agent
customer_service_manager = Agent(
    role="Customer Service Manager",
    goal="Coordinate specialist agents to resolve customer issues effectively",
    backstory="""You are an experienced customer service manager who
    knows how to route issues to the right specialists. You assess
    each situation and delegate to the appropriate experts.

    Your approach:
    - Analyze the customer issue to identify required expertise
    - Delegate to relevant specialists (one or multiple)
    - Synthesize their inputs into a cohesive response
    - Ensure the customer gets a complete resolution""",
    verbose=True,
    allow_delegation=True  # Manager can delegate to others
)

# Define the task for the manager
resolve_customer_issue = Task(
    description="""
    Resolve the following customer issue:

    {customer_issue}

    Analyze the issue and delegate to appropriate specialists.
    Synthesize their expertise into a complete resolution.
    Ensure the customer receives a helpful, actionable response.
    """,
    expected_output="""
    Complete customer response including:
    - Acknowledgment of their concern
    - Specific resolution steps
    - Any relevant information from specialists
    - Follow-up actions if needed
    """,
    agent=customer_service_manager
)

# Create hierarchical crew
customer_service_crew = Crew(
    agents=[
        customer_service_manager,
        pricing_expert,
        inventory_expert,
        support_expert,
        shipping_expert
    ],
    tasks=[resolve_customer_issue],
    process=Process.hierarchical,
    manager_agent=customer_service_manager,  # Explicit manager
    verbose=True
)

# Example usage
result = customer_service_crew.kickoff(inputs={
    "customer_issue": """
    I ordered a laptop 5 days ago (Order #12345) and paid for express shipping.
    The tracking still shows 'processing' and I need it for a presentation on Friday.
    Also, I noticed you're now selling it for $50 less. Can I get the difference refunded?
    """
})

How Hierarchical Delegation Works

When the crew runs, the manager:

  • Analyzes the issue - identifies shipping delay and pricing concern
  • Delegates to shipping expert for order status
  • Delegates to pricing expert for price match policy
  • Synthesizes both responses into one cohesive reply
  • Returns complete resolution to customer
[Manager] Analyzing customer issue...
[Manager] Issue requires: Shipping status + Price match inquiry
[Manager] Delegating to Shipping Expert...
[Shipping Expert] Order #12345 delayed due to carrier backlog, expediting now
[Manager] Delegating to Pricing Expert...
[Pricing Expert] Price match eligible within 7 days, refund approved
[Manager] Synthesizing response...

Comparison: Side by Side

Aspect Sequential Hierarchical
Control Flow Fixed order, predetermined Dynamic, manager decides
Best For Pipelines, content creation Problem-solving, support
Complexity Simple, predictable More complex, flexible
Token Usage Lower (direct flow) Higher (manager overhead)
Debugging Easier (linear trace) Harder (dynamic routing)
E-commerce Uses Product listings, campaigns Customer service, complex queries

E-commerce Pattern Examples

Pattern 1: Product Launch (Sequential)

Perfect for sequential - each step builds on the previous:

# Research โ†’ Copy โ†’ SEO โ†’ Design Brief โ†’ Review โ†’ Publish
product_launch_crew = Crew(
    agents=[researcher, copywriter, seo, designer, reviewer, publisher],
    tasks=[research, write, optimize, design_brief, review, publish],
    process=Process.sequential
)

Pattern 2: Customer Support Ticket (Hierarchical)

Perfect for hierarchical - issue type determines routing:

# Manager analyzes ticket, routes to appropriate specialists
support_crew = Crew(
    agents=[manager, billing, technical, shipping, returns],
    tasks=[resolve_ticket],
    process=Process.hierarchical,
    manager_agent=manager
)

Pattern 3: Daily Operations Dashboard (Hybrid)

Some workflows benefit from combining patterns:

# Sequential for data gathering, Hierarchical for decisions
class DailyOperationsCrew:
    def __init__(self):
        # Sequential crew for gathering data
        self.data_crew = Crew(
            agents=[sales_tracker, inventory_tracker, support_tracker],
            tasks=[get_sales, get_inventory, get_tickets],
            process=Process.sequential
        )

        # Hierarchical crew for action decisions
        self.decision_crew = Crew(
            agents=[ops_manager, pricing_agent, restock_agent, support_escalation],
            tasks=[make_daily_decisions],
            process=Process.hierarchical,
            manager_agent=ops_manager
        )

    def run_daily_ops(self):
        # First, gather data sequentially
        data = self.data_crew.kickoff()

        # Then, make decisions hierarchically
        decisions = self.decision_crew.kickoff(inputs={"daily_data": data})

        return decisions

Choosing the Right Pattern

Use this decision framework:

                    Is there a clear
                    linear workflow?
                          โ”‚
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚                       โ”‚
             YES                     NO
              โ”‚                       โ”‚
              โ–ผ                       โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    Does the next step
    โ”‚   SEQUENTIAL    โ”‚    depend on input?
    โ”‚                 โ”‚           โ”‚
    โ”‚ โ€ข Product copy  โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ โ€ข Order process โ”‚    โ”‚             โ”‚
    โ”‚ โ€ข Campaigns     โ”‚   YES           NO
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚             โ”‚
                           โ–ผ             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ HIERARCHICAL โ”‚  โ”‚  Consider    โ”‚
                  โ”‚              โ”‚  โ”‚  PARALLEL    โ”‚
                  โ”‚ โ€ข Support    โ”‚  โ”‚  (Future)    โ”‚
                  โ”‚ โ€ข Complex    โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚   queries    โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Takeaways

  • Sequential for pipelines - When step B always follows step A
  • Hierarchical for problem-solving - When routing depends on the input
  • Manager agents need allow_delegation=True - Required for hierarchical
  • Hierarchical has higher token cost - Manager reasoning adds overhead
  • Hybrid patterns work - Combine patterns for complex workflows

Next up: CrewAI E-commerce Assessment - Test your knowledge with a comprehensive quiz.

๐Ÿง  Quick Quiz

Test your understanding of this lesson.

1

When should you use a Sequential process in CrewAI?

2

What is the key characteristic of a Hierarchical crew process?

3

In which e-commerce scenario would a Hierarchical crew be more appropriate than Sequential?

Competitor Analysis Agent Crew