add m365 extension and sample - #558
Open
Lily Du (lilyydu) wants to merge 6 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new microsoft-teams-m365extensions package that bridges a Microsoft Agents SDK AgentApplication with a teams.py App via middleware routing, plus an end-to-end sample showing Teams-only features alongside pass-through handling for non-Teams channels.
Changes:
- Added a new
packages/m365extensions/package implementinguse_teams_sdk(...),TeamsMiddleware,is_teams_channel(...), and token/credential wiring for reuse of the host app’s auth. - Added unit tests for core helpers/guards and updated diagnostics to exempt the new bridge package from Agents SDK import restrictions.
- Added a runnable
examples/m365extensions/sample, including a small Direct Line/Web Chat harness for validating non-Teams pass-through behavior.
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Adds the new example and package workspace members and their resolved dependencies. |
| pyrightconfig.json | Adds m365extensions package + example roots to type checking configuration. |
| pyproject.toml | Registers microsoft-teams-m365extensions as a workspace dependency. |
| packages/m365extensions/tests/test_m365extensions.py | New unit tests for channel detection, token projection, and use_teams_sdk kwarg guards. |
| packages/m365extensions/src/microsoft_teams/m365extensions/token.py | Implements TeamsToken (TokenProtocol) synthesized from an Agents SDK Activity. |
| packages/m365extensions/src/microsoft_teams/m365extensions/middleware.py | Implements TeamsMiddleware routing Teams activities to teams.py with fallthrough behavior. |
| packages/m365extensions/src/microsoft_teams/m365extensions/install.py | Implements use_teams_sdk(...) to wire credentials and install middleware. |
| packages/m365extensions/src/microsoft_teams/m365extensions/credentials.py | Implements token-provider callback that reuses the Agents SDK connection manager. |
| packages/m365extensions/src/microsoft_teams/m365extensions/context.py | Adds ContextVar to flow the Agents SDK TurnContext to credential selection. |
| packages/m365extensions/src/microsoft_teams/m365extensions/init.py | Exposes the public API surface of the new package. |
| packages/m365extensions/README.md | Adds package README and links/badges. |
| packages/m365extensions/pyproject.toml | Defines the new distributable package metadata and dependencies. |
| packages/apps/tests/test_apps_diagnostics.py | Exempts m365extensions from the “don’t depend on Agents SDK” guard. |
| examples/m365extensions/tools/webchat/serve.py | Adds a minimal local server that exchanges a Direct Line secret for a short-lived token. |
| examples/m365extensions/tools/webchat/README.md | Documents Web Chat harness setup and usage. |
| examples/m365extensions/tools/webchat/index.html | Adds a simple Web Chat UI consuming the local token endpoint. |
| examples/m365extensions/src/main.py | New sample demonstrating teams.py routes + Agents SDK fallthrough routes and auth scenarios. |
| examples/m365extensions/src/cards.py | New sample Adaptive Card helpers for help/task-module flows. |
| examples/m365extensions/sample.env | Provides env var template for local running and optional auth demo. |
| examples/m365extensions/README.md | Documents sample behavior, setup, commands, and multi-channel validation. |
| examples/m365extensions/pyproject.toml | Defines the sample app dependencies and workspace sources. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…r selection Address Copilot review feedback that the bridge's core behavior wasn't exercised: add tests for TeamsMiddleware routing/short-circuiting, plugin propagation into process_activity, and token-provider selection by turn identity. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Kavin (singhk97)
approved these changes
Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
microsoft-teams-m365extensionspackage — an M365 extension that lets you run theTeams SDK for Python (teams.py) inside an existing M365 Agents
app. It installs middleware that routes Teams activities to a teams.py
App, whileevery other channel — and any Teams turn with no matching teams.py route — falls through to the host
app's existing handlers. This lets you layer rich Teams-native features (Adaptive Cards, task
modules, reactions, targeted messages) onto an app without rewriting its current message handling.
What's included
Package —
packages/m365extensions/use_teams_sdk(...)— one-call setup that builds the teams.pyAppand installs the routing middleware.TeamsMiddleware/is_teams_channel— the middleware and a channel-detection helper.tests/test_m365extensions.py).Example —
examples/m365extensions/targeted messages, task modules) alongside pass-through commands handled by the host app.
tools/webchat/— a small Direct Line harness (browser UI + scriptable CLI) for exercising thenon-Teams path.
README.md+sample.envwith Teams CLI-based setup.How it works
For each Teams turn, the middleware checks whether the teams.py
Apphas a matching route. If itdoes, teams.py handles the turn and its response flows back through the host pipeline. If not — or
for any non-Teams channel — the turn passes through unchanged to the host app.
Example snippets
Outlook:

Direct Line/Webchat:
