From Zero to A2A Compliant Agent in 72 Hours
When I received the Stage 3 task for HNG Internship - "Build and Integrate AI Agents" - I knew I wanted to create something that combined my passion for space exploration with modern chat platform integration. The result? NASA Space Explorer, an A2A compliant agent that brings the wonders of the universe directly to Telex.im chat.
๐ The Vision
Space has always fascinated me. The daily Astronomy Picture of the Day (APOD) from NASA has been part of my morning routine for years. What if I could make this experience more accessible, right within the chat platform my team uses daily? That's how NASA Space Explorer was born.
๐ ๏ธ Technical Architecture
Choosing the Stack
As a Python developer, I opted for FastAPI - it's perfect for building robust APIs quickly. The key requirements were:
A2A protocol compliance
NASA APOD API integration
Telex.im compatibility
Error handling and fallbacks
The A2A Protocol Challenge
The A2A (Agent-to-Agent) protocol uses JSON-RPC 2.0, which sounded straightforward until I saw Telex's actual message structure. The complexity was in the nested data arrays containing conversation history.
Key Insight: Telex sends the entire conversation context, not just the current message. My agent needed to intelligently extract the most recent user command from this historical data.
NASA API Integration
NASA's APOD API is fantastic but has rate limits. I implemented:
Caching: 1-hour cache to avoid repeated API calls
Timeout handling: 8-second timeout with graceful fallbacks
Multiple image sources: Primary API + fallback images
๐ก The Breakthrough Moment
The biggest challenge was command detection. Initially, my agent was confused by previous bot responses in the conversation history. The solution? Reverse chronological parsing - looking for the most recent user command while filtering out bot responses.
def extract_user_message_simple(params):
# Look for user commands in reverse order (most recent first)
for text in reversed(all_texts):
if not is_bot_response(text):
command = detect_command(text)
if command:
return command
๐ฏ Key Features Implemented
1. Robust Command Detection
Handles variations: "today", "today's image", "random fact", etc.
Filters out bot responses and previous messages
Graceful fallback to default command
2. Comprehensive Error Handling
NASA API timeout management
Network failure fallbacks
Invalid response validation
3. User-Friendly Responses
Clear, clickable image URLs
Informative space facts
Helpful command guidance
๐งช Testing and Iteration
The integration process involved constant testing:
- Local testing with simulated A2A requests
- Telex integration and real-world usage
- Log analysis using Telex's agent logs endpoint
- User feedback from team members
The most valuable debugging tool was Telex's agent logs at https://api.telex.im/agent-logs/{channel-id}.txt - they provided complete visibility into the request-response cycle.
๐ Results and Impact
After deployment, the agent successfully:
โ Processes natural language commands
โ Returns beautiful astronomy images with descriptions
โ Provides educational space facts
โ Handles errors gracefully
โ Integrates seamlessly with Telex.im
Team response has been fantastic! My colleagues now start their day with space images and facts, bringing a bit of cosmic wonder to our daily standups.
๐ Lessons Learned
- Protocols matter: Understanding A2A/JSON-RPC 2.0 was crucial.
- Real data beats assumptions: Telex's actual message structure was more complex than expected
- Error handling is feature: Users appreciate graceful degradation
Simple is better: Clear, clickable URLs often work better than complex embedding
๐ฎ Future Enhancements
Image search by date ("show me image from 2020-01-15")
Space news integration
Multiple language support
Interactive image exploration
๐ Acknowledgments
This project was built for HNG Internship Stage 3. Special thanks to:
Telex.im for the amazing platform and A2A protocol
NASA for the incredible APOD API
HNG Internship for the challenging and educational task
The experience taught me that building useful AI agents isn't just about the algorithms - it's about creating seamless, delightful user experiences that integrate naturally into people's workflows.
The cosmos is now just a chat message away! ๐
Want to build your own? Check out the GitHub repository and start exploring!
Top comments (0)