Module 8 Lesson 5: Communication Patterns
How agents share data. Understanding context passing, memory sharing, and the 'Kitchen' environment in CrewAI.
Communication Patterns: Sharing the Context
When multiple agents work together, the biggest risk is "Information Loss." If the Researcher finds 10 facts but the Writer only receives 3 of them, the system has failed.
In CrewAI, communication is handled through Context and Shared Memory.
1. Automated Context Passing
By default, when Task B follows Task 1, Task B receives the Final String Output of Task 1.
The Challenge: What if Task B needs the output of Task 1 AND Task 2?
The Solution: Use the context parameter in the Task definition.
# Task 3 now gets the results from BOTH 1 and 2 automatically.
task3 = Task(
description='Summarize all findings.',
context=[task1, task2],
agent=manager
)
2. Shared Memory (The Kitchen)
CrewAI has a built-in memory system that allows agents to share "Insights" in real-time.
- Short-Term Memory: Agents share their current task progress.
- Long-Term Memory: Agents can store results in a local database to use in future executions of the crew.
3. Communication Verbosity
When debugging multi-agent systems, you need to see the "Conversation."
verbose=True: Shows the agent's internal monologue.step_callback: Allows you to send every action to a dashboard or Slack for monitoring.
4. Visualizing the Data Flow
graph TD
T1[Researcher Output] -->|String| T2[Analyst Input]
T1 -.->|Memory Store| T3
T2 -->|String + Context| T3[Writer Input]
T3 -->|Final Result| User
5. The "Human-Friendly" Protocol
Because agents communicate in Natural Language, they sometimes "over-explain" things to each other.
- The Problem: Agent A sends a 5-page report to Agent B. Agent B hits its token limit and crashes.
- The Fix: Use Structured Output (Pydantic). Instead of sending a report, Agent A sends a
ReportMetaDataobject. Agent B then knows exactly where to look for the information without reading 5 pages of fluff.
Key Takeaways
- Context Passing is the backbone of multi-agent synergy.
- The
contextparameter allows for non-linear data gathering. - Shared Memory helps agents learn across different tasks and sessions.
- Structured Output is the best way to prevent "Token Bloat" during agent-to-agent communication.