Course Content
CrewAI Multi-Agents
9 sections · 53 lessons
How do agents collaborate to solve a single complex task?
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:
- Task
context.Task(context=[a, b])puts the outputs of tasksaandbinto this task's prompt. In a sequential crew, a task with nocontextset receives the outputs of all earlier tasks, which is simple but can make prompts long; settingcontextnarrows it. - Delegation. An agent with
allow_delegation=Truegets 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. - Shared memory and knowledge. Crew memory and
knowledge_sourceslet 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.
1from pydantic import BaseModel2from crewai import Task34class PolicyCheck(BaseModel):5 covered: bool6 clause: str # e.g. "4.2(b) Water damage"7 deductible_inr: int89class FraudSignals(BaseModel):10 risk: str # "low" | "medium" | "high"11 signals: list[str]1213intake = Task(description="Extract claim facts from {claim_pdf}",14 expected_output="Claim facts", agent=intake_agent,15 output_pydantic=ClaimFacts)16policy = Task(description="Check the claim against the policy wording",17 expected_output="Coverage decision with clause", agent=policy_agent,18 context=[intake], output_pydantic=PolicyCheck)19fraud = Task(description="Look for fraud signals in the claim facts",20 expected_output="Risk level and signals", agent=fraud_agent,21 context=[intake], output_pydantic=FraudSignals)22summary = Task(description="Write the adjuster summary and recommendation",23 expected_output="Half-page summary", agent=writer,24 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=Trueit 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=Trueon independent tasks (likepolicyandfraudabove), joined by a later task'scontext.