ActivityRouteAttribute(String, String, Boolean, UInt16, String) Constructor
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Attribute to define a route that handles activities matching a specific type or type pattern.
public ActivityRouteAttribute(string type = default, string typeRegex = default, bool isAgenticOnly = false, ushort rank = 32767, string autoSignInHandlers = default);
new Microsoft.Agents.Builder.App.ActivityRouteAttribute : string * string * bool * uint16 * string -> Microsoft.Agents.Builder.App.ActivityRouteAttribute
Public Sub New (Optional type As String = Nothing, Optional typeRegex As String = Nothing, Optional isAgenticOnly As Boolean = false, Optional rank As UShort = 32767, Optional autoSignInHandlers As String = Nothing)
Parameters
- type
- String
The exact activity Type to match, e.g. ActivityTypes. Mutually exclusive with typeRegex.
- isAgenticOnly
- Boolean
When true, the route only fires for agentic turns. Defaults to false.
- rank
- UInt16
Route evaluation order. Lower values run first. When no type filter is specified, defaults to Last so specific-type routes take priority.
- autoSignInHandlers
- String
A comma/space/semicolon-delimited list of OAuth sign-in handler names, or the name of an instance or static method on the agent class matching Func<ITurnContext, string[]>.
Remarks
Decorate a method with this attribute to register it as a handler for activities of the specified type. Provide either type for an exact match or typeRegex for a pattern match; they are mutually exclusive. When neither is provided the route matches any activity type and defaults to Last. The method must match the RouteHandler delegate signature.
// Match by exact type
[ActivityRoute(ActivityTypes.Event)]
public async Task OnEventAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
// Handle any event activity
}
// Match by type pattern
[ActivityRoute(typeRegex: "event|invoke")]
public async Task OnEventOrInvokeAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
// Handle event or invoke activities
}
// Match any activity type (fires last, after all specific routes)
[ActivityRoute]
public async Task OnAnyAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
// Handle any unmatched activity
}