← Back to DevBytes

Hierarchical Agent Teams: Manager-Worker Patterns in CrewAI

Understanding Hierarchical Agent Teams in CrewAI

The Manager-Worker pattern in CrewAI introduces a hierarchical structure where a manager agent orchestrates and delegates tasks to specialized worker agents. Instead of all agents collaborating as equals in a flat sequence, one agent assumes a supervisory role — reviewing outputs, assigning subtasks, and validating results before proceeding. This mirrors real-world organizational structures where project leads coordinate specialists to achieve complex goals.

What is the Manager-Worker Pattern?

In a standard CrewAI flow, agents execute tasks in a defined sequence — either sequentially or in parallel. The Manager-Worker pattern breaks this mold by introducing a manager agent that dynamically decides which worker to invoke, what task to assign, and how to process the results. The manager acts as a reasoning layer that evaluates context, delegates work, and synthesizes final outputs.

Key characteristics include:

Why the Manager-Worker Pattern Matters

Flat agent architectures work well for straightforward, linear workflows. But as task complexity grows, you encounter challenges that hierarchical delegation solves naturally:

Setting Up CrewAI with the Hierarchical Process

CrewAI provides a built-in Process.hierarchical execution model. When you set this process type, CrewAI automatically designates the agent with manager=True as the coordinating manager. Let's build a complete example step by step.

Step 1: Install CrewAI and Dependencies

pip install crewai crewai-tools langchain-openai

Step 2: Define Worker Agents

Each worker agent gets a focused role, a specific goal, and tools relevant to its domain. Notice we do not set allow_delegation=True on workers — only the manager should delegate.

from crewai import Agent
from crewai_tools import SerperDevTool, WebsiteSearchTool

# Shared tools
search_tool = SerperDevTool()
web_scraper = WebsiteSearchTool()

# Worker: Researcher
researcher = Agent(
    role="Senior Data Researcher",
    goal="Gather accurate, up-to-date information on the given topic from reliable sources",
    backstory=(
        "You are a meticulous researcher with 15 years of experience in investigative journalism. "
        "You cross-reference multiple sources and always cite your findings."
    ),
    tools=[search_tool, web_scraper],
    allow_delegation=False,  # Workers do NOT delegate
    verbose=True,
)

# Worker: Technical Analyst
analyst = Agent(
    role="Technical Market Analyst",
    goal="Analyze research data and extract actionable insights, trends, and numerical comparisons",
    backstory=(
        "You hold a PhD in data science and have worked at top consulting firms. "
        "You turn raw data into structured reports with clear recommendations."
    ),
    tools=[],
    allow_delegation=False,
    verbose=True,
)

# Worker: Report Writer
writer = Agent(
    role="Senior Technical Writer",
    goal="Transform analysis into a polished, publication-ready report with executive summaries",
    backstory=(
        "You are an award-winning technical writer who has authored white papers for Fortune 500 companies. "
        "Your prose is clear, concise, and compelling."
    ),
    tools=[],
    allow_delegation=False,
    verbose=True,
)

Step 3: Define the Manager Agent

The manager agent is the cornerstone of the pattern. Set manager=True and allow_delegation=True. Give the manager a broad, oversight-oriented goal. The manager's backstory should emphasize its coordinating and quality-assurance responsibilities.

manager = Agent(
    role="Project Manager & Chief Editor",
    goal=(
        "Orchestrate the research, analysis, and writing process to produce a comprehensive, "
        "accurate, and well-structured final report. Ensure every section meets quality standards."
    ),
    backstory=(
        "You are an experienced project lead who has managed complex research teams for over two decades. "
        "You excel at breaking down large objectives into discrete tasks, reviewing deliverables, "
        "and synthesizing contributions into a unified whole. You are pragmatic and deadline-driven."
    ),
    allow_delegation=True,
    manager=True,  # This marks the agent as the hierarchical manager
    verbose=True,
)

Step 4: Create Tasks

In a hierarchical process, you typically define high-level tasks and let the manager decompose them. The manager will internally create subtasks for workers. However, you can still provide guidance via task descriptions. Note that tasks in hierarchical mode often don't specify an agent directly — the manager assigns them dynamically.

from crewai import Task

research_task = Task(
    description=(
        "Research the current state of renewable energy adoption in Southeast Asia. "
        "Focus on solar, wind, and hydropower. Gather data on installed capacity (in GW), "
        "year-over-year growth rates, major projects, government incentives, and key players. "
        "Provide citations for all quantitative claims."
    ),
    expected_output="A detailed research brief with cited statistics, trends, and source references.",
    # No agent assigned — the manager will delegate this
)

analysis_task = Task(
    description=(
        "Take the research brief and perform a comparative analysis. Identify the top 3 fastest-growing "
        "renewable segments, calculate compound annual growth rates where possible, highlight investment "
        "patterns, and flag any policy risks. Structure your output with clear headings and bullet-point summaries."
    ),
    expected_output="A structured analysis document with growth metrics, risk assessment, and recommendations.",
)

