Microsoft.Dynamics.AgentsSDK.Middleware 1.0.0

Prefix Reserved
dotnet add package Microsoft.Dynamics.AgentsSDK.Middleware --version 1.0.0
                    
NuGet\Install-Package Microsoft.Dynamics.AgentsSDK.Middleware -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.Dynamics.AgentsSDK.Middleware" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Microsoft.Dynamics.AgentsSDK.Middleware" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Microsoft.Dynamics.AgentsSDK.Middleware" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Microsoft.Dynamics.AgentsSDK.Middleware --version 1.0.0
                    
#r "nuget: Microsoft.Dynamics.AgentsSDK.Middleware, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Microsoft.Dynamics.AgentsSDK.Middleware@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Microsoft.Dynamics.AgentsSDK.Middleware&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Microsoft.Dynamics.AgentsSDK.Middleware&version=1.0.0
                    
Install as a Cake Tool

Microsoft Dynamics 365 Customer Service Agents SDK Middleware

The Agents SDK Middleware provides middleware and utilities for building agents that integrate with Microsoft Dynamics 365 Customer Service Omnichannel platform using the Microsoft Agents Framework. It simplifies the process of handling Omnichannel-specific activities, extracting channel data, and managing bidirectional communication between your agent and Dynamics 365 Customer Service.

Getting started

Install the package via NuGet Package Manager:

Install-Package Microsoft.Dynamics.AgentsSDK.Middleware

Or via .NET CLI:

dotnet add package Microsoft.Dynamics.AgentsSDK.Middleware

Prerequisites

  • .NET 8.0 or later
  • Microsoft Agents Framework packages
  • An existing agent project or a new ASP.NET Core application

Usage

Adding the Middleware invloves multiple steps

Creating the Adapter

Inherit from CloudAdapter and add middleware using Use():

public class YourCustomAdapter : CloudAdapter
{
    public YourCustomAdapter(
        IChannelServiceClientFactory channelServiceClientFactory, 
        IActivityTaskQueue activityTaskQueue, 
        ILogger<IAgentHttpAdapter> logger)
        : base(channelServiceClientFactory, activityTaskQueue, logger)
    {
        // Add middleware to the pipeline
        Use(new LoggingMiddleware());
    }
}

Adding to Your Agent

Register in Program.cs:

var builder = WebApplication.CreateBuilder(args);

// Register the custom adapter with middleware
builder.Services.AddAgent<YourAgent, YourCustomAdapter>();

var app = builder.Build();

Using Activity Extensions

The SDK provides extension methods to easily work with Omnichannel activities:

using Microsoft.Dynamics.AgentsSDK.Middleware.Extensions;

public async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
    // Check if the activity is from Omnichannel
    if (turnContext.Activity.IsOmnichannel())
    {
        // Get channel-specific data
        var tags = turnContext.Activity.GetChannelDataOrDefault<string>("tags");
        var fromUserId = turnContext.Activity.GetChannelDataOrDefault<string>("fromUserId");
        
        // Process the activity based on channel data
        await turnContext.SendActivityAsync($"Received message from user: {fromUserId}", cancellationToken);
    }
}

Key Components

The SDK includes the following components:

  • OmnichannelMiddleware: Microsoft Agents Framework middleware for processing Omnichannel-specific activities, handling channel data extraction, activity transformation, and user identification
  • ActivityExtensions: Helper methods like IsOmnichannel() and GetChannelData<T>() for working with Omnichannel activity data
  • OmnichannelMiddlewareConstants: Predefined constants for channel data keys, tags, identifiers, and regex patterns

Features

  • Channel Data Processing: Automatic extraction of channel-specific metadata and user identification across channels
  • Activity Transformation: Bidirectional conversion between message and event activities with preservation of original channel information
  • Error Handling: Graceful handling of malformed channel data with fallback mechanisms and non-blocking error processing

Additional documentation

Feedback

For issues, questions, and feature requests:


� Microsoft Corporation. All rights reserved.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 696 12/2/2025