Lesson 4 of 5·11 min read

Advanced Crew Patterns

Beyond sequential and hierarchical, there are advanced patterns that make CrewAI a powerful orchestration framework. From manager agents through conditional task execution to inter-crew communication.

Hierarchical Crews

In hierarchical process, a manager agent takes over coordination:

from crewai import Crew, Process

crew = Crew(
    agents=[researcher, analyst, writer],
    tasks=[research_task, analysis_task, writing_task],
    process=Process.hierarchical,
    manager_llm=ChatOpenAI(model="gpt-4o"),
    manager_agent=None  # Automatic manager
)

Custom Manager Agent

manager = Agent(
    role="Project Director",
    goal="Coordinate the team, ensure quality and "
         "keep the schedule",
    backstory="Experienced project director with expertise in "
              "agile methods and stakeholder management",
    allow_delegation=True
)

crew = Crew(
    agents=[researcher, analyst, writer],
    tasks=[research_task, analysis_task, writing_task],
    process=Process.hierarchical,
    manager_agent=manager
)

Conditional Task Execution

Tasks can be skipped or activated based on conditions:

def should_run_deep_analysis(context):
    """Only deep analysis if initial research is significant."""
    research_output = context[0].output
    return "significant" in research_output.lower() or len(research_output) > 2000

deep_analysis_task = Task(
    description="Perform deep analysis of significant findings",
    expected_output="Detailed analysis with statistical metrics",
    agent=analyst,
    context=[research_task],
    condition=should_run_deep_analysis
)

Crew Collaboration

Multiple crews can work together — each crew specializes in a task area:

# Crew 1: Research
research_crew = Crew(
    agents=[web_researcher, academic_researcher],
    tasks=[web_research_task, academic_research_task],
    process=Process.sequential
)

# Crew 2: Analysis & Reporting
analysis_crew = Crew(
    agents=[data_analyst, report_writer],
    tasks=[analysis_task, report_task],
    process=Process.sequential
)

# Sequential crew execution
research_result = research_crew.kickoff(inputs={"topic": "AI Agents"})
final_result = analysis_crew.kickoff(inputs={
    "topic": "AI Agents",
    "research_data": research_result.raw
})

Inter-Crew Communication

Output as Input

# Crew 1 result → Crew 2 input
crew1_result = crew1.kickoff(inputs={"query": "Market analysis DACH"})
crew2_result = crew2.kickoff(inputs={
    "research": crew1_result.raw,
    "format": "executive_summary"
})

Shared Knowledge Base

Crews can share a common knowledge base:

from crewai.knowledge import Knowledge

shared_knowledge = Knowledge(
    sources=["docs/company_data.pdf", "docs/market_reports/"],
    embedder={"provider": "openai"}
)

crew1 = Crew(agents=[...], tasks=[...], knowledge=shared_knowledge)
crew2 = Crew(agents=[...], tasks=[...], knowledge=shared_knowledge)

Pattern Selection

PatternWhen to useComplexity
SequentialLinear sequence, clear orderLow
HierarchicalManager decisions neededMedium
Multi-crewSeparate responsibility areasHigh
ConditionalDynamic workflowsMedium

Practical tip: Always start with sequential. Switch to hierarchical when the workflow requires decisions. Multi-crew only pays off when you have clearly separated responsibility areas — otherwise you increase complexity without added value.