writing_task = Task(
    description=(
        "Using the analysis document, produce a final executive report titled 'Southeast Asia Renewable "
        "Energy Outlook 2025'. Include: (1) Executive Summary, (2) Key Findings, (3) Segment Deep-Dives, "
        "(4) Investment Landscape, (5) Risks & Recommendations. Format in Markdown with a professional tone."
    ),
    expected_output="A polished, publication-ready Markdown report with all five sections.",
)

Step 5: Assemble the Crew with Hierarchical Process

The critical piece is setting process=Process.hierarchical. This tells CrewAI to route all task planning through the manager agent. The manager receives the task list, plans execution, delegates to workers, reviews their outputs, and assembles the final result.

from crewai import Crew, Process

crew = Crew(
    agents=[researcher, analyst, writer, manager],
    tasks=[research_task, analysis_task, writing_task],
    process=Process.hierarchical,  # Activates the Manager-Worker pattern
    manager_agent=manager,         # Explicitly designate the manager
    verbose=True,
    memory=True,  # Enables cross-task context retention
)

# Kick off the crew
result = crew.kickoff()
print(result)

How the Manager-Worker Execution Actually Works

When crew.kickoff() runs with Process.hierarchical, here's what happens under the hood:

  1. Planning phase — The manager receives all top-level tasks and analyzes their descriptions. It formulates an execution plan, deciding which worker handles what, and in what order
  2. Delegation phase — The manager creates subtasks and assigns them to the most appropriate worker. For example, the research task goes to the researcher agent
  3. Execution & review — Each worker executes its assigned subtask and returns output to the manager. The manager reviews the result against the expected output criteria
  4. Iteration (if needed) — If a worker's output is incomplete or off-target, the manager can request clarifications or reassign the subtask
  5. Synthesis — Once all subtasks complete satisfactorily, the manager compiles the final deliverable — either passing intermediate results to the next phase or merging everything into a final response

Advanced: Custom Manager Logic with LangChain Tools

You can enhance the manager's reasoning by equipping it with custom tools for planning and evaluation. Here's an example of a manager with a planning tool that helps it break down complex objectives:

from langchain_openai import ChatOpenAI
from crewai import Agent

# Custom planning tool (simplified example)
class PlanningTool:
    """Gives the manager structured planning capabilities."""
    
    def create_plan(self, objective: str, available_agents: list[str]) -> dict:
        """
        Returns a structured execution plan with phases, 
        assigned agents, and success criteria.
        """
        # In production, this could call an LLM for plan generation
        plan = {
            "objective": objective,
            "phases": [
                {
                    "phase": "Research",
                    "assigned_agent": available_agents[0],
                    "deliverable": "Research brief with citations",
                    "review_criteria": ["Completeness", "Source quality", "Data freshness"]
                },
                {
                    "phase": "Analysis",
                    "assigned_agent": available_agents[1],
                    "deliverable": "Structured analysis document",
                    "review_criteria": ["Quantitative rigor", "Actionable insights"]
                },
                {
                    "phase": "Writing",
                    "assigned_agent": available_agents[2],
                    "deliverable": "Final executive report",
                    "review_criteria": ["Clarity", "Professional tone", "Section completeness"]
                }
            ]
        }
        return plan

# Enhanced manager with custom tools
enhanced_manager = Agent(
    role="Strategic Program Manager",
    goal="Plan, delegate, review, and synthesize with maximum efficiency and output quality",
    backstory=(
        "You are a certified PMP with experience managing multi-million-dollar research programs. "
        "You use structured planning methodologies and always validate outputs before integration."
    ),
    tools=[PlanningTool()],
    allow_delegation=True,
    manager=True,
    verbose=True,
    llm=ChatOpenAI(model="gpt-4o", temperature=0.2),  # Lower temperature for consistent decisions
)

Best Practices for Manager-Worker Crews

Common Pitfalls and How to Avoid Them

Pitfall 1: Overly vague task descriptions. If a task description is too generic, the manager struggles to create meaningful subtasks. Always specify scope, format, and success criteria explicitly in the task description.

Pitfall 2: Manager micromanagement loops. If the manager rejects worker outputs too many times, the crew can get stuck in an iteration loop. Set a maximum retry count or provide the manager with a "accept with minor edits" option.

Pitfall 3: Workers with overlapping skills. When two workers can handle the same task, the manager may flip-flop between them. Differentiate worker roles sharply in their backstories.

Pitfall 4: Forgetting to set manager=True. Without this flag, even if you use Process.hierarchical, CrewAI won't know which agent is the manager. Always explicitly set manager=True on exactly one agent.

Complete Production-Ready Example

Here's a full, self-contained example combining all best practices. This crew researches a technology trend, analyzes it, and produces a final report — all coordinated by a hierarchical manager:

