From the course: Hands-On AI: Building AI Agents with Model Context Protocol (MCP) and Agent2Agent (A2A)
Build the HR Timeoff Agent with MCP Client
From the course: Hands-On AI: Building AI Agents with Model Context Protocol (MCP) and Agent2Agent (A2A)
Build the HR Timeoff Agent with MCP Client
- [Instructor] Now, let's proceed to build the time off agent. The code for this agent is in the timeoff_agent.py file in the chapter4 folder. Most of this code is similar to the HR policy agent that we built in the previous chapter. We begin by first setting up the Azure Chat OpenAI model for use with the agent. We use the environment variables to identify the required parameters. Please use your own instance of an LLM when trying out this exercise. Next, we proceed to define the time off agent asynchronous function. This takes a username and a user query as inputs. The MCP server in this case is using a streamable HTTP interface. Unlike the previous example where we used stdio, we need to run the MCP server first as a service exposing a HTTP URL and port. We identify that URL for the MCP server in the client. Now, we proceed to connect to the server. We use streamable HTTP client interface for this purpose and initialize the connection. The server is already running, so this merely opens a live connection to that server. Then we get the list of tools. We then get a prompt that is updated with the user and the query. We print those. Once a connection is established, these steps are similar to our previous example. We then create a React agent with the tools. We use the prompt to initiate the agent. The agent will then use the tools available to create the response. The response is then returned back from the function. In the main loop, we send a sequence of three queries to the agent. First, we request the time off balance for Alice. Then we file a new time off request for Alice for five days. Then we again query for the time off balance to see if the balance has been updated correctly. This should be updated based on our previous time off request. These three queries simulate how a real user behavior would be when this is deployed in production. Let's execute this system in the next video and see the results.