Course Content
CrewAI Multi-Agents
9 sections · 53 lessons
How do you pass context or outputs between tasks?
What you need to know
The default is "everything before me"
This surprises many people. In a sequential crew:
context on the task | What it receives |
|---|---|
| not set | the raw output of all earlier tasks, joined |
context=[research] | only research's output |
context=[] | no earlier outputs |
So task 5 with no context receives tasks 1 to 4 in full, on every step of its loop.
The four mechanisms
1research = Task(description="Research {company}.",2 expected_output="10 facts with URLs", agent=researcher)3profile = Task(description="Turn the research into a profile.",4 expected_output="A CompanyProfile",5 agent=analyst, context=[research],6 output_pydantic=CompanyProfile)7email = Task(description="Write a first email to {contact_name}.",8 expected_output="An email under 120 words",9 agent=writer, context=[profile]) # not the raw research1011crew.kickoff(inputs={"company": "Acme Logistics", "contact_name": "Priya"})context—emailsees only the clean profile.- Inputs —
{company}and{contact_name}come fromkickoff. - Structured output —
CompanyProfileis passed as JSON text, so the writer sees clear fields. - Async join — if
researchhadasync_execution=True,context=[research]would makeprofilewait for it.
Passing data in a Flow
In a Flow, each step writes to self.state, and later steps read it. A common pattern: a crew step stores result.pydantic in state, and the next step passes selected fields as inputs to another crew. This gives you full control over what each crew sees.
A real-life example
A loan-document review crew has five tasks: extract salary slip, extract bank statement, extract ID, check policy, write summary. The summary task had no context, so it received all four earlier outputs — about 9,000 tokens, including raw OCR text — on each of its 5 steps. It sometimes quoted OCR errors ("Rs 8,50,00" instead of "Rs 85,000") that the policy task had already corrected.
The fix: the policy task outputs a PolicyResult model, and the summary task uses context=[policy_task]. The summary's input fell to about 1,200 tokens per step, cost per file dropped by about 40%, and OCR errors stopped leaking into credit notes.
Follow-up questions to expect
- "What is the difference between context and memory?" — Context is explicit and exact for this run; memory is retrieved by similarity, may include older runs, and is not guaranteed to surface a given fact.
- "Does
contextaffect order?" — In a sequential crew the list order still decides;contextmakes a task wait for async tasks it depends on, but it cannot point to a task that comes later. - "How do I pass a value only code knows, like a user ID?" — Use
kickoff(inputs=...), or in a Flow keep it in state and pass it when calling the crew.