This repository contains the code reference for building a multi-agent system that demonstrates seamless collaboration between agents built with Microsoft Semantic Kernel and communicating via Google Agent-to-Agent (A2A) protocol.
The project showcases a practical example: a Trip Management System where a Travel Planner Agent orchestrates a Flight Booking Agent to assist users with their travel needs.
- Multi-Agent Collaboration: See how independent agents can work together using a common communication protocol.
- Microsoft Semantic Kernel Integration: Agents are built leveraging Semantic Kernel's powerful capabilities for AI orchestration and tool use.
- Google A2A Protocol: Demonstrates how to set up A2A servers and clients for robust agent-to-agent communication.
- Modular Design: Each agent is independent, with its own toolset and runtime, promoting scalability and maintainability.
- Stateful Interactions: Agents maintain context for multi-turn conversations using
context_id.
This project is divided into two main parts:
- A2A Agent Server (
flight-booking-agent): Hosts theFlight Booking Agent. - A2A Client (
travel-planner-agent): Hosts theTravel Planner Agentwhich acts as the orchestrator and consumes theFlight Booking Agentas a tool.
The core components and their roles are detailed in the accompanying blog post.
.
├── flight_booking_agent_server/
│ ├── __main__.py # A2A Server implementation for Flight Booking Agent
│ └── flight_booking_agent.py # Defines the SemanticKernelFlightBookingAgent
├── travel_planner_agent_client/
│ ├── travel_agent.py # A2A Client implementation for Travel Planner Agent
│ └── flight_booking_tool.py # Semantic Kernel tool to interact with Flight Booking Agent
├── requirements.txt # Project dependencies
└── README.md # You are here!
Before you begin, ensure you have the following:
- Python 3.9+
- An Azure OpenAI Service deployment with a chat completion model (e.g.,
gpt-35-turbo,gpt-4). You'll need the API key, endpoint, and deployment name. uvicorn(for running the A2A server).
-
Clone the repository:
git clone https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git cd YOUR_REPO_NAME -
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Configure API Keys:
-
Navigate to
flight_booking_agent_server/flight_booking_agent.pyand replace placeholders with your Azure OpenAI credentials:api_key="<api_key>", endpoint="https://<endpoint>.openai.azure.com", deployment_name="<deployment_name>",
-
Navigate to
travel_planner_agent_client/travel_agent.pyand replace placeholders with your Azure OpenAI credentials:api_key="<your-api-key>", endpoint="https://<your-endpoint>.openai.azure.com", deployment_name="<your-deployment-name>",
-
Note: For production environments, consider using environment variables to manage sensitive API keys securely.
-
To see the multi-agent system in action, you'll need to run the A2A server and client in separate terminals.
-
Start the Flight Booking Agent (A2A Server): Open your first terminal, navigate to the project root, and run:
cd flight_booking_agent_server python __main__.pyYou should see output indicating the server is starting on
http://0.0.0.0:9999. -
Start the Travel Planner Agent (A2A Client): Open a second terminal, navigate to the project root, and run:
cd travel_planner_agent_client python travel_agent.pyThis will start the
Travel Planner Agent, which will then be ready to communicate. You can interact with it via its chat interface.
When you interact with the Travel Planner Agent (the A2A client), it will intelligently determine if a user query requires flight booking assistance. If it does, it will:
- Invoke its internal
FlightBookingTool. - The
FlightBookingToolwill act as an A2A client, fetching theAgentCardfrom theFlight Booking Agent(A2A server). - It will then send a
SendMessageRequestto theFlight Booking Agentwith the user's flight booking request. - The
Flight Booking Agentprocesses the request and sends back a response, which theTravel Planner Agentthen relays back to the user.
Both agents maintain their own conversational context based on a context_id, demonstrating stateful interactions within this multi-agent setup.
- Microsoft Semantic Kernel Documentation: https://learn.microsoft.com/en-us/semantic-kernel/
- Google Agent-to-Agent (A2A) Documentation: https://developers.google.com/agents/docs/a2a
- My Blog Post: [https://www.google.com/search?q=YOUR_BLOG_POST_LINK_HERE] (Highly recommended for a detailed explanation of the steps!)
Contributions are welcome! If you have suggestions or improvements, please open an issue or submit a pull request.