| page_type | sample | ||||
|---|---|---|---|---|---|
| description | Contoso Knowledge Hub - AI Academic & Career Guidance Agent | ||||
| products |
|
||||
| languages |
|
||||
| extensions |
|
||||
| urlFragment | officedev-microsoft-teams-samples-agent-knowledge-hub-python |
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.
- 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
Uses Microsoft Teams SDK for Python (v2.0 alpha):
Appclass for bot creation and HTTP serverChatPromptfor AI-powered conversationsOpenAICompletionsAIModelfor Azure OpenAI integration- Decorator-based event handlers (
@app.on_message) - Built-in authentication support (Managed Identity, Client Credentials)
LocalStoragefor conversation state management
- Microsoft Teams is installed and you have an account
- UV version is >= 0.8.11. Install or upgrade.
- Python Version Install or upgrade min version >= 3.12.
- dev tunnel or ngrok latest version or equivalent tunnelling solution
- Microsoft 365 Agents Toolkit for VS Code or TeamsFx CLI
- Azure OpenAI in Azure AI Foundry Models resource
- AI: Create an Azure OpenAI Resource and Deploy a Model
The simplest way to run this sample in Teams is to use Microsoft 365 Agents Toolkit for Visual Studio Code.
- Ensure you have downloaded and installed Visual Studio Code
- Install the Microsoft 365 Agents Toolkit extension and Python Extension
- Select File > Open Folder in VS Code and choose this samples directory from the repo
- 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.txtas dependencies to install when creating the virtual environment. - Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps
- Select Debug > Start Debugging or F5 to run the app in a Teams web client.
- 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.
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
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.
-
Clone the repository
git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
-
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
-
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.
-
In a terminal, navigate to
samples/agent-knowledge-hub/python -
Activate your desired virtual environment
-
Update the
.envconfiguration 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
.envfile, 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
-
Install dependencies by running
pip install -r requirements.txtin the project folder. -
Update the
config.pyconfiguration 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.) -
This step is specific to Teams.
- Edit the
manifest.jsoncontained in theappManifestfolder 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 themanifest.json) - Zip up the contents of the
appManifestfolder to create amanifest.zip - Upload the
manifest.zipto Teams (in the Apps view click "Upload a custom app")
- Edit the
-
Run your bot with
python app.py
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
To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.





