If you’ve been wanting to try the M365 Agent SDK, but didn’t know where to start, this guide is for you. We’re going to set up everything from scratch using VS Code, use the official Python Cards sample, run it locally, create a dev tunnel, and finally test it in Web Chat. I’m using Visual Studio Code (VS Code) for the setup, but the steps are the same on any machine with Python installed
Step 1: Set Up Your Development Environment
I am using VS Code, so you don’t need to manually install Python on your system (unless you want to).
VS Code can handle Python via extensions which makes it super easy and everything at once place.
You can download complete sample : here
Install These Extensions in VS Code
Open VS Code → Extensions → install:
- Python (Microsoft)
- Dev Tunnels (optional but helpful)
- GitHub Pull Requests & Issues ( Saves a lot of Download time)
These ensure:
- You can run Python files directly inside VS Code
- IntelliSense / linting works
- Dev tunnel commands work in the integrated terminal
Step 2: Download/Clone the Official Sample
I am using this exact sample: Agent SDK Python Cards
Run these commands inside VS Code Terminal:
git clone https://github.com/microsoft/Agents.git cd Agents/samples/python/cards
You now have the complete working Python Agent sample.
Step 3: Install All Required Packages
Inside the cards folder, run:
pip install -r requirements.txt
This installs:
- FastAPI
- Uvicorn
- Agents SDK
- dotenv
VS Code will automatically detect and configure a Python interpreter for you. Once done, your requirements.txt file will look like :
Step 4: Add Your M365 Agent Configuration
Inside the folder, you’ll see:
.env.TEMPLATE
Rename it to:
.env
Then open the file and fill in:
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID=
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET=
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID=
Here I am creating a single tenant bot, hence I am suing these settings for MSI it will be different
You can refer the different type of available authentication types here
Python -m src.main
Where do these values come from?
Your Azure portal -> App Registration/ Managed Identity ( Depending on what type of application is created)
Step 5: Run the M365 Agent Locally
Start your Agent:
Python -m src.main
You will see :
But you will not be able to test the bot here locally, so we would need additional tools to help us test locally.
Step 6: Create a Dev Tunnel
You must expose your local bot over HTTPS.
For that we use devtunnel.
Step 6.1 — Authenticate devtunnel
You must authenticate first or you’ll get:
Unauthorized tunnel creation access
So run:
devtunnel user login
A browser pops up -> Sign in with the same Microsoft account used for your M365 Agent.
Step 6.2 — Create the Tunnel
Now run:
devtunnel host -p 3978 --allow-anonymous
You will get a public HTTPS URL like:
Copy this URL and we can test the bot in Azure bot service
Step 7: Update the M365 Agent Endpoint in Portal
Go to your Azure portal → ABS Agent → Settings → Endpoint URL
Paste: <tunnel-url>/api/messages
Click Save.
At this point:
- Your Agent is running locally
- Your tunnel is publishing it
- You will be able to can talk to your Agent
Step 8: Test the Agent (The Fun Part)
Go to your Azure bot service → Test in Web Chat.
Type:
hello
You should get back the card responses from the sample.
If the sample sends Adaptive Cards or text messages, you will see them appear here exactly as coded.
That's It! You Built Your First Python M365 Agent
This guide took you from:
✔ VS Code setup
✔ Python environment extensions
✔ Cloning the sample
✔ Adding env configuration
✔ Running the Agent
✔ Creating a dev tunnel
✔ Testing in Web Chat