Skip to content

Latest commit

 

History

History

README.md

page_type sample
description Contoso Knowledge Hub - AI Academic & Career Guidance Agent
products
office-teams
office
office-365
languages
Python
extensions
contentType createdDate
samples
10/21/2025 01:38:25 PM
urlFragment officedev-microsoft-teams-samples-agent-knowledge-hub-python

Contoso Knowledge Hub - AI Academic & Career Guidance Agent

This sample demonstrates an AI-powered Academic Agent built with the Microsoft Teams SDK for Python. The bot provides comprehensive educational support, career guidance, and course recommendations using Azure OpenAI.

Interaction with App

Contoso knowledge Hub

Included Features

  • Teams SDK - Microsoft Teams SDK for Python (microsoft.teams.*)
  • Azure OpenAI Integration - GPT-powered responses with Azure OpenAI
  • Prompt Management - Structured prompts system with instructions
  • Educational Agent - Academic guidance and course recommendations

Architecture

Uses Microsoft Teams SDK for Python (v2.0 alpha):

  • App class for bot creation and HTTP server
  • ChatPrompt for AI-powered conversations
  • OpenAICompletionsAIModel for Azure OpenAI integration
  • Decorator-based event handlers (@app.on_message)
  • Built-in authentication support (Managed Identity, Client Credentials)
  • LocalStorage for conversation state management

Prerequisites

Run the app (Using Microsoft 365 Agents Toolkit for Visual Studio Code)

The simplest way to run this sample in Teams is to use Microsoft 365 Agents Toolkit for Visual Studio Code.

  1. Ensure you have downloaded and installed Visual Studio Code
  2. Install the Microsoft 365 Agents Toolkit extension and Python Extension
  3. Select File > Open Folder in VS Code and choose this samples directory from the repo
  4. Press CTRL+Shift+P to open the command box and enter Python: Create Environment to create and activate your desired virtual environment. Remember to select requirements.txt as dependencies to install when creating the virtual environment.
  5. Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps
  6. Select Debug > Start Debugging or F5 to run the app in a Teams web client.
  7. In the browser that launches, select the Add button to install the app to Teams.

If you do not have permission to upload custom apps (uploading), Microsoft 365 Agents Toolkit will recommend creating and using a Microsoft 365 Developer Program account - a free program to get your own dev environment sandbox that includes Teams.

Setup for bot

In Azure portal, create a Azure Bot resource. - For bot handle, make up a name. - Select "Use existing app registration" (Create the app registration in Microsoft Entra ID beforehand.) - If you don't have an Azure account create an Azure free account here

In the new Azure Bot resource in the Portal, - Ensure that you've enabled the Teams Channel - In Settings/Configuration/Messaging endpoint, enter the current https URL you were given by running the tunneling application. Append it with the path /api/messages

Run the app (Manually Uploading to Teams)

Setup for code

Note these instructions are for running the sample on your local machine, the tunnelling solution is required because the Teams service needs to call into the bot.

  1. Clone the repository

    git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
  2. Run ngrok - point to port 3978

    ngrok http 3978 --host-header="localhost:3978"

    Alternatively, you can also use the dev tunnels. Please follow Create and host a dev tunnel and host the tunnel with anonymous user access command as shown below:

    devtunnel host -p 3978 --allow-anonymous
  3. Register a new application in the Microsoft Entra ID – App Registrations portal.

A) Select New Registration and on the register an application page, set following values: * Set name to your app name. * Choose the supported account types (any account type will work) * Leave Redirect URI empty. * Choose Register. B) On the overview page, copy and save the Application (client) ID, Directory (tenant) ID. You'll need those later when updating your Teams application manifest and in the appsettings.json. C) Navigate to API Permissions, and make sure to add the following permissions: Select Add a permission * Select Add a permission * Select Microsoft Graph -> Delegated permissions. * User.Read (enabled by default) * Click on Add permissions. Please make sure to grant the admin consent for the required permissions.

  1. In a terminal, navigate to samples/agent-knowledge-hub/python

  2. Activate your desired virtual environment

  3. Update the .env configuration for the agent to use the Microsoft App Id and App Password from the app registration. (Note the App Password is referred to as the "client secret" in the azure portal and you can always create a new client secret anytime.)

  • In the .env file, set:
    • MicrosoftAppId=<your-microsoft-app-id>
    • MicrosoftAppPassword=<your-app-password>
    • MicrosoftAppType=<MultiTenant|SingleTenant|UserAssignedMSI> (MultiTenant is default)
  • Also configure your Azure OpenAI settings:
    • AZURE_OPENAI_API_KEY=<your-azure-openai-key>
    • AZURE_OPENAI_ENDPOINT=<your-azure-openai-endpoint>
    • AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o-mini
  1. Install dependencies by running pip install -r requirements.txt in the project folder.

  2. Update the config.py configuration for the bot to use the Microsoft App Id and App Password from the Bot Framework registration. (Note the App Password is referred to as the "client secret" in the azure portal and you can always create a new client secret anytime.)

  3. This step is specific to Teams.

    • Edit the manifest.json contained in the appManifest folder to replace your Microsoft App Id (that was created when you registered your bot earlier) everywhere you see the place holder string ${{BOT_ID}} and ${{TEAMS_APP_ID}} (depending on the scenario the Microsoft App Id may occur multiple times in the manifest.json)
    • Zip up the contents of the appManifest folder to create a manifest.zip
    • Upload the manifest.zip to Teams (in the Apps view click "Upload a custom app")
  4. Run your bot with python app.py

Running the sample

Using Teams AI SDK for Python:

The bot responds to user messages with AI-generated educational guidance, course recommendations, and career advice based on the instructions in prompts/chat/instructions.txt.

Key Features:

  • AI-powered responses using Azure OpenAI (gpt-4o-mini)
  • Educational support and course recommendations
  • Career guidance and skills assessment
  • Feedback mechanism with thumbs up/down buttons
  • Automatic "AI generated" indicator on responses

Screenshots

  • App Installation: App Installation

  • Personal Chat - AI Guidance: Personal Chat

  • AI Response with Feedback: AI Response

  • Agent Recommendations: Course Recommendations

  • Agent Recommendations: Group Chat

Deploy the agent to Azure

To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.

Further reading