Skip to content

add m365 extension and sample - #558

Open
Lily Du (lilyydu) wants to merge 6 commits into
mainfrom
lilyydu/m365extensions-package
Open

add m365 extension and sample#558
Lily Du (lilyydu) wants to merge 6 commits into
mainfrom
lilyydu/m365extensions-package

Conversation

@lilyydu

@lilyydu Lily Du (lilyydu) commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a new microsoft-teams-m365extensions package — an M365 extension that lets you run the
Teams SDK for Python (teams.py) inside an existing M365 Agents
app. It installs middleware that routes Teams activities to a teams.py App, while
every 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.py App and installs the routing middleware.
  • TeamsMiddleware / is_teams_channel — the middleware and a channel-detection helper.
  • Credential/token wiring so teams.py's outbound calls reuse the host app's existing credentials.
  • Unit tests (tests/test_m365extensions.py).

Example — examples/m365extensions/

  • A runnable sample demonstrating Teams-only features (help card, reactions, quoted replies,
    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 the
    non-Teams path.
  • README.md + sample.env with Teams CLI-based setup.

How it works

For each Teams turn, the middleware checks whether the teams.py App has a matching route. If it
does, 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:
Screenshot 2026-08-12 at 1 40 23 PM

Direct Line/Webchat:
Screenshot 2026-08-12 at 1 41 03 PM

Copilot AI lite review requested due to automatic review settings August 12, 2026 18:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 implementing use_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.

Comment thread packages/m365extensions/src/microsoft_teams/m365extensions/middleware.py Outdated
Comment thread examples/m365extensions/tools/webchat/serve.py Outdated
Comment thread packages/m365extensions/tests/test_m365extensions.py
Lily Du (lilyydu) and others added 5 commits August 12, 2026 11:48
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants