Communication Between Agents › The Communication Challenge
AI Agent HandbookAll chapters Communication Between Agents › The Communication ChallengeOne section · Sections in this chapter2 / 11 ↓
Let's start with a concrete problem. Imagine you have two agents:
- Agent A (Research): Finds the current price of Bitcoin
- Agent B (Analysis): Determines if now is a good time to buy
Agent B needs the information Agent A discovers. But how does Agent A send that information? And how does Agent B know it's receiving price data rather than, say, historical trends or market sentiment?
Here's what makes agent communication tricky:
Different Contexts: Each agent has its own conversation history, system prompt, and state. When Agent A says "the price is $45,000," Agent B needs enough context to understand what that means.
Timing: Agent B might need to wait for Agent A to finish its research. How does it know when Agent A is done? What if Agent A encounters an error?
Format: Should Agent A send a simple number, a structured JSON object, or a natural language description? The format affects how easily Agent B can use the information.
Reliability: What if the message gets lost or corrupted? What if Agent A sends information that Agent B doesn't understand?
Let's see these challenges in action with a simple example:
## Using Claude Sonnet 4.5 for agent communication
from anthropic import Anthropic
import json
client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
## Agent A: Research Agent
def research_agent(query):
"""
Researches information and returns findings.
"""
system_prompt = """You are a research specialist.
When asked to research something, provide factual information in a clear format.
Always structure your response as JSON with 'topic', 'findings', and 'confidence' fields."""
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=512,
system=system_prompt,
messages=[{"role": "user", "content": query}]
)
return response.content[0].text
## Agent B: Analysis Agent
def analysis_agent(research_data):
"""
Analyzes research data and provides recommendations.
"""
system_prompt = """You are an analysis specialist.
You receive research findings and provide actionable recommendations.
Focus on practical insights."""
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=512,
system=system_prompt,
messages=[{"role": "user", "content": f"Analyze this research: {research_data}"}]
)
return response.content[0].text
## Simple communication flow
research_result = research_agent("What is the current sentiment around electric vehicles?")
print(f"Research Agent found:\n{research_result}\n")
analysis_result = analysis_agent(research_result)
print(f"Analysis Agent recommends:\n{analysis_result}")Research Agent found:
```json
{
"topic": "Electric Vehicle Sentiment Analysis",
"findings": {
"overall_sentiment": "Mixed but trending positive",
"positive_factors": [
"Environmental benefits and reduced emissions",
"Lower operating costs compared to gasoline vehicles",
"Improved technology and longer range capabilities",
"Government incentives and tax credits in many regions",
"Growing charging infrastructure",
"Performance advantages (instant torque, quiet operation)"
],
"concerns": [
"Higher upfront purchase costs",
"Charging time compared to gasoline refueling",
"Range anxiety for long-distance travel",
"Charging infrastructure gaps in rural areas",
"Battery degradation over time",
"Supply chain and raw material sourcing questions",
"Grid capacity concerns with mass adoption"
],
"market_trends": [
"Sales growth continues globally despite economic headwinds",
"Traditional automakers rapidly expanding EV lineups",
"China leading in production and adoption",
"Europe showing strong policy support",
"U.S. market growing but still relatively smaller percentage of total sales"
],
"demographic_variations": [
"Younger consumers generally more enthusiastic",
"Urban residents more positive than rural",
"Early adopters satisfied, mainstream buyers more cautious",
"Business/fleet operators increasingly interested in TCO benefits"
]
},
"confidence": "High - based on consistent market data, sales trends, and consumer surveys from 2023-2024"
}
```Analysis Agent recommends: # Electric Vehicle Sentiment Analysis: Strategic Recommendations ## Executive Summary The research reveals a market at an inflection point—sentiment is positive and growing, but significant barriers remain for mainstream adoption. Success requires targeted strategies addressing specific customer segments and pain points. --- ## Priority Recommendations ### 1. **Address the Cost-Value Perception Gap** **Actions:** - **Educate on Total Cost of Ownership (TCO)**: Create calculators and comparison tools showing 5-year costs including fuel savings, maintenance, and incentives - **Flexible financing options**: Partner with financial institutions for EV-specific loans with lower rates - **Trade-in programs**: Offer premium valuations for gas vehicles to offset upfront cost concerns - **Target fleet operators first**: Their TCO focus makes them ideal early mainstream adopters—build case studies for consumer marketing **Why**: Higher upfront costs are the #1 barrier, but the math favors EVs over time. Make this transparent. --- ### 2. **Segment Your Market Strategy** **Urban vs. Rural Approach:** **Urban Markets (Priority 1):** - Emphasize convenience of home/work charging - Highlight performance and tech features - Focus on environmental benefits - Leverage existing infrastructure density **Rural Markets (Secondary Phase):** - Partner with utilities on charging infrastructure - Emphasize range improvements prominently - Consider plug-in hybrids as bridge products - Use local dealerships as charging hubs **Why**: Demographics show clear divides—allocate resources where adoption likelihood is highest first. --- ### 3. **Eliminate Range Anxiety Through Psychology & Infrastructure** **Tactical Solutions:** - **Real-world range guarantees**: Offer buy-back/exchange if customers experience genuine range limitations in first year - **Free charging packages**: Include 2-3 years of public charging credits with purchase - **Trip planning integration**: Built-in navigation showing charging stops (make it foolproof) - **Strategic infrastructure partnerships**: Work with governments/businesses to fill rural gaps on major routes **Communication Strategy:** - Lead marketing with actual range numbers in varied conditions - Show real customer testimonials about long-distance travel - Emphasize that 95% of daily driving is within easy range **Why**: Range anxiety is psychological more than practical
This works, but notice the limitations. The analysis agent receives raw text from the research agent. It has to parse that text and hope it contains the information it needs. There's no guarantee the format will be consistent, no way to verify the message was understood correctly, and no mechanism for the analysis agent to ask follow-up questions.
We can do better.