CrewAI Multi-Agents

Course Content

CrewAI Multi-Agents

9 sections · 53 lessons

How do agents communicate with each other in CrewAI?


What you need to know

Channel 1: task outputs as context

Each finished task produces a TaskOutput with .raw text and, if configured, .pydantic. When the next task runs, CrewAI adds earlier outputs to its prompt:

  • no context set → in a sequential crew, all earlier outputs are joined and passed;
  • context=[task_a] → only task_a's output;
  • context=[] → nothing.

Channel 2: delegation tools

Python
writer = Agent(role="Content Writer", goal="...", backstory="...",               allow_delegation=True)

This adds two tools:

ToolArgumentsUse
Delegate work to coworkertask, context, coworkerhand over a sub-task
Ask question to coworkerquestion, context, coworkerget one fact or opinion

The coworker string is matched against the other agents' roles, ignoring case and extra spaces. If no match is found, the tool returns an error listing valid coworkers, and the agent has to try again — one more step spent. The coworker runs a fresh task and knows nothing except what is in context.

Channel 3: shared memory and knowledge

With memory=True on the crew, outputs are saved to a shared store and relevant items are recalled before later tasks. Crew-level knowledge_sources let every agent search the same documents. This is shared background, not a conversation.

Two consequences to mention

  • Context grows down the chain. Task 5 may receive tasks 1 to 4 in full. Pass context selectively, and prefer compact structured outputs.
  • Delegation is not free. Each delegation is a full extra agent loop, and its path can change between runs.

A real-life example

A market-research crew for a consumer electronics brand has a researcher, a pricing analyst and a report writer.

In the first version, the writer's task had no context set. It received the researcher's 3,000-word raw notes and the analyst's table, about 5,000 tokens, on every one of its 6 loop steps — about 30,000 input tokens for one task. The writer also quoted raw notes the analyst had already corrected.

The fix was one line: context=[pricing_task], with the pricing task producing a Pydantic PriceTable. The writer's input dropped to about 800 tokens per step, and it could no longer quote the uncorrected notes. Delegation stayed off, because the order of work was fixed.

Follow-up questions to expect

  • "Can agents talk in both directions?" — Only through delegation: the delegating agent receives the coworker's answer as a tool result. There is no ongoing chat.
  • "What does the coworker see?" — Its own persona, the delegated task or question, and the context string the delegator wrote. Not the delegator's history.
  • "How would you pass structured data?" — Set output_pydantic on the upstream task; downstream tasks get it as JSON text, and your code can read task_output.pydantic.