From the course: Building Agents Using the Azure AI Foundry Agent Service
Grounding with Bing Search
From the course: Building Agents Using the Azure AI Foundry Agent Service
Grounding with Bing Search
- [Instructor] Our first agent was able to reply to queries using the data available in his own internal dataset. We may sometimes want our agent to get real-time information from the web or information from specific websites. This is made possible thanks to Bing Search. Bing Search provides you two tools for your agents. Grounding with Bing Search allows you to incorporate real-time public web data when generating responses. Grounding with Bing Custom Search allows you to search within a configurable set of public web domains. Let's set up Grounding with Bing Search first. We go to the Azure portal and search for Bing Resources at the search bar. We will then select Add Grounding with Bing Search. Make sure you create this Grounding with Bing Search resource in the same resource group as your Azure AI agent, AI project, and other resources. We enter a resource name and the pricing tier, and we also confirm the terms. We then click Review + create. Then, click Create. Now we set up the Grounding with Bing Custom Search. We again search for Bing Resources, select it, and this time, we select Grounding with Bing Custom Search. Again, we select the same resource group as our other resources. We enter a resource name, select a pricing tier, and we also confirm the terms. We click Review + create. Then, click create. Once the resource is created, we head over to the resource and we click Create new configuration. We enter a configuration name and we specify our web addresses. We can enter a domain. We can also enter a domain and a path, and we can also enter a webpage. For allowed domains, if you want to include subpages, you need to make sure the domains have at least two levels of subpages. We can also adjust ranks if needed. We need to make sure we save each row. We then click Create new configuration. Now let's visit the Foundry portal to integrate these assets. We go to the Management center and click on Connected resources for the project, select New connection, and choose Grounding with Bing Search. We then add connection with API key authentication. We click Back to select another asset type, select Grounding with Bing Custom Search this time, and add a connection to our resource using the same authentication method. We then click Close. We need to jot down these connection names in a notepad because we'll need to refer this in our code. We then head over back to our project. Now it's time to create an agent using these resources with the portal. We head over to the Agents page, create a new agent, and you click Try in the playground. We provide two sample queries. You can see that the agent doesn't know the answer. Now let's provide the agent some basic instructions. Then, under Knowledge, we click Add, we first select Bing Search, select our resource, then click Next. We have optional parameters we can set. Count refers to the number of search results to return. Set language is set for the language setting. Market is where the results come from. And Freshness filters results by age. To learn more about these parameters, you can find more information in the Microsoft Learn page. We accept the defaults for now and click Connect. We do the same steps with custom search. We click again, Add knowledge, select Bing Custom Search, select our resource, click Next. We then choose our configuration. We again accept the default parameters. Click Next. And we then choose our configuration and click Connect. Now let's ask the same queries. In these two instances, you can see responses and citations from Bing Search. Now let's try Bing Custom Search. You can see that the response comes from one of the web pages we provided in the custom configuration. Let's create the agent this time using Python. We import the needed libraries for the tools. We create a project client. And more importantly, we get our connection IDs for both tools. We need to enter here the connection names for each tool, and you can get this in the Connections page in the Foundry portal. We also need to specify the configuration name for the custom search tool we created in the Azure portal. We run the cell and we create the corresponding Bing grounding tools. We then create our agent by adding the tool definitions of each tool in the tools parameter. We then create a thread, which will contain all our messages. And you create our helper function to run the agent. In this helper function, we add optional code to display the run_steps in more detail. We run the agent to see the results. We can see the agent use the Bing Grounding tool in the first query and the Bing Custom Search in the second query. And we can now delete the agent after. Let's now explore file search tool to see how agents can get data from specific internal files.