An educational demonstration of Google's Agent-to-Agent (A2A) protocol v1 through a multi-agent storytelling system. Three AI agents collaborate iteratively to adapt and enhance stories, showcasing real-world A2A communication patterns.
π Educational Purpose: This project is designed to teach the A2A protocol through hands-on exploration. Not intended for production use.
This demo teaches A2A protocol concepts through working code:
- β A2A Message Envelopes - Standardized communication format
- β
Conversation Threading - Tracking related messages with
conversation_id - β
Message Chains - Linking requests and responses with
in_reply_to - β Agent Identity - How agents identify themselves
- β
Agent Cards - Discovery endpoint at
/.well-known/agent.json - β Task States - Official A2A lifecycle (SUBMITTED β WORKING β COMPLETED)
- β Message Parts - Typed content (TextPart, DataPart, FilePart)
- β Multi-Agent Orchestration - Coordinating multiple agents
- β Message Audit Trail - Logging and debugging agent communication
- β Iterative Workflows - Building feedback loops between agents
What this is: A learning tool demonstrating A2A protocol implementation What this isn't: A production-ready storytelling application
# Clone the repository
git clone https://github.com/rdondeti/A2A-StoryLab.git
cd A2A-StoryLab
# 1. Prerequisites
# - Python 3.9+
# - Ollama with gemma3:1b model
# Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh
ollama serve
ollama pull gemma3:1b
# 2. Setup Python environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
# 3. Start all services
./start_all.sh
# 4. Verify services are running
curl http://localhost:8000/health
# 5. Stop services when done
./stop_all.shServices running:
- π― Orchestrator: http://localhost:8000
- βοΈ Creator Agent: http://localhost:8001
- π Critic Agent: http://localhost:8002
- π§ Ollama LLM: http://localhost:11434
Send a story adaptation request:
curl -X POST http://localhost:8000/adapt-story \
-H "Content-Type: application/json" \
-d '{
"base_story_id": "bear_loses_roar",
"variation_request": "scientist who lost his formulas"
}'Watch what happens: The system demonstrates A2A protocol as agents collaborate through multiple iterations.
This demo implements a three-agent system using A2A protocol for all communication:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER REQUEST β
β "Adapt story as scientist who lost formulas" β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββ
β ORCHESTRATOR (Port 8000) β
β Coordinates the workflow β
β Demonstrates: Agent coordination β
ββββββββ¬ββββββββββββββββββββββ¬βββββββββββββ
β β
β A2A Messages β A2A Messages
βΌ βΌ
ββββββββββββββββ ββββββββββββββββ
β CREATOR β β CRITIC β
β (Port 8001) β β (Port 8002) β
β β β β
β Demonstrates:β β Demonstrates:β
β β’ Requests β β β’ Responses β
β β’ Refinement β β β’ Feedback β
ββββββββ¬ββββββββ ββββββββ¬ββββββββ
β β
βββββββββββ¬ββββββββββββ
βΌ
ββββββββββββββββ
β OLLAMA LLM β
β (Port 11434) β
ββββββββββββββββ
| Agent | Port | Educational Purpose |
|---|---|---|
| Orchestrator | 8000 | Demonstrates workflow coordination and multi-agent management |
| Creator | 8001 | Shows request handling and iterative refinement patterns |
| Critic | 8002 | Illustrates response generation and feedback provision |
| Ollama | 11434 | LLM backend (not part of A2A - just provides AI capability) |
This is what you'll see in the logs (logs/a2a_messages.log):
conversation_id: "conv_abc123" β Links all messages in this workflow
β
ββ msg_001: Orchestrator β Creator (remix_story)
β ββ msg_002: Creator β Orchestrator (story v1.0)
β ββ msg_003: Orchestrator β Critic (evaluate_story)
β ββ msg_004: Critic β Orchestrator (score: 6.5/10)
β
ββ msg_005: Orchestrator β Creator (refine_story) β in_reply_to: msg_004
β ββ msg_006: Creator β Orchestrator (story v2.0)
β ββ msg_007: Orchestrator β Critic (evaluate_story)
β ββ msg_008: Critic β Orchestrator (score: 8.5/10 β)
β
ββ Complete: 8 messages demonstrate full A2A protocol features
Key Learning Points:
- Every message has unique
message_id - All messages share same
conversation_id - Responses link back via
in_reply_to - Complete audit trail for debugging
1. Watch the message audit trail:
# Start services
./start_all.sh
# In another terminal, watch A2A messages in real-time
tail -f logs/a2a_messages.log
# In another terminal, make a request
curl -X POST http://localhost:8000/adapt-story \
-H "Content-Type: application/json" \
-d '{"base_story_id": "bear_loses_roar", "variation_request": "test"}'You'll see every A2A message logged with:
- Message ID
- Conversation ID
- Sender/Recipient
- Timestamp
- Message type
2. Run the test suite:
# See 190+ tests demonstrating A2A patterns
pytest tests/ -v
# Focus on A2A protocol tests
pytest tests/ -k "a2a" -v
# See A2A compliance tests
pytest tests/ -k "compliance" -v3. Test individual components:
# Health checks (all agents respond)
curl http://localhost:8000/health
curl http://localhost:8001/health
curl http://localhost:8002/health
# Discover agent capabilities via Agent Card
curl http://localhost:8001/.well-known/agent.jsonExercise 1: Trace a Conversation
# Make a request and note the session_id in response
curl -X POST http://localhost:8000/adapt-story ...
# Search logs for that conversation
grep "conv_SESSION_ID" logs/a2a_messages.log
# Count messages
grep "conv_SESSION_ID" logs/a2a_messages.log | wc -lExercise 2: Examine Message Structure
# View A2A message examples in the code
cat src/common/a2a_utils.py | grep -A 20 "def create_request_message"
cat src/common/a2a_utils.py | grep -A 20 "def create_response_message"Exercise 3: Modify and Experiment
- Change quality threshold in
src/orchestrator/main.py(line ~60) - Add logging in
src/common/a2a_utils.py - Observe how agents communicate through breakpoints
Google's A2A protocol provides a standard way for AI agents to communicate, similar to how HTTP standardizes web requests.
Why standardize agent communication?
- π Traceability - Debug conversations by following message IDs
- π§΅ Threading - Group related messages together
- π Chaining - Link requests to responses
- π€ Interoperability - Any A2A-compliant agent can communicate
- π Auditability - Complete logs for analysis
Every agent communication uses this structure:
{
"protocol": "google.a2a.v1", // β Protocol version
"message_id": "msg_abc123xyz789", // β Unique ID for THIS message
"conversation_id": "conv_session_001", // β Groups related messages
"timestamp": "2025-10-29T10:30:45Z", // β When sent
"sender": { // β Who's sending
"agent_id": "orchestrator-001",
"agent_type": "orchestrator",
"instance": "http://localhost:8000"
},
"recipient": { // β Who should receive
"agent_id": "creator-agent-001",
"agent_type": "creator",
"instance": "http://localhost:8001"
},
"message_type": "request", // β request/response/error
"in_reply_to": null, // β Links to parent message
"payload": { // β Your actual data
"action": "remix_story",
"parameters": {
"story_id": "bear_loses_roar",
"variation": "scientist who lost formulas"
}
}
}1. Message Envelope
- Wraps your data in standardized metadata
- Like addressing a letter: envelope (A2A) contains letter (your data)
2. Conversation Threading
conversation_idgroups related messages- Like email threads - keeps everything together
3. Message Chains
in_reply_tolinks responses to requests- Trace causality: "This response answers that request"
4. Agent Identity
- Each agent has unique ID, type, and location
- Clear accountability: who said what
5. Message Types
- REQUEST: Ask another agent to do something
- RESPONSE: Return results
- ERROR: Report problems
- HEALTH_CHECK: Verify agent is alive
See A2A in code:
src/common/a2a_utils.py- Complete A2A utilities (550+ lines)src/common/conversation_manager.py- Tracks conversations (450+ lines)tests/test_a2a_compliance.py- Protocol validation testslogs/a2a_messages.log- Live message audit trail
Learn more:
- A2A Protocol Guide - Complete implementation guide
- Testing Guide - Testing patterns and examples
Once services are running, explore the auto-generated API docs:
- Orchestrator: http://localhost:8000/docs
- Creator Agent: http://localhost:8001/docs
- Critic Agent: http://localhost:8002/docs
User-Facing Endpoint (simplified - for demo ease):
POST http://localhost:8000/adapt-story
{
"base_story_id": "bear_loses_roar",
"variation_request": "developer who lost motivation"
}Behind the Scenes (A2A messages):
- Orchestrator sends A2A REQUEST to Creator
- Creator sends A2A RESPONSE with story
- Orchestrator sends A2A REQUEST to Critic
- Critic sends A2A RESPONSE with evaluation
- Loop continues until quality threshold met
| Story ID | Theme |
|---|---|
squirrel_and_owl |
Seeking wisdom |
bear_loses_roar |
Inner strength |
turtle_wants_to_fly |
Appreciating uniqueness |
lonely_firefly |
Finding community |
rabbit_and_carrot |
Discovery |
This system demonstrates a complete A2A workflow:
1. User Request β System receives story adaptation request
2. Orchestrator (Coordinator)
- Creates unique
conversation_id - Sends A2A REQUEST to Creator agent
3. Creator (Worker Agent)
- Receives A2A REQUEST
- Generates story
- Sends A2A RESPONSE back
4. Orchestrator β Critic
- Receives Creator's story
- Sends A2A REQUEST to Critic agent
5. Critic (Evaluator Agent)
- Receives A2A REQUEST
- Evaluates story (score 0-10)
- Sends A2A RESPONSE with feedback
6. Iteration Decision
- If score < 8.0: Return to step 2 with feedback
- If score β₯ 8.0: Complete
7. Result β Return final story to user
The Critic evaluates on 4 dimensions to demonstrate iterative improvement:
| Dimension | Weight | Purpose in Demo |
|---|---|---|
| Moral Preservation | 30% | Shows validation logic |
| Structure Quality | 25% | Demonstrates scoring |
| Creativity | 25% | Illustrates subjective evaluation |
| Coherence | 20% | Tests consistency checking |
Threshold: 8.0/10 | Max Iterations: 5
A2A-StoryLab/
βββ src/
β βββ common/
β β βββ a2a_utils.py # β Core A2A implementation
β β βββ conversation_manager.py # β Conversation tracking
β β βββ models.py # Data models
β β βββ ollama_client.py # LLM integration
β βββ orchestrator/main.py # Coordinator agent
β βββ creator_agent/main.py # Worker agent example
β βββ critic_agent/main.py # Evaluator agent example
βββ tests/
β βββ test_a2a_utils.py # β A2A protocol tests
β βββ test_conversation_manager.py
β βββ test_integration_a2a.py # β End-to-end A2A tests
βββ docs/
β βββ A2A_PROTOCOL_GUIDE.md # β Complete A2A guide
β βββ ARCHITECTURE_AND_USER_GUIDE.md
βββ logs/
β βββ a2a_messages.log # β View all A2A messages here
βββ requirements.txt # Python dependencies
βββ start_all.sh # Start all services
βββ stop_all.sh # Stop all services
βββ README.md # You are here
β = Essential for learning A2A protocol
Start here:
- A2A Protocol Guide - Complete tutorial
- Architecture Guide - System design
- Testing Guide - Test patterns and examples
Key files to study:
src/common/a2a_utils.py- All A2A utilitiessrc/orchestrator/main.py- Coordinator patterntests/test_a2a_compliance.py- Protocol validationlogs/a2a_messages.log- Real message examples
| Component | Technology | Educational Purpose |
|---|---|---|
| Protocol | Google A2A v1 | β Main learning focus |
| Language | Python 3.9+ | Clear, readable implementation |
| Framework | FastAPI | Modern async Python, auto-docs |
| LLM | Ollama (gemma3:1b) | Local, no API keys needed |
| Testing | pytest | 190+ tests show proper usage |
Services won't start:
# Check if ports are in use
lsof -ti:8000 8001 8002 11434 | xargs kill -9Ollama not responding:
# Check Ollama status
curl http://localhost:11434/api/tags
# Start if needed
ollama serve
# Pull model
ollama pull gemma3:1bCan't see A2A messages:
# Ensure logs directory exists
mkdir -p logs
# Check file permissions
ls -la logs/
# Watch in real-time
tail -f logs/a2a_messages.log- Start: Run the system, make requests, watch logs
- Explore: Read
src/common/a2a_utils.py - Experiment: Modify code, add logging, test changes
- Study: Review test files to see proper A2A usage
- Build: Try creating a new agent type
We welcome contributions that help others learn:
- π Improved documentation
- π Tutorial additions
- π§ͺ More test examples
- π‘ Better code comments
- π Bug fixes
See CONTRIBUTING.md for guidelines.
Purpose: Educational A2A Protocol Demonstration
Metrics:
- π ~4,000 lines of Python code
- π§ͺ 190+ tests demonstrating proper A2A usage
- π Comprehensive documentation and examples
- π§ Core A2A protocol features (Agent Cards, Task States, Message Parts)
- β Focus: Teaching, not production
Note: This is an educational implementation focusing on core A2A concepts. For full protocol compliance (JSON-RPC 2.0, streaming, push notifications), see the official A2A specification.
MIT License - See LICENSE file.
TL;DR: Free to use for learning and teaching. Modify as needed for educational purposes.
- Base Stories: SimpleMCP project
- A2A Protocol: Google A2A Protocol Specification
- LLM Backend: Ollama for local inference
- π Issues: Report bugs or problems
- π¬ Discussions: Ask questions about A2A protocol
- π Documentation: See docs/ directory
Built to Teach Google's A2A Protocol Through Working Code
Learn by doing - explore, experiment, understand