import os
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool, WebsiteSearchTool
from langchain_openai import ChatOpenAI

# Configure API keys
os.environ["OPENAI_API_KEY"] = "your-openai-key"
os.environ["SERPER_API_KEY"] = "your-serper-key"

# Shared LLM with different temperatures
manager_llm = ChatOpenAI(model="gpt-4o", temperature=0.2)
worker_llm = ChatOpenAI(model="gpt-4o-mini", temperature=0.7)

# Tools
search = SerperDevTool()
scraper = WebsiteSearchTool()

# ---- WORKER AGENTS ----
researcher = Agent(
    role="Deep Researcher",
    goal="Find and verify factual information with source citations",
    backstory="Expert researcher skilled in finding niche data points and verifying claims.",
    tools=[search, scraper],
    llm=worker_llm,
    allow_delegation=False,
    verbose=True,
)

analyst = Agent(
    role="Quantitative Analyst",
    goal="Derive insights, trends, and numerical comparisons from raw research data",
    backstory="Former McKinsey analyst specialized in technology market intelligence.",
    tools=[],
    llm=worker_llm,
    allow_delegation=False,
    verbose=True,
)

writer = Agent(
    role="Executive Writer",
    goal="Produce polished, structured reports ready for C-suite presentation",
    backstory="Award-winning business writer with experience at The Economist and Bloomberg.",
    tools=[],
    llm=worker_llm,
    allow_delegation=False,
    verbose=True,
)

# ---- MANAGER AGENT ----
manager = Agent(
    role="Delivery Manager",
    goal="Coordinate the team to produce a complete, accurate, high-quality final report on time",
    backstory=(
        "Seasoned engineering manager with a track record of delivering complex technical projects. "
        "You break work into phases, assign tasks based on agent specializations, review all outputs, "
        "and ensure the final deliverable meets the highest standards."
    ),
    llm=manager_llm,
    allow_delegation=True,
    manager=True,
    verbose=True,
)

# ---- TASKS ----
tasks = [
    Task(
        description=(
            "Research the adoption of AI coding assistants (Copilot, Cursor, Codeium, etc.) "
            "among professional developers in 2024-2025. Gather data on: market share per tool, "
            "total user counts, pricing models, key features, developer satisfaction scores, "
            "and notable enterprise adoption cases. Cite all sources."
        ),
        expected_output="Research brief with at least 10 quantitative data points and source citations.",
    ),
    Task(
        description=(
            "Analyze the research data. Calculate growth trends, compare tools on key dimensions "
            "(accuracy, latency, language support, price), identify market leaders, and assess "
            "which segments (individual devs, startups, enterprises) are adopting fastest. "
            "Present findings as structured sections with tables where appropriate."
        ),
        expected_output="Structured analysis with comparative tables, growth figures, and segment breakdowns.",
    ),
    Task(
        description=(
            "Write a final report: 'AI Copilot Landscape 2025: Developer Adoption & Market Analysis'. "
            "Sections: Executive Summary, Methodology, Market Overview, Tool Comparisons, "
            "Adoption Trends by Segment, Enterprise Case Studies, Outlook & Recommendations. "
            "Professional Markdown formatting, 2500+ words."
        ),
        expected_output="Complete, polished Markdown report exceeding 2500 words with all specified sections.",
    ),
]

# ---- CREW ASSEMBLY ----
crew = Crew(
    agents=[researcher, analyst, writer, manager],
    tasks=tasks,
    process=Process.hierarchical,
    manager_agent=manager,
    memory=True,
    verbose=True,
)

# Execute
if __name__ == "__main__":
    final_report = crew.kickoff()
    print("\n=== FINAL DELIVERABLE ===\n")
    print(final_report)
    
    # Optionally save to file
    with open("ai_copilot_report.md", "w") as f:
        f.write(str(final_report))

Comparing Hierarchical vs. Sequential Processes

Choosing between Process.hierarchical and Process.sequential depends on your use case:

The hierarchical process adds latency and token cost from the manager's planning and review cycles. For simple "research → summarize" pipelines, sequential is faster and cheaper. For multi-stage projects with quality gates, hierarchical is indispensable.

Conclusion

The Manager-Worker pattern in CrewAI transforms multi-agent systems from rigid pipelines into adaptive, quality-controlled workflows. By designating a manager agent and using Process.hierarchical, you gain dynamic delegation, iterative review, and coherent final synthesis — all while keeping individual workers focused and efficient. The pattern shines in complex projects where task decomposition can't be fully predicted upfront. Start by defining sharp worker specializations, craft a manager with oversight-oriented goals, write tasks with explicit expected outputs, and monitor the delegation behavior during development. With these practices in place, your agent teams will produce higher-quality results with less manual orchestration, bringing you closer to truly autonomous multi-agent collaboration.

— Ad —

Google AdSense will appear here after approval

← Back to all articles