Python: Add Teams SDK end-to-end sample - #6676
Python: Add Teams SDK end-to-end sample#6676Mehak Bindra (MehakBindra) wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
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. |
Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com>
…ndra/agent-framework into feature/teams-sdk-sample
| """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()) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
|
Please re-open when ready to address the comments and move forward. Thank you. |
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
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
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
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
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.