Exercise - Integrate knowledge and actions

Completed

In this exercise, learners will enhance their declarative agent for Microsoft 365 Copilot using TypeSpec. They gain foundational skills in adding capabilities such as web content, OneDrive/SharePoint integration, Teams messages, and more, while testing and provisioning the agent to ensure proper functionality.

Task 1: Integrate web content knowledge

Goal: Add web content as a knowledge source for your declarative agent, enabling it to use Bing's search index to respond to user prompts.

  1. Open Visual Studio Code.

  2. Open the main.tsp file in your project.

  3. Add the following code snippet to include the WebSearch capability in the MyAgent namespace:

    namespace MyAgent {
      op webSearch is AgentCapabilities.WebSearch<TSites = [
        {
          url: "https://learn.microsoft.com",
        },
      ]>;
    }
    
  4. Save the file.

  5. In the Lifecycle pane of the Microsoft 365 Agents Toolkit, select Provision to apply the changes.

  6. Reload the page in the Copilot application to activate the web content capability.

A screenshot shows a response from the declarative agent that contains web content.

Note

Not specifying the TSites array causes all web content to be available to the agent.

Task 2: Add OneDrive/SharePoint integration

Goal: Enable your declarative agent to access and use OneDrive and SharePoint content as knowledge sources.

  1. Open the main.tsp file in your project.

  2. Add the following code snippet to include the OneDriveAndSharePoint capability in the MyAgent namespace. Replace the URL with a valid SharePoint site URL from your organization:

    namespace MyAgent {
      op od_sp is AgentCapabilities.OneDriveAndSharePoint<TItemsByUrl = [
        {
          url: "https://contoso.sharepoint.com/sites/ProductSupport"
        }
      ]>;
    }
    
  3. Save the file.

  4. In the Lifecycle pane of the Microsoft 365 Agents Toolkit, select Provision to apply the changes.

  5. Reload the page in the Copilot application to activate the OneDrive/SharePoint capability.

Note

  • URLs should be full path to SharePoint items (site, document library, folder, or file). You can use the "Copy direct link" option in SharePoint to get the full path or files and folders. Right-click on the file or folder and select Details. Navigate to Path and select the copy icon.
  • Not specifying the TItemsByUrl array (or the alternative TItemsBySharePointIds array) causes all OneDrive and SharePoint content in your Microsoft 365 organization that is available to the logged in user to be available to the agent.

Check your work: Add OneDrive/SharePoint integration

To validate the integration:

  1. Navigate to the Copilot application.
  2. Select your declarative agent.
  3. Ask a question that requires OneDrive or SharePoint knowledge (e.g., "What documents are available in the ProductSupport site?").
  4. Confirm that the agent provides a response based on the specified SharePoint site.

A screenshot shows a response from the declarative agent that contains SharePoint and OneDrive content.

Task 3: Incorporate Teams messages

Goal: Allow your declarative agent to use Teams messages, including channels, teams, and meeting chats, as knowledge sources.

  1. Open the main.tsp file in your project.1

  2. Add the following code snippet to include the TeamsMessages capability in the MyAgent namespace. Replace the URL with a valid Teams channel or team URL from your organization:

    namespace MyAgent {
      op teamsMessages is AgentCapabilities.TeamsMessages<TUrls = [
        {
          url: "https://teams.microsoft.com/l/team/..."
        }
      ]>;
    }
    
  3. Save the file.

  4. In the Lifecycle pane of the Microsoft 365 Agents Toolkit, select Provision to apply the changes.

  5. Reload the page in the Copilot application to activate the Teams messages capability.

Note

  • The URL in the url property must be well formed links to a Teams chat, team, or meeting chat.
  • Not specifying the TUrls array causes all Teams channels, teams, meetings, 1:1 chat, and group chats in your Microsoft 365 organization that is available to the logged in user to be available to the agent.

Check your work: Incorporate Teams messages

To validate the integration:

  1. Navigate to the Copilot application.
  2. Select your declarative agent.
  3. Ask a question that requires Teams messages knowledge (e.g., "What was discussed in the last team meeting?").
  4. Confirm that the agent provides a response based on the specified Teams messages.

A screenshot shows a response from the declarative agent that contains Teams content.

Task 4: Include email knowledge

Goal: Enable your declarative agent to use email from the user's mailbox or a shared mailbox as a knowledge source.

  1. Open the main.tsp file in your project.

  2. Add the following code snippet to include the Email capability in the MyAgent namespace:

    namespace MyAgent {
      op email is AgentCapabilities.Email<TFolders = [
        {
          folder_id: "Inbox"
        }
      ]>;
    }
    
  3. Save the file.

  4. In the Lifecycle pane of the Microsoft 365 Agents Toolkit, select Provision to apply the changes.

  5. Reload the page in the Copilot application to activate the email knowledge capability.

Note

  • This example accesses the user of the agent's mailbox. To access a shared mailbox instead, add the optional shared_mailbox property set to the email address of the shared mailbox.
  • The TFolders array limits the mailbox access to specific folders. To access the entire mailbox, omit the folders array.

Check your work: Include email knowledge

To validate the integration:

  1. Navigate to the Copilot application.
  2. Select your declarative agent.
  3. Ask a question that requires email knowledge (e.g., "What emails are in my inbox?").
  4. Confirm that the agent provides a response based on the specified email folder.

A screenshot shows a response from the declarative agent that contains email knowledge.

Task 5: Add image generator

Goal: Enable your declarative agent to generate images based on user prompts.

  1. Open the main.tsp file in your project.

  2. Add the following code snippet to include the GraphicArt capability in the MyAgent namespace:

    namespace MyAgent {
      op graphicArt is AgentCapabilities.GraphicArt;
    }
    
  3. Save the file.

  4. In the Lifecycle pane of the Microsoft 365 Agents Toolkit, select Provision to apply the changes.

  5. Reload the page in the Copilot application to activate the image generator capability.

Check your work: Add image generator

To validate the integration:

  1. Navigate to the Copilot application.
  2. Select your declarative agent.
  3. Provide a prompt to generate an image (e.g., "Create an image of a sunset over mountains.").
  4. Confirm that the agent generates an appropriate image.

A screenshot shows a response from the declarative agent that contains generated graphic art.

Task 6: Add code interpreter

Goal: Enable your declarative agent to solve complex tasks using Python code.

  1. Open the main.tsp file in your project.

  2. Add the following code snippet to include the CodeInterpreter capability in the MyAgent namespace:

    namespace MyAgent {
      op codeInterpreter is AgentCapabilities.CodeInterpreter;
    }
    
  3. Save the file.

  4. In the Lifecycle pane of the Microsoft 365 Agents Toolkit, select Provision to apply the changes.

  5. Reload the page in the Copilot application to activate the code interpreter capability.

Check your work: Add code interpreter

To validate the integration:

  1. Navigate to the Copilot application.
  2. Select your declarative agent.
  3. Provide a prompt requiring Python code execution (e.g., "Generate a graph of sales data.").
  4. Confirm that the agent generates the graph and provides the Python code used.

A screenshot shows a response from the declarative agent that contains a generated graph. A screenshot shows the Python code used to generate the requested graph.