← Master Index
Vol. 15 Module 15.4 Lecture

CrewAI

Agent Frameworks (cross-ref Vol. 14.3)

How This Lesson Fits the Module & Volume

Vol. 14.3 CrewAI previewed crews as an alternative to RAG chains. This lecture is the Volume 15 multi-agent view: roles, tasks, sequential vs hierarchical process, tool loops per agent, memory, and HITL—mapped onto multi-agent systems and Module 15.2 memory types. Do not retake the RAG-vs-crew table from 14.3; go deeper on how crews behave as agents.

Compare with AutoGen (conversation-centric) and LangGraph (explicit graphs). CrewAI wins when humans think in job titles; graphs win when compliance needs a drawn state machine.

Learning Objectives

By the end of this lesson, students should be able to:

  • Define CrewAI agents, tasks, tools, crews, and processes in agent terms.
  • Choose sequential vs hierarchical process for a workflow.
  • Give each role a narrow tool belt (incl. MCP / semantic lookup) to limit blast radius.
  • Pass artifacts between agents instead of full transcripts (working memory).
  • Add HITL review tasks and episodic recaps after the crew finishes.
  • Know failure modes: role overlap, chatter cost, and hidden loops.
Definition

CrewAI orchestrates role-playing agents as a crew. Each agent has a role, goal, and backstory; tasks declare expected outputs; a process (sequential or hierarchical, with a manager) coordinates who works when. Each agent may run its own tool-calling loop to complete a task.

Crew Anatomy (Agent Lens)

PieceAgent meaning15.x link
Agent (role)Specialist with permissions + promptSingle-agent inside a team
TaskGoal + expected artifactPlanning unit
ToolsThat role’s allowlisted actionsMCP tools / LC tools
ProcessCoordination policyAgentic workflow
MemoryShort-term WM + optional LTMModule 15.2 types

Sequential vs Hierarchical

Sequential

  • Researcher → writer → reviewer
  • Predictable cost
  • Best for linear pipelines

Hierarchical

  • Manager delegates + critiques
  • More agency, more tokens
  • Needs tight task specs

HITL slot

  • Human as a “reviewer” task
  • Or pause before write tools
  • LangGraph if you need resume

Crew with Split Tool Belts

Vol. 14.3 showed a tiny researcher+writer crew. Here we add permissioning: only the researcher may hit semantic LTM and tickets; the writer has no write tools; a reviewer may flag HITL. That is multi-agent safety, not just roleplay flavor.

from crewai import Agent, Task, Crew, Process researcher = Agent( role="Support Researcher", goal="Gather policy + ticket facts only; no customer-facing prose", backstory="Careful analyst who cites sources and never guesses policy", tools=[policy_search, lookup_ticket, episode_lookup], # semantic + episodic + SoR verbose=True, ) writer = Agent( role="Customer Writer", goal="Draft a reply from the research brief only", backstory="Clear writer who does not invent new facts or call tools", tools=[], # no tools = smaller blast radius ) reviewer = Agent( role="Compliance Reviewer", goal="Block drafts that lack citations or promise unapproved actions", backstory="Picky reviewer; escalate to human if a write to Jira is needed", tools=[], ) t_research = Task( description="Ticket {ticket_id}: can we enable contractor SSO? Return a brief with citations.", expected_output="Markdown brief: facts, policy quotes, recommendation, open risks.", agent=researcher, ) t_write = Task( description="Turn the brief into a customer-facing reply. Do not add new claims.", expected_output="Email draft <= 200 words.", agent=writer, context=[t_research], # artifact, not full chat dump ) t_review = Task( description="Approve or reject the draft. If Jira write is required, mark HITL_REQUIRED.", expected_output="APPROVE | REJECT | HITL_REQUIRED + notes", agent=reviewer, context=[t_research, t_write], ) crew = Crew( agents=[researcher, writer, reviewer], tasks=[t_research, t_write, t_review], process=Process.sequential, memory=True, # still compact; do not treat as durable org LTM ) print(crew.kickoff(inputs={"ticket_id": "881"}))

Memory and Cost

Crew “memory” flags often mix working memory with optional vector LTM. Keep semantic policy in a dedicated index; write one episodic recap after kickoff, not every internal message. Hierarchical managers can explode token spend—budget max iterations per agent the same way you cap a LangChain loop.

Pick CrewAI when

  • Stakeholders think in roles/SOPs
  • Tasks have clear artifacts
  • You want fast multi-agent prototypes
  • Sequential pipelines dominate

Tradeoffs

  • Topology less explicit than LangGraph
  • Chatter and cost blowups
  • Vague roles → duplicated work
  • HITL resume is weaker than checkpoints
Common Misconception

“More agents always means better answers.” Three overlapping researchers will argue, retrieve the same chunks, and triple cost. Split by permission and output type (facts vs prose vs compliance), not by buzzwords. A single agent with good tools often beats a sloppy crew.

Knowledge Check

  1. Short Answer: What does a CrewAI process control? Answer: How tasks/agents are coordinated (e.g. sequential vs hierarchical).
  2. True/False: This lecture duplicates Vol. 14.3’s RAG-vs-crew intro only. Answer: False—it focuses on agent roles, tools, HITL, and memory.
  3. Multiple Choice: Passing context=[t_research] is meant to share: (a) compact artifacts, (b) GPU kernels, (c) MCP hosts. Answer: (a).
  4. Short Answer: Why give the writer no tools? Answer: Least privilege—reduce accidental writes and retrieval noise.
  5. True/False: Hierarchical process always cheaper than sequential. Answer: False—managers add tokens and loops.
  6. Multiple Choice: Durable pause/resume of a mid-crew write is stronger in: (a) LangGraph checkpoints, (b) CSS, (c) k-NN. Answer: (a).
  7. Short Answer: Where should policy text live—crew chat or semantic LTM? Answer: Semantic LTM (index/KB), retrieved on demand.
  8. True/False: More agents automatically improve quality. Answer: False.
  9. Multiple Choice: AutoGen’s metaphor vs CrewAI’s: (a) chats vs roles/tasks, (b) CNNs vs RNNs, (c) stdio vs HDMI. Answer: (a).
  10. Short Answer: Which lecture is the Volume 15 capstone on conversation-centric multi-agent + framework choice? Answer: AutoGen.

Key Takeaways

  • CrewAI = role + task + process multi-agent, each role possibly tool-looping.
  • Split tool belts; pass artifacts; cap iterations.
  • Sequential for pipelines; hierarchical only with tight specs.
  • Use LangGraph when you need inspectable HITL resume.
  • Continue with AutoGen (Vol. 15 capstone).
Trainer’s Guide

Lab: Run researcher+writer with vs without writer tools; compare hallucinated “new facts.” Add a HITL_REQUIRED path when Jira write appears.

Whiteboard: Org chart vs LangGraph topology vs AutoGen group chat. Same SSO ticket through all three.

Recap: CrewAI is role-based multi-agent with task artifacts. Continue with AutoGen.