AgentHostExtensions Class
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.
Extension methods on IHostApplicationBuilder and WebApplication for configuring agent services and the request pipeline.
public static class AgentHostExtensions
type AgentHostExtensions = class
Public Module AgentHostExtensions
- Inheritance
-
AgentHostExtensions
Remarks
These methods provide a streamlined way to configure an agent application. The minimal setup is:
builder.AddAgentDefaults()
.AddAgent<MyAgent>()
.AddAgentAuthorization(b => b.AddAgentAspNetAuthentication());
var app = builder.Build();
app.UseAgents();
app.MapDefaultAgentEndpoints();
For advanced scenarios (custom HttpClient configuration, non-standard middleware ordering, custom endpoint routing, etc.), use ServiceCollectionExtensions for DI registration and AgentEndpointExtensions for endpoint mapping directly. The equivalent manual setup for the above is:
builder.Services.AddHttpClient();
builder.Services.AddControllers();
builder.AddAgent<MyAgent>();
// Configure authentication (e.g., AddAgentAspNetAuthentication, MISE, or custom)
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapAgentRootEndpoint();
app.MapAgentApplicationEndpoints(requireAuth: true);
Methods
| Name | Description |
|---|---|
| AddAgent(IHostApplicationBuilder, Func<IServiceProvider,IAgent>) |
Adds an Agent via lambda construction.
|
| AddAgent<TAdapter>(IHostApplicationBuilder, Func<IServiceProvider,IAgent>) |
This is the same as AddAgent(IHostApplicationBuilder, Func<IServiceProvider,IAgent>), except allows the
use of any |
| AddAgent<TAgent,TAdapter>(IHostApplicationBuilder) |
Same as AddAgent<TAgent>(IHostApplicationBuilder) but allows for use of
any
|
| AddAgent<TAgent>(IHostApplicationBuilder) |
Adds an Agent which subclasses
|
| AddAgentApplicationOptions(IHostApplicationBuilder, AutoSignInSelector) |
Registers AgentApplicationOptions for AgentApplication-based Agents. |
| AddAgentAttachmentDownloader(IHostApplicationBuilder) |
Registers the AttachmentDownloader for non-Teams channels. This downloader handles standard HTTP attachment URLs. |
| AddAgentAuthorization(IHostApplicationBuilder, Action<IHostApplicationBuilder>, Nullable<Boolean>) |
Configures token validation for inbound requests. The provided action should register
authentication services (e.g., call |
| AddAgentCore(IHostApplicationBuilder) |
Adds the core agent services.
|
| AddAgentCore<TAdapter>(IHostApplicationBuilder) |
Adds the core agent services using a derived CloudAdapter.
|
| AddAgentDefaults(IHostApplicationBuilder) |
Registers default services required by the Agents SDK. |
| AddAgentFileDownloader(IHostApplicationBuilder, IInputFileDownloader) |
Registers an IInputFileDownloader instance for use by AgentApplicationOptions. Can be called multiple times to add additional downloaders. |
| AddAgentM365AttachmentDownloader(IHostApplicationBuilder, M365AttachmentDownloaderOptions) |
Registers the M365AttachmentDownloader for Teams/M365 channels. This downloader handles M365 attachment URLs using the configured token provider. |
| AddAgentMiddleware(IHostApplicationBuilder, IMiddleware) |
Registers an IMiddleware instance to be used by the CloudAdapter pipeline. Can be called multiple times to add additional middleware in order. |
| AddCloudAdapter(IHostApplicationBuilder) |
Add the default CloudAdapter. |
| AddCloudAdapter<T>(IHostApplicationBuilder) |
Add a derived CloudAdapter. |
| IsAgentAuthorizationConfigured(IEndpointRouteBuilder) |
Indicates whether agent authorization was configured via AddAgentAuthorization(IHostApplicationBuilder, Action<IHostApplicationBuilder>, Nullable<Boolean>). |
| IsAgentAuthorizationConfigured(IServiceProvider) |
Indicates whether agent authorization was configured via AddAgentAuthorization(IHostApplicationBuilder, Action<IHostApplicationBuilder>, Nullable<Boolean>). |
| MapDefaultAgentEndpoints(IEndpointRouteBuilder, String) |
Maps the default agent endpoints: a root health endpoint ( |
| UseAgents(WebApplication, Boolean, Boolean) |
Adds authentication and authorization middleware to the request pipeline. |
| UseHeaderPropagation(IApplicationBuilder) |
Adds a middleware that collects headers to be propagated. |
| UseHeaderPropagation(IHostApplicationBuilder) |
Registers the HeaderPropagationMiddleware so that incoming request headers are propagated to outgoing requests. This builder-phase overload allows header propagation to be configured fluently alongside the other agent registration calls:
|