Add search capabilities to a pro-code Declarative Agent

POSTED ON

Introduction

[Disclaimer] In this post I will not cover how to create a declarative agent, if you’re interested in knowing the basics you can check my previous post here.

When creating declarative agents the pro-code way, there are plenty of possibilities to customise your agents. In this post, I will cover how to add the capability of executing web searches.

The sample declarative agent I’ve created execute searches on a specific list of Microsoft’s sites.

If you’re interested in checking the sample code you can find it here.

Visual appearance

As every declarative agent we have a chat-like interface:

In the sample solution there are some suggested prompts just to ease testing it out.

Sending one of the suggested prompts will make the declarative agent search for an answer and reply to the user:

The search scopes are restricted to only a few Microsoft’ sites and, to demonstrate it, here is the list of the sources returned by the declarative agent:

Show me the code

In the declarativeAgent.json file, alongside the name, description and instructions properties, it’s also possible to define the capabilities property.

This capabilities property contains the potentialities that the agent has.

To enable the web search capability all that is needed is to simply define it as following:

"capabilities": [
{
"name": "WebSearch"
}
]

Specifying only the name with the value WebSearch, it will allow the declarative agent to search the whole web.

If it’s needed to restrict the search, like in the sample solution, it’s possible to define what are the searchable sites that you want the declarative agent to use:

 "capabilities": [
    {
        "name": "WebSearch",
        "sites": [
            {
            "url": "https://learn.microsoft.com"
            },
            {
            "url": "https://techcommunity.microsoft.com"
            },
            {
            "url": "https://azure.microsoft.com"
            },
            {
            "url": "https://www.microsoft.com"
            }
        ]
    }
]

If you’re interested in the official documentation about the WebSearch capability, you can find it here.

Conclusions

Adding a web search capability to a declarative agent created with a pro-code approach is a very easy and straightforward process, in no time you can give your agent the ability to search the internet for information.

If you’ve never created a declarative agent I suggest that you start with my previous post or navigate to the Copilot dev camp, which is a very comprehensive site with multiple ways of creating your declarative/custom engine/low-code/no-code agents.

Hope this helps!


Discover more from I am GuidoZam

Subscribe to get the latest posts sent to your email.