CrewAI Multi-Agents

Course Content

CrewAI Multi-Agents

9 sections · 53 lessons

How do you pass context or outputs between tasks?


What task 5 receives when context is not setsalaryslipbankstatementIDproofpolicycheckcreditnote01234all it needsnocontext setDefault: all four earlier outputs, about 9,000 tokens per step. With context set to the policy check: about 1,200.
In a sequential crew the default is everything before me, so one missing context line can quietly multiply cost and leak uncorrected text.

What you need to know

The default is "everything before me"

This surprises many people. In a sequential crew:

context on the taskWhat it receives
not setthe 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

Python
research = Task(description="Research {company}.",                expected_output="10 facts with URLs", agent=researcher)profile = Task(description="Turn the research into a profile.",               expected_output="A CompanyProfile",               agent=analyst, context=[research],               output_pydantic=CompanyProfile)email = Task(description="Write a first email to {contact_name}.",             expected_output="An email under 120 words",             agent=writer, context=[profile])   # not the raw researchcrew.kickoff(inputs={"company": "Acme Logistics", "contact_name": "Priya"})
  • context — email sees only the clean profile.
  • Inputs — {company} and {contact_name} come from kickoff.
  • Structured output — CompanyProfile is passed as JSON text, so the writer sees clear fields.
  • Async join — if research had async_execution=True, context=[research] would make profile wait 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 context affect order?" — In a sequential crew the list order still decides; context makes 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.