Skip to content

Instantly share code, notes, and snippets.

@garrytrinder
Created March 11, 2025 14:53
Show Gist options
  • Save garrytrinder/9bbbcb32c0da447d00b25efe09816f00 to your computer and use it in GitHub Desktop.
Save garrytrinder/9bbbcb32c0da447d00b25efe09816f00 to your computer and use it in GitHub Desktop.
Challenge project - Build a declarative agent to chat with your docs

Introduction

Use declarative agents to extend Microsoft 365 Copilot. You define custom knowledge to create agents that can answer questions using authoritative content.

Example scenario

Suppose you work in a customer support team. You and your team handle queries about products that your organization makes from customers. You want to improve response times and provide a better experience. You store documents in a document library on a SharePoint Online site that contains product specifications, frequently asked questions, and policies for handling repairs, returns, and warranties. You want to be able to use natural language to query information in these documents and get answers quickly to customer queries.

What will we be doing?

Here, you create a declarative agent which can answer product support questions using information stored in documents in Microsoft 365:

Screenshot of Microsoft Edge showing Microsoft 365 Copilot. The Product support declarative agent is displayed in the immersive experience.

What is the main goal?

By the end of this module, you'll demonstrate your ability to create a declarative agent for Microsoft 365 Copilot that can answer questions using information from documents.

Prepare

You'll be building a declarative agent for Microsoft 365 Copilot that's grounded in your documents. Here, we discuss the project business logic and target behavior. We also cover the accounts and software you'll need.

Project specification

The declarative agent:

  • is available within Microsoft 365 Copilot
  • provides examples of how users can ask it questions
  • answers a user's questions using the information from the referenced documents
  • in the answer, includes a reference to the relevant document
  • politely refuses answering questions not related to its function
  • admits when it doesn't have relevant information to answer a user's question

Setup

To complete this challenge, you need a Microsoft 365 tenant with the Microsoft 365 Copilot license, Visual Studio Code and the Teams Toolkit extension.

Get a Microsoft 365 tenant with the Microsoft 365 Copilot license

To complete this exercise, you need a Microsoft 365 tenant with the Microsoft 365 Copilot license. You access Microsoft 365 Copilot through the Microsoft 365 tenant. You need the Microsoft 365 Copilot license to get access to semantic index and be able to ground agents in work documents.

Upload sample documents

Here we provide sample documents for you to use in the challenge. The documents contain product specifications and frequently asked questions about specific Contoso Electronics products. Upload them to your OneDrive or an existing SharePoint site so that they're available for use in the declarative agent you'll build.

Important

Upload the files to OneDrive or an existing SharePoint site so that they're immediately available for you to use. If you choose to use a new SharePoint Online site, the documents will take longer to be indexed and available for use by Copilot.

Install Visual Studio Code

You'll build the agent using Visual Studio Code. Visual Studio Code is an IDE that provides you with tooling to build agents for Microsoft 365 Copilot. To install Visual Studio Code for your operating system, visit https://code.visualstudio.com/.

Install Teams Toolkit extension for Visual Studio Code

Teams Toolkit is a Visual Studio Code extension that helps developers build agents for Microsoft 365 Copilot. It provides you with the project boilerplate and tasks to automate building and deploying agents. To install the Teams Toolkit extension for Visual Studio Code visit https://marketplace.visualstudio.com/items?itemName=TeamsDevApp.ms-teams-vscode-extension.

To get started, use the Teams Toolkit to create a new app with the declarative agent without an action template.

Exercise - Start building your declarative agent

The customer support teams needs an agent that answers their questions using information from documents stored in Microsoft 365. Here, you start building a declarative agent. You'll validate how it's working against requirements to check your work.

Specification

The declarative agent:

  • is available within Microsoft 365 Copilot
  • provides examples of how users can ask it questions
  • politely refuses answering questions not related to its function

Check your work

At this point, you have a declarative agent with custom instructions and examples of questions that the users might ask. The agent is visible in Microsoft 365 Copilot chat.

  1. Navigate to Microsoft 365 Copilot chat. Is your agent visible?
  2. In Microsoft 365 Copilot chat, navigate to the agent. Does it show examples of the questions that a user might ask?
  3. Ask a question not related to Contoso products. Does the agent politely refuse to answer it?

Exercise - Add grounding data

The customer support teams needs an agent that answers their questions using information from documents stored in Microsoft 365. Here, you extend your declarative agent and ground it in your documents. You'll validate how it's working against requirements to check your work.

Specification

The declarative agent:

  • answers a user's questions using the information from the referenced documents
  • in the answer, includes a reference to the relevant document
  • politely refuses answering questions not related to its function
  • admits when it doesn't have relevant information to answer a user's question

Check your work

At this point, you have a fully functional declarative agent grounded in work documents. The agent answers questions about products using the information from the referenced documents

  1. Navigate to your agent. Ask it a question about one of the products from the referenced documents. Does the agent answer using the information from the document?
  2. Does the answer include a reference to the document?
  3. Is the reference pointing to the correct document?
  4. Ask another question, this time about something that's not in the referenced documents. Does the agent admit that it doesn't have the information to answer the question?
  5. Ask a question not related to Contoso products. Does the agent politely refuse to answer it?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment