From the course: Hands-On AI: Building AI Agents with Model Context Protocol (MCP) and Agent2Agent (A2A)

Execute the multi-agent HR App with A2A

- [Instructor] Having created the code for the multi-agent router and the a2a servers, let's now run the multi-agent system and experience it in action. To do this, we need to first run the timeoff_db_server. Please recollect that the timeoff agent uses this MCP server in HTTP mode on port 8,000. We can run this by running the Python file in a dedicated terminal. Then we need to run the a2a server for the policy agent. We can start it in a similar fashion. This starts the server in port 9,001. Next, we need to run the a2a server for the timeoff agent. This starts the server in port 9,002. Finally, we get to run the a2a client router agent file. This will create the router agent. Then it will go through the list of file tasks or queries. It can take some time to complete. The first query is, tell me about payroll processing. The router chooses the destination as unsupported. This is because the router agent only has policies and timeoff functions. The next question is, what is the policy for remote work? The destination chosen is POLICY. This invokes the policy node in the router. The policy node then calls the a2a client. The client first retrieves the agent card at port 9,001. It then prints the agent URL for the policy. Since the agent card is served by the a2a server itself, this URL is same as the agent card. Next, it prompts the agent using the user query. After some time, we receive the response from the agent. This is printed as the agent output. Let's now switch to the policy a2a servers logs, and see what happens there for this request from the client. We see the first request is for .well-known/agent.json. This is the request received for the agent card. Next, it creates the agent and prompts the agent with the user query. It then proceeds to contact the MCP server, load the tools, prompt, and then invoke the policy agent to answer the question back to the client router agent. The next question is, what is my vacation balance? The destination now is chosen as TIMEOFF. This then results in invoking the timeoff node in the router agent. The timeoff agent calls the a2a client. This client then proceeds to get the agent card from port 9,002. It proceeds to execute the query on the a2a server, get the response, and returns to the router agent. If we look at the logs for the time of a2a server, we see similar log messages as the policy a2a server. On the client router agent, the next two requests for filling a timeoff request and querying a balance, again, are also executed with the timeoff a2a server. This example illustrates how the a2a protocol is used for multi-agent communications. It also shows how MCP can be used along with a2a to build multi-agent systems.

Contents