CrewAI Multi-Agents

Course Content

CrewAI Multi-Agents

9 sections · 53 lessons

How do agents collaborate to solve a single complex task?


One flood claim through the review crewIntakereturnsClaimFactsPolicy check:covered,clause, deductibleFraud scan:risk leveland signalsWriter readsall threetyped outputsPolicy and fraud both read only the claim facts, so they can run in parallel.
Collaboration is decided at the handoffs: a typed deductible field cannot be paraphrased into 'fully covered'.

What you need to know

Agents in CrewAI do not share a brain. They share text that the framework passes between them. There are three ways that text moves:

  1. Task context. Task(context=[a, b]) puts the outputs of tasks a and b into this task's prompt. In a sequential crew, a task with no context set receives the outputs of all earlier tasks, which is simple but can make prompts long; setting context narrows it.
  2. Delegation. An agent with allow_delegation=True gets two tools: Delegate work to coworker and Ask question to coworker. It can hand a sub-task to a teammate mid-task. This is flexible but adds hidden LLM calls.
  3. Shared memory and knowledge. Crew memory and knowledge_sources let agents recall facts. This is useful background, but it is retrieval, so it can miss or return stale facts. Never rely on it for facts a task must receive.

Why the schema matters most

When the handoff is free text, information gets lost quietly. The analyst writes "the claim looks mostly fine", and the next agent cannot tell which document was checked. With a schema, a missing field is a validation error you can see.

Python
from pydantic import BaseModelfrom crewai import Taskclass PolicyCheck(BaseModel):    covered: bool    clause: str            # e.g. "4.2(b) Water damage"    deductible_inr: intclass FraudSignals(BaseModel):    risk: str              # "low" | "medium" | "high"    signals: list[str]intake = Task(description="Extract claim facts from {claim_pdf}",              expected_output="Claim facts", agent=intake_agent,              output_pydantic=ClaimFacts)policy = Task(description="Check the claim against the policy wording",              expected_output="Coverage decision with clause", agent=policy_agent,              context=[intake], output_pydantic=PolicyCheck)fraud  = Task(description="Look for fraud signals in the claim facts",              expected_output="Risk level and signals", agent=fraud_agent,              context=[intake], output_pydantic=FraudSignals)summary = Task(description="Write the adjuster summary and recommendation",               expected_output="Half-page summary", agent=writer,               context=[intake, policy, fraud])

policy and fraud both read only the claim facts, not each other. The writer reads all three. Each agent sees only what it needs, which keeps prompts short and makes it easy to see which agent went wrong.

A real-life example

An insurer's claims-review crew handles motor and home claims. A home-flood claim for ₹3.8 lakh arrives with 14 photos and a repair estimate.

  • The intake agent extracts date, address, amount and items.
  • The policy agent finds clause 4.2(b) and a ₹10,000 deductible.
  • The fraud agent notices the repair shop appears in 9 other claims this month and marks risk "medium".
  • The writer produces a summary for the human adjuster: covered, deductible applies, check the repair shop.

Before the team added schemas, the policy agent's free-text answer sometimes said "covered subject to conditions", and the writer turned that into "fully covered". After output_pydantic, the writer receives covered=True, clause="4.2(b)", deductible_inr=10000 and cannot lose the deductible.

Follow-up questions to expect

  • "Why not one hierarchical task and let the manager figure it out?" — Less code, but the manager decides the order and wording of each sub-task at runtime, so failures are hard to reproduce. I use it only when the sub-tasks really cannot be known in advance.
  • "How does an agent ask another agent a question?" — With allow_delegation=True it gets the Ask question to coworker tool and names the coworker by role. Keep it on only for the agent that needs it.
  • "Can two tasks run at the same time?" — Yes, async_execution=True on independent tasks (like policy and fraud above), joined by a later task's context.