Table of Contents

Interface IMiddleware

Namespace
Microsoft.Agents.Builder
Assembly
Microsoft.Agents.Builder.dll

Represents middleware that can operate on incoming activities.

public interface IMiddleware

Remarks

A IChannelAdapter passes incoming activities from the user's channel to the middleware's OnTurnAsync(ITurnContext, NextDelegate, CancellationToken) method.

You can add middleware objects to your adapter’s middleware collection. The adapter processes and directs incoming activities in through the Agent middleware pipeline to your Agent’s logic and then back out again. As each activity flows in and out of the Agent, each piece of middleware can inspect or act upon the activity, both before and after the Agent logic runs.

For each activity, the adapter calls middleware in the order in which you added it.

Methods

OnTurnAsync(ITurnContext, NextDelegate, CancellationToken)

When implemented in middleware, processes an incoming activity.

Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default)

Parameters

turnContext ITurnContext

The context object for this turn.

next NextDelegate

The delegate to call to continue the Agent middleware pipeline.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

A task that represents the work queued to execute.

Remarks

Middleware calls the next delegate to pass control to the next middleware in the pipeline. If middleware doesn’t call the next delegate, the adapter does not call any of the subsequent middleware’s request handlers or the Agent’s receive handler, and the pipeline short circuits.

The turnContext provides information about the incoming activity, and other data needed to process the activity.

See Also

See Also