microsoft/agents/agents-sdk-dotnet-activityhandler-migration
Claude Code and agent skill by microsoft/agents
- vendor
Checking that the SKILL.md file is still in the repository.
Use when migrating a Microsoft 365 Agents SDK agent that uses ActivityHandler or TeamsActivityHandler to AgentApplication. This is ONLY for DotNet projects that uses `Microsoft.Agents.*` packages. Triggered by Agents SDK bots that subclass ActivityHandler or TeamsActivityHandler that need to be modernized to AgentApplication routing.
Install
npx vskill@latest install microsoft/agents/agents-sdk-dotnet-activityhandler-migrationSKILL.md
The same SKILL.md was published earlier as microsoft/agents/agents-sdk-dotnet-activityhandler-migration.
Agents SDK ActivityHandler → AgentApplication Migration (.NET)
Overview
Upgrades a bot from the ActivityHandler compat layer to the modern AgentApplication routing pattern. This is ONLY for DotNet projects that already use Microsoft.Agents.* packages. If the project is still using Microsoft.Bot.* packages the bf-to-agents-sdk-dotnet-migration skill should be used first.
Two entry points:
- Standalone: The bot already uses
Microsoft.Agents.*packages, namespaces, and appsettings — focus is on the bot class, Program.cs, and endpoint mapping. - Second step after `bf-to-agents-sdk-dotnet-migration`: Packages, namespaces, and appsettings were converted in that step — this skill handles the AgentApplication conversion.
What Does NOT Need to Change
Verify each of these is already correct — do not modify unless broken:
| Item | Expected State | |
|---|---|---|
| Namespaces in bot class | Already Microsoft.Agents.* — only remove compat namespaces | |
appsettings.json | Already has Connections + TokenValidation sections | |
builder.Services.AddAgentAspNetAuthentication(...) | Already present — keep | |
AspNetExtensions.cs (if present) | Sample-provided auth helper — keep as-is | |
| Custom DI in Program.cs | Preserve dialogs, adapters, custom services — but remove `ConversationState` and `UserState` (see Step 2) |
⚠️ If beta packages are required: Tell the user explicitly: "This migration uses pre-release (`-beta`) Agents SDK packages, which are nightly builds and not suitable for production. Upgrade to a stable release before deploying."
Handler Mapping: ActivityHandler → AgentApplication
| ActivityHandler Override | AgentApplication Registration | |
|---|---|---|
OnMessageActivityAsync(ITurnContext<IMessageActivity>, CT) | OnActivity(ActivityTypes.Message, handler, rank: RouteRank.Last) | |
OnMembersAddedAsync(IList<ChannelAccount>, ITurnContext<IConversationUpdateActivity>, CT) | OnConversationUpdate(ConversationUpdateEvents.MembersAdded, handler) | |
OnMembersRemovedAsync(...) | OnConversationUpdate(ConversationUpdateEvents.MembersRemoved, handler) | |
OnMessageUpdateActivityAsync(...) | OnActivity(ActivityTypes.MessageUpdate, handler) | |
OnMessageDeleteActivityAsync(...) | OnActivity(ActivityTypes.MessageDelete, handler) | |
OnReactionsAddedAsync(IList<MessageReaction>, ...) | OnMessageReactionsAdded(handler) | |
OnReactionsRemovedAsync(IList<MessageReaction>, ...) | OnMessageReactionsRemoved(handler) | |
OnEventAsync(ITurnContext<IEventActivity>, CT) | OnEvent(eventName, handler) or OnActivity(ActivityTypes.Event, handler) | |
OnInvokeActivityAsync(...) with adaptiveCard/action + verb switch | AdaptiveCards.OnActionExecute(verb, handler) — one registration per verb (preferred) | |
OnInvokeActivityAsync(...) with application/search | AdaptiveCards.OnSearch(dataset, handler) — one registration per choices.data.dataset value | |
OnInvokeActivityAsync(...) (other invoke types) | OnActivity(ActivityTypes.Invoke, handler) | |
OnTurnAsync(...) override (cross-cutting) | OnBeforeTurn(handler) / OnAfterTurn(handler) | |
OnInstallationUpdateActivityAsync(...) | OnActivity(ActivityTypes.InstallationUpdate, handler) | |
OnEndOfConversationActivityAsync(...) | OnActivity(ActivityTypes.EndOfConversation, handler) |
Key difference: Handler signature changes from (ITurnContext<T>, CT) to (ITurnContext, ITurnState, CT). membersAdded, membersRemoved, messageReactions are no longer separate parameters — access via turnContext.Activity.*.
adaptiveCard/action invokes → AdaptiveCards.OnActionExecute
If the bot overrides OnInvokeActivityAsync and switches on a verb from adaptiveCard/action activities, replace it with per-verb AdaptiveCards.OnActionExecute registrations. AdaptiveCards is a property on AgentApplication (no RegisterExtension needed):
Key points:
dataparameter =invokeValue.Action.Data— deserialize as your data model, not asAdaptiveCardInvokeValue- Return
AdaptiveCardInvokeResponsedirectly — the framework wraps it in anInvokeResponseautomatically CreateInvokeResponse()is a compat-layer helper that does not exist onAgentApplication- Namespace:
using Microsoft.Agents.Builder.App.AdaptiveCards;
Step 1-a: Convert Bot Class to AgentApplication (not using Dialogs)
- Remove
using Microsoft.Agents.Builder.Compat;(ActivityHandler namespace) - Remove
using Microsoft.Agents.Extensions.Teams.Compat;(TeamsActivityHandler namespace) - Keep all other
using Microsoft.Agents.*statements — they are already correct
For Teams bots (TeamsActivityHandler) with Teams-specific handlers (messaging extensions, task modules, etc.), see Step 1-d below.
Step 1-b: Convert Bot Class to AgentApplication (using Dialogs)
- Remove
using Microsoft.Agents.Builder.Compat;(ActivityHandler namespace) - Remove
using Microsoft.Agents.Extensions.Teams.Compat;(TeamsActivityHandler namespace) - Keep all other
using Microsoft.Agents.*statements — they are already correct
Key differences from non-dialog migration:
- Do not inject
ConversationStateinto the bot — passturnState.ConversationtoDialog.RunAsyncinstead - Use
InvokeRouteBuilder(notOnActivity(ActivityTypes.Invoke, ...)) to route signin invokes — the name pattern matches bothsignin/verifyStateandsignin/tokenExchange - Remove
ConversationStateandUserStatefrom DI entirely — see Step 2
⚠️ Generic `DialogBot<T>` base class pattern: Some projects use a two-level class hierarchy where a generic base class (e.g.DialogBot<T> : ActivityHandler) holds the dialog field, state injection, andOnTurnAsyncstate-saving override, and the concrete bot class (e.g.MyBot : DialogBot<MainDialog>) only adds routing. Collapse both classes into a single non-genericAgentApplicationsubclass — inject the concrete dialog type directly in the constructor. The generic type parameter is not needed. RemoveOnTurnAsyncentirely (AgentApplication manages state automatically).
Step 1-c: Remove State Management Boilerplate
Remove OnTurnBeginAsync / OnTurnEndAsync Overrides
ActivityHandler and TeamsActivityHandler bots sometimes manually load and save state in turn lifecycle overrides. Remove these entirely — AgentApplication handles state loading and saving automatically:
Also remove any ConversationState or UserState properties/fields that were injected for this purpose.
Migrate CloudAdapter OnTurnError to AgentApplication
If a custom CloudAdapter subclass injects ConversationState only to call DeleteStateAsync on error, move that logic to an AgentApplication.OnTurnError handler instead.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files. Certified 12 Jun 2026.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingagent-plugins/agents-for-net/skills/agents-sdk-dotnet-activityhandler-migration/SKILL.md
Popularity
- Repository stars
- 1,060
- Repository forks
- 338
- 7-day trend score
- 35
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 12 Sep 2026, 2 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/microsoft/agents/agents-sdk-dotnet-activityhandler-migration)