Chapter 1 · Multi-Agent Systems and CrewAI Overview
Chapter goals: Understand "why one Agent is not enough," master CrewAI's five core concepts (Agent / Task / Crew / Process / Flow), and learn the Crew vs Flow decision framework to build a global mental map before writing code.
1.1 Why You Need "Multiple" Agents
A single LLM call excels at answering questions, but real-world business is often a pipeline: research → analyze → write → review. Having one model handle everything in a single conversation hits three classic problems:
- Context pollution: role confusion. When the model plays both researcher and reviewer simultaneously, prompts conflict with each other and output quality drops;
- Tool overload: stuffing search, scraping, database, and file I/O into a single agent significantly increases tool-selection errors;
- Uncontrollable execution paths: a single agent's step order is left to the model's discretion, making the workflow un-auditable and unreproducible.
The multi-agent approach decomposes the pipeline into multiple agents with single responsibilities, each with its own role definition, toolset, and task — with the framework handling their collaboration. This is like a company that wouldn't let the same person both write code and conduct financial audits: specialized division of labor + clear interfaces is the foundation of production LLM applications.
Difference from "chained calls"
You can hand-write llm1(prompt) → llm2(llm1_out) as a function chain, but CrewAI adds on top of that: role memory, inter-task context passing, delegated collaboration, retry and rate-limiting, token accounting, replay, and more runtime capabilities. This is exactly where the framework's value lies.
1.2 CrewAI Core Concept Map
CrewAI's world consists of five core components. Remember this relationship diagram:
┌─────────────────────────────────────────────────┐
│ Flow (event-driven precise orchestration layer, optional) │
│ └── Orchestrates one or more Crews / functions │
│ ┌─────────────────────────────────────┐ │
│ │ Crew (team: one complete execution unit) │ │
│ │ ├── Process (collaboration mode: │ │
│ │ │ sequential / hierarchical) │ │
│ │ ├── Agent × N (role-based members) │ │
│ │ └── Task × N (task list, bound to agents) │ │
│ └─────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘| Component | Role | One-sentence summary |
|---|---|---|
| Agent | Autonomous worker | An "employee" with role/goal/backstory, optionally with tools |
| Task | Specific work item | A "work order" with description and expected_output, bound to an agent |
| Crew | Team | One complete execution formed by agents + tasks + process |
| Process | Collaboration mode | How tasks flow: sequential execution or hierarchical delegation |
| Flow | Precise orchestration | Connects multiple crews and plain functions via events (@start/@listen) |
Data flow: a Task's output is automatically passed to the next Task as context by default; you can also explicitly declare dependencies with context=[...]. After the entire Crew completes, it returns a CrewOutput object.
Translating this map into a code skeleton, five components take their positions (just get familiar — each will be expanded in subsequent chapters):
from crewai import Agent, Task, Crew, Process, LLM
llm = LLM(model="openai/deepseek-chat",
base_url="https://api.deepseek.com/v1",
api_key="sk-xxx")
agent = Agent(role="Researcher", goal="Summarize key points", backstory="10 years research experience", llm=llm)
task = Task(description="Research a topic", expected_output="5 key points", agent=agent)
crew = Crew(agents=[agent], tasks=[task], process=Process.sequential)
# Flow syntax appears in Chapter 15, using @start / @listen decorators to orchestrate multiple crews1.3 Crews vs Flows: Official Decision Framework
This is the most common point of confusion for beginners. CrewAI's official decision criteria are clear:
Choose Crews when you need "collaborative intelligence":
- Multiple agents with different specialties need to work together;
- The solution cannot be pre-written as deterministic steps (agents need to decide what to do next);
- Typical scenarios: deep research, creative content production, brainstorming.
Choose Flows when you need "precise control":
- Workflow requires strict execution order and state management;
- Deterministic event orchestration, conditional routing, and breakpoint recovery are needed;
- Typical scenarios: ETL pipelines, approval flows, multi-stage batch processing.
Combining both is the norm: use Flow for top-level control and state management, and call Crews at key stages for tasks requiring creativity. For example, a content factory: Flow manages the three phases "topic selection → production → publishing," and the "production" phase internally is a Crew of researcher + writer + editor.
Chapter 15–16 cover Flow systematically; the first 14 chapters focus on Crews.
1.4 Same Requirement, Two Approaches: With vs Without Framework
Requirement: have the model list key points first, then write a short essay from those points.
Hand-written chained call version:
# Raw function chain: works, but you manage everything yourself
import os
from openai import OpenAI
client = OpenAI(api_key=os.getenv("DEEPSEEK_API_KEY"),
base_url="https://api.deepseek.com/v1")
def chat(prompt):
resp = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": prompt}],
)
return resp.choices[0].message.content
points = chat("List 5 core key points about AI Agents")
article = chat(f"Expand the following points into a 300-word essay:\n{points}")This code runs, but retry, rate-limiting, token accounting, task replay, role memory, multi-agent delegation... you build everything from scratch. The same requirement expressed with CrewAI (complete runnable version in Chapter 2):
# CrewAI version: framework handles the execution loop, context passing, and accounting
from crewai import Agent, Task, Crew
researcher = Agent(role="Researcher", goal="Produce 5 key points",
backstory="Industry research expert", llm=llm)
writer = Agent(role="Writer", goal="Expand into a short essay",
backstory="Tech column author", llm=llm)
crew = Crew(
agents=[researcher, writer],
tasks=[
Task(description="List 5 key points", expected_output="numbered list", agent=researcher),
Task(description="Expand into a 300-word essay", expected_output="Markdown article", agent=writer),
],
)
result = crew.kickoff() # Automatically completes two calls and context passing1.5 Typical Application Scenarios
- Research & intelligence: competitor monitoring weekly report — searcher finds materials, analyst distills insights, reporter writes summary;
- Content marketing: keyword-to-article SEO pipeline (full capstone in Chapter 23);
- Data analysis: natural language to SQL → validation → result interpretation multi-agent review chain (Chapter 24 capstone);
- Customer support tickets: classification → knowledge base retrieval → draft response → compliance review;
- Code engineering support: requirements analysis → solution design → code generation → test review.
Common characteristics: multiple roles, multiple steps, inspectable intermediate artifacts. If your scenario is simply "ask one question, get one answer," calling the LLM API directly is sufficient — no need for multi-agent.
1.6 Learning Path and Environment Preview
This tutorial is based on CrewAI 1.15.x (requiring Python >=3.10 and <3.14). It unfolds in four stages:
| Stage | Chapters | Goal |
|---|---|---|
| Getting Started | 01–05 | Core concepts, first working Crew, parameter deep dive |
| Intermediate | 06–12 | Third-party model integration, tooling system, hierarchical process, memory & knowledge bases |
| Advanced | 13–19 | Planning & fault tolerance, event callbacks, Flow workflows, engineering project structure |
| Production Practice | 20–25 | Evaluation testing, MCP, observability, deployment, capstone projects |
Per course conventions, all examples uniformly use OpenAI-compatible third-party models (using DeepSeek as the example), without depending on the OpenAI official API:
import os
from crewai import LLM
# Unified model integration pattern throughout the book: openai/ prefix + custom base_url
llm = LLM(
model="openai/deepseek-chat", # provider/model format
base_url="https://api.deepseek.com/v1", # third-party OpenAI-compatible endpoint
api_key=os.getenv("DEEPSEEK_API_KEY"), # credentials always via env var
temperature=0.7,
)1.7 Chapter Summary
- Three pain points of single agents: role confusion, tool overload, uncontrollable paths; multi-agent solves these through specialized division of labor;
- Five components: Agent (worker), Task (work order), Crew (team), Process (collaboration mode), Flow (precise orchestration layer);
- Crews suit open-ended problems requiring collaborative intelligence; Flows suit deterministic processes requiring precise control; complex applications combine both;
- CrewAI 1.x requires Python >=3.10 and ❤️.14; this book uniformly uses
LLM(model="openai/deepseek-chat", base_url=...)for third-party model integration.
🧪 随堂测验
点击你认为正确的选项。答错时会展示正确答案与原因解析。
1. In CrewAI, which component defines "how tasks flow (sequential or hierarchical)"?
2. According to the official decision framework, which scenario is best suited for Flow over Crew?
3. Regarding the book's unified third-party model integration pattern, which is correct?
4. What is CrewAI 1.x's Python version requirement?
🛠️ Hands-On Exercises
- Describe in one paragraph an automated workflow at work that could be split into 3 roles, and draft each agent's role/goal/backstory.
- Draw a variant of the diagram in Section 1.2: suppose you're building a "daily news briefing" system — mark which parts use Crew and which use Flow.
- Check your local Python version (
python3 --version), confirm it meets CrewAI requirements; if not, record the version management plan you'll use (e.g., uv / pyenv).
The conceptual map is built. Next, set up the environment and run your first Crew.