Skip to content

Python: Add Teams SDK end-to-end sample - #6676

Closed
Mehak Bindra (MehakBindra) wants to merge 9 commits into
microsoft:mainfrom
MehakBindra:feature/teams-sdk-sample
Closed

Python: Add Teams SDK end-to-end sample#6676
Mehak Bindra (MehakBindra) wants to merge 9 commits into
microsoft:mainfrom
MehakBindra:feature/teams-sdk-sample

Conversation

@MehakBindra

@MehakBindra Mehak Bindra (MehakBindra) commented Jun 22, 2026

Copy link
Copy Markdown
Member

Motivation & Context

This PR adds a Teams SDK end-to-end sample to demonstrate that Agent Framework agents work seamlessly across different hosting platforms. It mirrors the existing m365-agent sample but uses the Microsoft Teams SDK (teams.py) for hosting instead of the M365 Agents SDK, showing developers they can deploy agents in Teams without requiring Copilot Studio or M365 infrastructure.

Description & Review Guide

  • What are the major changes?

New sample at python/samples/05-end-to-end/teams-agent/ with:
app.py: Complete Teams bot implementation with streaming responses, multi-turn memory, feedback, and suggested actions
README.md: Setup and testing instructions
.env.example: Configuration template for Azure OpenAI and Teams bot credentials

  • What is the impact of these changes?

Provides Teams developers a clear starting point for building AI agents in Teams
Demonstrates agent streaming, SessionState management, and Teams UI integration (feedback buttons, suggested actions)
Follows the same PEP 723 single-file sample pattern as other 05-end-to-end examples

  • What do you want reviewers to focus on?

Sample clarity and completeness for a Teams developer audience
Alignment with repo sample conventions (no extra workspace deps, proper docstrings, error handling)
README accuracy for local dev + Teams testing flow

Related Issue

This is a new example addition without a related issue.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings June 22, 2026 23:33
@moonbox3 Evan Mattson (moonbox3) added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Jun 22, 2026
@github-actions github-actions Bot changed the title Add Teams SDK end-to-end sample Python: Add Teams SDK end-to-end sample Jun 22, 2026

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

Adds a new Python end-to-end sample that hosts an Agent Framework “weather” agent as a Microsoft Teams bot using the Teams SDK (teams.py), demonstrating streaming responses and multi-turn session memory in a Teams chat surface.

Changes:

  • Introduces a new Teams bot sample (teams-agent) implemented as a PEP 723 single-file script.
  • Adds setup/run documentation and a configuration template for local testing via dev tunnels.
  • Demonstrates Teams UI affordances (suggested actions, AI-generated label, feedback buttons) after streaming completes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
python/samples/05-end-to-end/teams-agent/app.py Teams bot implementation wiring Teams SDK message handling to an Agent Framework agent with streaming.
python/samples/05-end-to-end/teams-agent/README.md Local run + Teams testing instructions and configuration guidance for the sample.
python/samples/05-end-to-end/teams-agent/.env.example Example environment configuration for Azure OpenAI + Teams bot credentials.

Comment thread python/samples/05-end-to-end/teams-agent/app.py
Comment thread python/samples/05-end-to-end/teams-agent/app.py Outdated
Comment thread python/samples/05-end-to-end/teams-agent/app.py Outdated
Comment thread python/samples/05-end-to-end/teams-agent/README.md Outdated
Comment thread python/samples/05-end-to-end/teams-agent/README.md Outdated
Comment thread python/samples/05-end-to-end/teams-agent/README.md
Comment thread python/samples/05-end-to-end/teams-agent/.env.example Outdated
Comment thread python/samples/05-end-to-end/teams-agent/app.py Outdated
Comment thread python/samples/05-end-to-end/teams-agent/app.py Outdated
Comment thread python/samples/05-end-to-end/teams-agent/app.py Outdated
Comment thread python/samples/05-end-to-end/teams-agent/README.md Outdated
"""Run the agent for each incoming Teams message and stream the reply back."""
try:
conversation_id = ctx.activity.conversation.id
session = _sessions.setdefault(conversation_id, agent.create_session())

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.

What happens when two messages land in the same conversation at nearly the same time? teams.py dispatches each activity concurrently and AgentSession has no internal locking, so both turns run agent.run against the same session and can interleave or duplicate history. Since this sample is the one advertising the per-conversation session pattern, should we serialize turns per conversation (an asyncio.Lock per id) or at least add a NOTE like the approval_mode one? The _sessions dict also grows without bound in a long-running bot, which is a real leak for anyone copying this into production.

if not text.strip():
return

async for chunk in agent.run(text, session=session, stream=True):

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.

Have we tested this in a group chat or channel? Teams only supports streamed bot messages in personal (1:1) scope, and the SDK flushes chunks in a fire-and-forget task, so in group scope the send failure never reaches this handler's try/except and stream.close() waits ~30s for a stream id before silently dropping the reply, so the user gets nothing. Could the sample fall back to a plain ctx.send when ctx.activity.conversation isn't personal, or should the README call out that this sample is 1:1 chat only?

@moonbox3

Copy link
Copy Markdown
Contributor

Please re-open when ready to address the comments and move forward. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants