How to Add the Teams Extension to an Agent in the Microsoft 365 Agents SDK in C#
Some features exist only in Microsoft Teams: dialogs, message extensions, meeting events, team and channel events. The Microsoft 365 Agents SDK keeps them in its Teams extension. You turn it on for an agent with one package and one attribute.
Syntax
using Microsoft.Agents.Extensions.MSTeams;
[TeamsExtension]
public partial class <AgentName> : AgentApplication
{
// Teams features through the generated property:
// TeamsExtension.TaskModules, TeamsExtension.MessageExtensions, TeamsExtension.Meetings, ...
// or through Teams route attributes on methods, such as [TeamsMessageRoute].
}
| Part | What it does |
|---|---|
Microsoft.Agents.Extensions.MSTeams | The NuGet package with the Teams extension. Its readme: Provides Microsoft Teams-specific extensions for the Microsoft 365 Agents SDK. |
[TeamsExtension] | Asks the SDK's source generator to add the extension to this class |
partial | Lets the generator write the other part of the class. Without it, the build fails |
<AgentName> | Your agent class, a subclass of AgentApplication |
TeamsExtension | The property the generator adds, of type TeamsAgentExtension |
The property's name is TeamsExtension. The SDK's own documentation for the attribute says the property is called Teams, which doesn't build: Fixed: "The name 'Teams' does not exist in the current context" with [TeamsExtension] in the Microsoft 365 Agents SDK shows what the generator really writes.
Inside TeamsExtension, the SDK's source groups the Teams features as TaskModules (dialogs), MessageExtensions, Meetings, Channels, Teams (team events) and FileConsent.
The Example
The agent for this post answers every message in Teams with the kind of conversation it's in: Hello from Teams! This is a personal conversation. Its one route is a Teams route attribute, [TeamsMessageRoute], whose handler gets the activity as a Teams activity.
The agent is one class in an ASP.NET Core project with the Agents SDK 1.9.205, set up to run in Teams: its own bot registration and identity, token validation, and an app package whose bot allows personal.
Prerequisites
- An agent that already runs in Microsoft Teams, in a personal chat: a bot registration, the agent's identity in its settings, and the app added in Teams.
Step 1: Add the Package
In the project's folder:
dotnet add package Microsoft.Agents.Extensions.MSTeams --version 1.9.205
dotnet add package adds the package to the project file. Use the same version as your other Microsoft.Agents.* packages.
Step 2: Mark the Agent Class
using Microsoft.Agents.Builder.App;
using Microsoft.Agents.Builder.State;
using Microsoft.Agents.Extensions.MSTeams;
using Microsoft.Agents.Extensions.MSTeams.App;
namespace HoExtension;
[TeamsExtension]
public partial class WhereAmIAgent(AgentApplicationOptions options) : AgentApplication(options)
{
[TeamsMessageRoute]
public async Task OnMessageAsync(ITeamsTurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
string conversationType = turnContext.Activity.Conversation.ConversationType;
await turnContext.SendActivityAsync($"Hello from Teams! This is a {conversationType} conversation.", cancellationToken: cancellationToken);
}
}
![WhereAmIAgent.cs in a macOS-style editor window: the class marked [TeamsExtension] and partial, deriving from AgentApplication, with one method marked [TeamsMessageRoute] that reads the conversation type from the Teams activity and sends Hello from Teams! This is a ... conversation.](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/ai/microsoft/m365-agents-sdk/2026/m365-teams-extension-01-code.webp)
[TeamsExtension]andpartialturn the extension on for this class.[TeamsMessageRoute]is one of the extension's route attributes. With no text given, the SDK's description says it matches any message.ITeamsTurnContextis the turn context as the Teams extension sees it. ItsActivityis, in the SDK's words, a strongly-typed TeamsActivity, soConversation.ConversationTypeis right there.
Register the class in Program.cs the usual way, with builder.AddAgent<WhereAmIAgent>().
Step 3: See What the Attribute Adds
The attribute works through a source generator: code that writes more code while the project builds. To see that code, build once with the compiler's generated files turned on, and with --no-incremental, so the compiler runs even if nothing changed:
dotnet build --no-incremental -p:EmitCompilerGeneratedFiles=true
Determining projects to restore...
All projects are up-to-date for restore.
HoExtension -> /Users/you/HoExtension/bin/Debug/net10.0/HoExtension.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.63
The generator's file is under obj/Debug/net10.0/generated/Microsoft.Agents.Core.Analyzers/:
// <auto-generated />
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#nullable disable
namespace HoExtension
{
partial class WhereAmIAgent
{
/// <summary>
/// Provides access to <see cref="Microsoft.Agents.Extensions.MSTeams.TeamsAgentExtension"/> agent features.
/// </summary>
public global::Microsoft.Agents.Extensions.MSTeams.TeamsAgentExtension TeamsExtension { get; private set; }
protected override void ConfigureExtensions()
{
base.ConfigureExtensions();
TeamsExtension = new global::Microsoft.Agents.Extensions.MSTeams.TeamsAgentExtension(this);
RegisterExtension(TeamsExtension, _ => { });
}
}
}
The other part of WhereAmIAgent gets the TeamsExtension property, and a ConfigureExtensions method that creates it and registers it when the agent is constructed. That's why the class must be partial.
Step 4: Try It in Teams
Start the agent, and send it a message in its personal chat:

personal is the conversation type of a one-to-one chat with the agent. In a group chat, the same field says groupChat.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Leaving out partial | error MAA001: 'WhereAmIAgent' must be declared as 'partial' to use an AgentExtension attribute | Declare the class partial |
Writing Teams.TaskModules, as the SDK's documentation says | error CS0103: The name 'Teams' does not exist in the current context | Write TeamsExtension.TaskModules |
Using the old Microsoft.Agents.Extensions.Teams package | Its classes are marked obsolete in 1.9.205 | Use Microsoft.Agents.Extensions.MSTeams |
| Expecting the generated file after a build that changed nothing | No .g.cs file | Add --no-incremental |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
MAA001 | The class isn't partial | Add partial |
CS0103 for Teams | The property is called TeamsExtension | Rename the uses |
| The agent doesn't answer in Teams | The bot can't reach the agent, or the route isn't registered | Check the agent's log for the incoming message |
FAQ
Do I need the generated property if I only use route attributes?
No. Attribute routes such as [TeamsMessageRoute] register without touching it, as in this post. You need the property for the fluent methods, such as TeamsExtension.TaskModules.OnFetch.
What else does the extension give me?
Besides the feature groups, TeamsAgentExtension has GetTeamsClient, for Teams' own API, and GetGraphClient and GetAppGraphClient, for Microsoft Graph.
Is the Teams extension the same as the Teams SDK?
No. The Agents SDK's Teams extension builds on Microsoft's Teams SDK package, Microsoft.Teams.Apps, which 1.9.205 brings in at version 2.1.2, and exposes its features through Agents SDK routes.
Conclusion
To use Teams-only features in an Agents SDK agent, add Microsoft.Agents.Extensions.MSTeams, mark your AgentApplication class [TeamsExtension] and partial, and use the generated TeamsExtension property or the Teams route attributes.
Additional Resources
- TeamsExtensionAttribute Class, on Microsoft Learn.
- TeamsAgentExtension Class, on Microsoft Learn.
- Source generators, on Microsoft Learn.
Related
- Fixed: "The name 'Teams' does not exist in the current context" with [TeamsExtension] in the Microsoft 365 Agents SDK
- How to Define Routes with Attributes in the Microsoft 365 Agents SDK in C#
- How to Open a Teams Dialog from an Adaptive Card in the Microsoft 365 Agents SDK in C#
- Microsoft 365 Agents SDK Fundamentals in C# — Part 10: Teams Dialogs
