Synaptic AI Consulting
Estimated time: ~15 minutes
Outcome: Understand how to build Application Crews using CrewAI framework
By the end of this module, you will be able to:
CrewAI is an open-source framework designed to orchestrate role-playing, autonomous AI agents. It enables developers to create sophisticated multi-agent systems where specialized agents collaborate to accomplish complex tasks. CrewAI is the default framework used in the AAMAD method for building Application Crews—the core intelligence that powers your agentic applications.
Think of CrewAI as the “operating system” for your Application Crew. Just as an operating system manages processes and resources, CrewAI manages agents, tasks, and their interactions.
Before diving into CrewAI specifics, let’s clarify the Application Crew’s role in your architecture:
flowchart LR
Frontend[Frontend<br/>User Interface] -->|API Calls| Backend[Application Crew<br/>CrewAI Agents]
Backend -->|Processes & Responds| Frontend
subgraph Backend["Application Crew (Built with CrewAI)"]
Agent1[Agent 1]
Agent2[Agent 2]
Agent3[Agent 3]
end
style Frontend fill:#e3f2fd,stroke:#1976d2,stroke-width:2px,color:#000000
style Backend fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px,color:#000000
style Agent1 fill:#c8e6c9,color:#000000
style Agent2 fill:#c8e6c9,color:#000000
style Agent3 fill:#c8e6c9,color:#000000
The Application Crew is the backend intelligence of your agentic application. It:
During the AAMAD Build phase, you’ll design and implement this Application Crew using CrewAI, while your Development Crew (the temporary AI agents that build your application) creates both the frontend and the Application Crew backend.
CrewAI is built on three fundamental components:
An agent is an autonomous AI entity with a specific role, goal, and capabilities. Each agent is designed to excel at particular tasks.
Key Agent Properties:
Example:
from crewai import Agent
support_agent = Agent(
role="Customer Support Specialist",
goal="Resolve customer inquiries quickly and accurately",
backstory="You are an experienced customer service professional with deep knowledge of our products and services.",
tools=[search_knowledge_base, create_ticket],
verbose=True
)
A task is a unit of work assigned to an agent. Tasks define what needs to be accomplished, including:
Example:
from crewai import Task
analyze_inquiry = Task(
description="Analyze the customer's inquiry and identify the core issue",
agent=support_agent,
expected_output="A structured analysis of the customer's problem with key details identified"
)
Tools are functionalities that agents use to perform their tasks. Tools extend agent capabilities beyond language model responses.
Common Tool Types:
Example:
from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
agent = Agent(
role="Researcher",
tools=[search_tool] # Agent can now search the web
)
CrewAI provides two primary orchestration mechanisms. Understanding when to use each is crucial for designing effective Application Crews.
A Crew is a team of agents that work together to accomplish a shared goal. Crews are ideal when:
Crew Characteristics:
Use Cases:
A Flow is a more structured, sequential workflow where agents execute tasks in a predefined order. Flows are ideal when:
Flow Characteristics:
Use Cases:
Use this Decision Matrix to choose between Crews and Flows based on two dimensions: Complexity and Precision.
The Decision Matrix:
quadrantChart
title Decision Matrix: Crews vs Flows
x-axis Low Precision --> High Precision
y-axis Low Complexity --> High Complexity
quadrant-2 CREWS
quadrant-1 FLOWS + CREWS
quadrant-3 CREWS
quadrant-4 FLOWS
Step 1: Assess Precision (Rate each 1-10, then average)
Step 2: Assess Complexity (Rate each 1-10, then average)
Decision Rules:
Quick Reference:
| Complexity | Precision | Recommendation |
|---|---|---|
| Low | Low | CREWS |
| Low | High | FLOWS |
| High | Low | CREWS |
| High | High | FLOWS + CREWS |
CrewAI supports several orchestration patterns that determine how agents coordinate and execute tasks. Understanding these patterns helps you design efficient Application Crews.
Tasks execute one after another in a fixed order. Each task waits for the previous one to complete.
Characteristics:
Example Use Case: A document processing system where:
flowchart LR
A[Agent A<br/>Extract Text] --> B[Agent B<br/>Analyze Text] --> C[Agent C<br/>Generate Summary]
style A fill:#c8e6c9,color:#000000
style B fill:#c8e6c9,color:#000000
style C fill:#c8e6c9,color:#000000
A manager agent delegates tasks to worker agents and coordinates their outputs.
Characteristics:
Example Use Case: A research assistant where:
flowchart TD
Manager[Manager Agent<br/>Coordinates Research] --> Worker1[Worker Agent 1<br/>Academic Papers]
Manager --> Worker2[Worker Agent 2<br/>Market Data]
Manager --> Worker3[Worker Agent 3<br/>Competitor Info]
Worker1 --> Manager
Worker2 --> Manager
Worker3 --> Manager
Manager --> Synthesis[Synthesized Report]
style Manager fill:#bbdefb,stroke:#1976d2,stroke-width:3px,color:#000000
style Worker1 fill:#c8e6c9,color:#000000
style Worker2 fill:#c8e6c9,color:#000000
style Worker3 fill:#c8e6c9,color:#000000
style Synthesis fill:#fff3e0,stroke:#e65100,stroke-width:2px,color:#000000
Agents collaborate democratically to plan and execute tasks, often involving discussion and consensus-building.
Characteristics:
Example Use Case: A content creation system where multiple agents discuss and refine a marketing campaign strategy before execution.
Multiple agents work on independent tasks simultaneously.
Characteristics:
Example Use Case: A data processing system where:
flowchart TD
Start[Input Data] --> A[Agent A<br/>Process Users]
Start --> B[Agent B<br/>Process Transactions]
Start --> C[Agent C<br/>Process Logs]
A --> Combine[Combine Results]
B --> Combine
C --> Combine
style Start fill:#fff3e0,stroke:#e65100,stroke-width:2px,color:#000000
style A fill:#c8e6c9,color:#000000
style B fill:#c8e6c9,color:#000000
style C fill:#c8e6c9,color:#000000
style Combine fill:#e3f2fd,stroke:#1976d2,stroke-width:2px,color:#000000
Let’s walk through designing an Application Crew for a customer support chatbot:
Step 1: Define Your Agents
Step 2: Define Tasks
Step 3: Choose Orchestration Pattern
Step 4: Integrate with Frontend
During the AAMAD Build phase, your Development Crew will:
The Application Crew you build with CrewAI becomes the permanent intelligence running in production, while the Development Crew that built it is temporary and completes once the application is delivered.
Take a moment to reflect on these questions:
Core Components: What are the three fundamental components of CrewAI, and how do they work together to create a multi-agent system?
Crews vs Flows: Imagine you’re building a document analysis system. Would you use a Crew or a Flow? Why?
Orchestration Patterns: You’re designing a recommendation system that needs to: Analyze user preferences (Agent A), Search product catalog (Agent B), Generate personalized recommendations (Agent C). Which orchestration pattern would you choose? Why?
Application Crew Role: How does the Application Crew differ from the Development Crew in the AAMAD framework? Where does each run, and what is their purpose?
Architecture Design: Think of a simple application you’d like to build. What agents would make up your Application Crew? What tasks would each agent handle? Which orchestration pattern would you use? What would be in your Application Crew? (What agents will users interact with?) What would be in your Development Crew? (What agents will build the system?)
Continue to Module 05: Hands-On Mini-Project - Define where you’ll define your own Application Crew for the mini-project.