From SharePoint to Smart Answers: Building an AI Agent in Microsoft Teams

Introduction:

In this article, I’ll walk you through how I built a fully integrated AI-powered knowledge agent that lives inside Microsoft Teams. This intelligent agent allows users to ask natural language questions directly within Teams and instantly receive summarized answers from documents stored in a SharePoint site. The solution is powered by Azure AI Search for semantic retrieval and leverages the GPT-4.1 model from Azure AI Foundry to generate concise, context-aware responses. Whether you want to streamline internal knowledge access or enhance team productivity, this approach offers a practical and scalable solution.

Overview:

The AI agent is designed to:

  • Accept user prompts within Microsoft Teams
  • Search documents stored in a SharePoint site
  • Summarize relevant content using the GPT-4-1 model from Azure Foundry

This solution includes two integration options:

  1. A Blazor Server App configured as a Teams App
  2. A Teams Bot built using the Microsoft 365 Toolkit

Both are connected to Azure AI Search and integrated with Azure Foundry.

If you use Microsoft 365 Copilot, the SharePoint agent creation comes out of the box.

Pre-Requisites:

  1. Enable Custom Apps Deployment from Org-wide app settings using the Teams admin center
  2. Azure Foundry Project – With two model deployments
    1. GPT-4.1 for chat completion
    1. text-embedding-3-small for embeddings
  3. Azure AI Search – To import and vectorize the SharePoint site data
  4. M365 Dev Toolkit–Install it in VS Code for development
  5. Bot Service Provisioning

Architecture Components

ComponentPurpose
SharePoint SiteDocument storage repository
Azure AI SearchSemantic search engine for indexing and querying SharePoint content (Dependency – It will create an Azure Logic App to schedule the file processing with SharePoint Connector to import and vectorize data)
Azure Foundry (GPT-4-0 mini)Summarization and natural language understanding
Blazor Server App (optional)Frontend application with Entra ID authentication, another option for the Teams App
Microsoft 365 ToolkitDevelopment and deployment framework for Teams Bot and Apps
Microsoft TeamsEnd-user interface and collaboration platform

Index SharePoint Documents in Azure AI Search

  • Used Azure AI Foundry to apply the text-embedding-3-small model
    • Log in to Azure AI Foundry, select your project, and deploy the text-embedding-3-small model and gpt-4.1.
    • text-embedding-3-small model converts text into numerical vectors, capturing semantic meaning and relationships between words, phrases, or sentences. It is a lightweight version optimized for efficiency.
    • gpt-4.1 is used as a chat completion model to summarize the content.
  • Indexed documents from the SharePoint library into Azure AI Search
    • Log in to the Azure portal and create an Azure AI search resource. The basic tier comes with semantic configuration.
    • Click on Import and Vectorize data, as shown in the figure below.

      Azure AI Search
    • From the next screen, select SharePoint as a data source.

      Azure AI Search SharePoint Connector
    • This data source connector indexes SharePoint documents using the Azure Logic App workflow.

      Azure AI Search Workflow
    • Note: An Additional cost will be added based on Logic App consumption
    • Next step, select your deployed text embedding model to vectorize the text

      Azure AI Search Logic App AI Model
    • The Logic Apps Managed Identity Authentication type is recommended.
    • Review and create – This will create a workflow template to process and index a document using Azure Open AI and Azure AI Search.
    • The workflow gets the document, parses the content, and chunks the text based on token size. The workflow then processes each chunk to generate embeddings through an OpenAI deployment. The text chunks and their embeddings are mapped to a schema suitable for Azure AI Search. Finally, the documents are indexed in Azure AI Search for efficient retrieval and analysis.
    • Make sure all connections are in green and click on Use this template.

      Azure AI Search - SharePoint Template
    • In the next step, provide the parameters. Enter your SharePoint site and library name.
      SharePoint Parameters
    • Finally, clicking review+update will initiate the logic app workflow to vectorize the files.
    • Note: This workflow template triggers when the Request trigger receives a request, vectorizes files from a Microsoft SharePoint Online library, and writes the files to the Azure AI Search vector store.
  • Created a semantic configuration to enable relevance scoring and natural language queries
    • After the index creation, select Indexes from the Search Management blade and select your index. Select a semantic configuration, add a semantic configuration, and configure it.

      Azure AI Search Semantic Configuration
    • Pricing – Preferred Basic Tier (Includes Semantic ranker) for Development

Build the Blazor Server App (Optional)

  • Built a Blazor Server application with Microsoft Entra ID authentication
  • Integrated Azure AI Search query functionality
  • Called the Azure Foundry GPT-4-0 mini model to summarize results
  • Displayed summarized content and original SharePoint document links in the UI
  • Please refer to the source code in the GitHub repo

Create a Bot Using the Microsoft 365 Toolkit

  • Use Visual Studio Code and the Microsoft 365 Toolkit to scaffold a Teams Bot project
    • Connect your M365 account and Azure account

      M365 Dev Toolkit
    • Note: Ensure you opened VS Code as an Admin
  • Create an Agent/App
    • Select Create new agent/app from the Development Blade as shown in the figure below

      Toolkit Create an AI Agent
    • Select Agent for Teams -> Chat with your data -> Azure AI Search -> Azure OpenAI – Select the language, I used TypeScript.

      MS Team AI Agent Connect with Azure AI Search

      Azure AI Search Scaffolding Azure Open AI scaffolding
      TypeScript Language
    • Assign the values and secret for the Azure Open AI endpoints and Azure AI Search Endpoints in the env.playground.user file. Now run the program to test the chat experience in a local browser.
  • Provisioning, Deploy, and Publish
    • Select Provision under Lifecycle Blade, using the Bicep template in the Source to create all required resources (Azure Bot and App services) in Azure.

      M365 Toolkit LifeCycle
    • Select Deploy under Lifecycle Blade. Using the Bicep template, the toolkit will create an app package and deploy it to the web app.
    • Publish to Organization. This option is used to publish the application to Teams.
AI Bot For Teams

Conclusion:

This article shows how to build an AI-powered knowledge agent inside Microsoft Teams that allows users to search and summarize SharePoint documents using natural language queries. The solution leverages Azure AI Search to index and retrieve content from a SharePoint site and uses the GPT-4.1 model from Azure AI Foundry to generate smart summaries. The bot seamlessly integrates with Teams, allowing users to interact with enterprise knowledge conversationally. This guide covers everything from indexing SharePoint content to building the Teams agent and deploying and publishing it across your organization.

Gowtham K

Gowtham K has been awarded as MVP(Most Valuable Professional) for 9 times by Microsoft for his exceptional contribution in Microsoft technologies under the category “Developer Technologies & Security” . He has more than 12 years of experience on Microsoft technologies such as C#, ASP.NET MVC, ASP.NET WEB API, ASP.NET Core, MS SQL Server, Azure, Microsoft Entra ID, Azure AD B2C and other technologies such as JavaScript, jQuery, HTML and CSS .He is also a blogger and author of articles on various technologies. He is also a speaker and delivered talk on various technologies like ASP.NET MVC, Azure and Azure DevOps in the public events.

Leave a Reply

Your email address will not be published. Required fields are marked *