Building a Smart Holiday Booking System with Agent-to-Agent Communication

 Building a Multi-Agent Holiday Booking System with the A2A Protocol (An MVP Approach)


The world of AI is rapidly moving towards "agentic systems" — autonomous AI agents that can perform complex, multi-step tasks by collaborating with each other. The challenge, however, has always been standardization: how do you get agents built on different frameworks, by different teams, to communicate effectively?

This is the problem the Agent2Agent (A2A) protocol, an open standard, aims to solve. It provides a common language for agents to discover, communicate, and collaborate securely. In this blog post, we'll walk through a Minimum Viable Product (MVP) approach to a real-world scenario: building a holiday booking system using the A2A protocol in python.

Design Architecture (MVP)




The Problem: A Siloed Booking Experience

Imagine a traditional holiday booking website. It might have separate sections for flights, hotels, and cabs. Each of these services is handled by a different internal system or a third-party API. The user, or a central piece of code, has to manually orchestrate these calls. If the flight booking fails, the entire process might fall apart, requiring a complex rollback or manual user intervention. This approach is brittle, hard to scale, and prone to errors.

The Solution: A Collaborative A2A Multi-Agent System

Our MVP approach leverages the A2A protocol to create a system of specialized, autonomous agents that can work together.

  1. Orchestrator: A user-facing service (built with FastAPI) that receives the initial request. It doesn't know how to book a flight or a hotel itself. Its only job is to break down the user's request into smaller, more manageable tasks.

  2. Specialized Agents: We create three separate, independent agents, each a microservice running on its own server:

    • Flight Booking Agent: Specializes in finding and booking flights.

    • Hotel Booking Agent: Focuses solely on hotel reservations.

    • Cab Booking Agent: Handles airport transfers and local cab services.

Each of these agents is an "A2A server" that exposes its capabilities to the world via a standardized "Agent Card."


Key Components of Our A2A MVP

Our Python implementation uses the a2a-sdk and FastAPI to create a robust and scalable MVP.

1. Agent Discovery (.well-known/agent.json)

The foundation of the A2A protocol is agent discovery. Before the orchestrator can talk to the agents, it needs to know who they are and what they can do.

In our code, this is handled manually by the SmartHolidayOrchestrator's book_holiday_package method. It performs an HTTP GET request to a standardized endpoint on each agent's server: http://localhost:5001/.well-known/agent.json




How Orchestrator will deal with the card response?

# From orchestrator.py  
cab_card_response = await http_client.get(self.agent_urls["cab"] + ".well-known/agent.json") cab_card = AgentCard.model_validate(cab_card_response.json()) cab_client = A2AClient(http_client, agent_card=cab_card)

This code fetches the agent's "business card" and uses it to create a functional A2A client, establishing the communication link without any hard-coded logic about the agent's internal workings.


2. Task-Based Communication (send_task) 

A2A is a task-oriented protocol. Instead of a simple request-response, a client sends a Task to a remote agent. A task has a lifecycle (e.g., submittedworkingcompletedfailed), allowing for multi-step or long-running operations.

In our orchestrator, we create a SendTaskRequest object for each booking:

# From orchestrator.py 
flight_task_request = SendTaskRequest(task_id=str(uuid.uuid4()), message=flight_message) flight_response = await flight_client.send_task(flight_task_request)

The send_task method ensures that the booking request is sent in a format the remote agent can understand, and it returns a Task object that contains the final response and status.


3. Concurrent Processing 

One of the major benefits of this multi-agent architecture is concurrency. Since each agent runs as a separate service, the orchestrator can delegate tasks to all of them at the same time. We use asyncio.gather to execute all three booking requests concurrently:

# From orchestrator.py 
flight_response, hotel_response, cab_response = await asyncio.gather( flight_client.send_task(flight_task_request), hotel_client.send_task(hotel_task_request), cab_client.send_task(cab_task_request), return_exceptions=True )

This parallel approach significantly speeds up the booking process and demonstrates the power of distributing a complex problem across multiple specialized agents. The return_exceptions=True argument is a crucial piece of our MVP's error handling, as it ensures that if one agent fails, the others can still complete their tasks.

Conclusion

This MVP for a holiday booking system is a simple yet powerful demonstration of the A2A protocol. It showcases how specialized agents can work together seamlessly, even without direct knowledge of each other's internals. By adopting a standardized protocol, we can build robust, scalable, and resilient systems that are far more capable than monolithic applications. This is the future of AI—a future where agents can collaborate like a well-coordinated team. 

Code sample is available in code link

 

Comments

Popular posts from this blog

SOLID Principle (Quick Read)

Design Patterns