ServiceCollectionExtensions.AddAgent Method

Definition

Overloads

Name Description
AddAgent(IHostApplicationBuilder, Func<IServiceProvider,IAgent>)

Adds an Agent via lambda construction.

builder.Services.AddSingleton<IStorage, MemoryStorage>();
builder.AddAgent(sp =>
{
   var options = new AgentApplicationOptions()
   {
      TurnStateFactory = () => new TurnState(sp.GetService<IStorage>());
   };

   var app = new AgentApplication(options);

   ...

   return app;
});
AddAgent<TAdapter>(IServiceCollection, Func<IServiceProvider,IAgent>)

Adds an agent and its associated adapter to the service collection using the specified implementation factory.

AddAgent<TAdapter>(IHostApplicationBuilder, Func<IServiceProvider,IAgent>)

This is the same as AddAgent(IHostApplicationBuilder, Func<IServiceProvider,IAgent>), except allows the use of any CloudAdapter subclass.

AddAgent<TAgent,TAdapter>(IServiceCollection)

Adds an agent and its associated cloud adapter to the service collection for dependency injection.

services.AddSingleton<IStorage, MemoryStorage>();
services.AddAgent<MyAgent, CloudAdapter>();
AddAgent<TAgent,TAdapter>(IHostApplicationBuilder)

Same as AddAgent<TAgent>(IHostApplicationBuilder) but allows for use of any CloudAdapter subclass.

builder.Services.AddSingleton<IStorage, MemoryStorage>();
builder.AddAgent<MyAgent, MyCustomAdapter>();
AddAgent<TAgent>(IHostApplicationBuilder)

Adds an Agent which subclasses AgentApplication

builder.Services.AddSingleton<IStorage, MemoryStorage>();
builder.AddAgent<MyAgent>();

AddAgent(IHostApplicationBuilder, Func<IServiceProvider,IAgent>)

Adds an Agent via lambda construction.

builder.Services.AddSingleton<IStorage, MemoryStorage>();
builder.AddAgent(sp =>
{
   var options = new AgentApplicationOptions()
   {
      TurnStateFactory = () => new TurnState(sp.GetService<IStorage>());
   };

   var app = new AgentApplication(options);

   ...

   return app;
});
public static Microsoft.Extensions.Hosting.IHostApplicationBuilder AddAgent(this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, Func<IServiceProvider,Microsoft.Agents.Builder.IAgent> implementationFactory);
static member AddAgent : Microsoft.Extensions.Hosting.IHostApplicationBuilder * Func<IServiceProvider, Microsoft.Agents.Builder.IAgent> -> Microsoft.Extensions.Hosting.IHostApplicationBuilder
<Extension()>
Public Function AddAgent (builder As IHostApplicationBuilder, implementationFactory As Func(Of IServiceProvider, IAgent)) As IHostApplicationBuilder

Parameters

implementationFactory
Func<IServiceProvider,IAgent>

Returns

The same instance of IHostApplicationBuilder to allow for method chaining.

Remarks

This will also call AddAgentCore(IHostApplicationBuilder) and uses CloudAdapter. The Agent is registered as Transient. AgentApplicationOptions is automatically registered if not already present.

Applies to

AddAgent<TAdapter>(IServiceCollection, Func<IServiceProvider,IAgent>)

Adds an agent and its associated adapter to the service collection using the specified implementation factory.

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAgent<TAdapter>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<IServiceProvider,Microsoft.Agents.Builder.IAgent> implementationFactory) where TAdapter : Microsoft.Agents.Hosting.AspNetCore.CloudAdapter;
static member AddAgent : Microsoft.Extensions.DependencyInjection.IServiceCollection * Func<IServiceProvider, Microsoft.Agents.Builder.IAgent> -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Adapter :> Microsoft.Agents.Hosting.AspNetCore.CloudAdapter)
<Extension()>
Public Function AddAgent(Of TAdapter As CloudAdapter) (services As IServiceCollection, implementationFactory As Func(Of IServiceProvider, IAgent)) As IServiceCollection

Type Parameters

TAdapter

The type of the cloud adapter to associate with the agent. Must inherit from CloudAdapter.

Parameters

services
IServiceCollection

The service collection to which the agent and adapter are added.

implementationFactory
Func<IServiceProvider,IAgent>

A factory function that creates an instance of IAgent using the provided service provider.

Returns

Remarks

This method registers the specified agent and its adapter for dependency injection. The agent is registered with a transient lifetime. Call this method during application startup to enable agent-based functionality.

Applies to

AddAgent<TAdapter>(IHostApplicationBuilder, Func<IServiceProvider,IAgent>)

This is the same as AddAgent(IHostApplicationBuilder, Func<IServiceProvider,IAgent>), except allows the use of any CloudAdapter subclass.

public static Microsoft.Extensions.Hosting.IHostApplicationBuilder AddAgent<TAdapter>(this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, Func<IServiceProvider,Microsoft.Agents.Builder.IAgent> implementationFactory) where TAdapter : Microsoft.Agents.Hosting.AspNetCore.CloudAdapter;
static member AddAgent : Microsoft.Extensions.Hosting.IHostApplicationBuilder * Func<IServiceProvider, Microsoft.Agents.Builder.IAgent> -> Microsoft.Extensions.Hosting.IHostApplicationBuilder (requires 'Adapter :> Microsoft.Agents.Hosting.AspNetCore.CloudAdapter)
<Extension()>
Public Function AddAgent(Of TAdapter As CloudAdapter) (builder As IHostApplicationBuilder, implementationFactory As Func(Of IServiceProvider, IAgent)) As IHostApplicationBuilder

Type Parameters

TAdapter

Parameters

implementationFactory
Func<IServiceProvider,IAgent>

Returns

The same instance of IHostApplicationBuilder to allow for method chaining.

Remarks

AgentApplicationOptions is automatically registered if not already present.

Applies to

AddAgent<TAgent,TAdapter>(IServiceCollection)

Adds an agent and its associated cloud adapter to the service collection for dependency injection.

services.AddSingleton<IStorage, MemoryStorage>();
services.AddAgent<MyAgent, CloudAdapter>();
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAgent<TAgent,TAdapter>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where TAgent : class, Microsoft.Agents.Builder.IAgent where TAdapter : Microsoft.Agents.Hosting.AspNetCore.CloudAdapter;
static member AddAgent : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Agent : null and 'Agent :> Microsoft.Agents.Builder.IAgent and 'Adapter :> Microsoft.Agents.Hosting.AspNetCore.CloudAdapter)
<Extension()>
Public Function AddAgent(Of TAgent As {Class, IAgent}, TAdapter As {Class, IAgent}) (services As IServiceCollection) As IServiceCollection

Type Parameters

TAgent

The type of the agent to register. Must implement the IAgent interface.

TAdapter

The type of the cloud adapter to register. Must derive from CloudAdapter.

Parameters

services
IServiceCollection

The service collection to which the agent and adapter will be added.

Returns

Remarks

Registers both the agent and its adapter as transient services. Only one instance of each agent type is registered. AgentApplicationOptions is automatically registered if not already present. This method is typically used to configure multi-agent scenarios in applications that use dependency injection.

Applies to

AddAgent<TAgent,TAdapter>(IHostApplicationBuilder)

Same as AddAgent<TAgent>(IHostApplicationBuilder) but allows for use of any CloudAdapter subclass.

builder.Services.AddSingleton<IStorage, MemoryStorage>();
builder.AddAgent<MyAgent, MyCustomAdapter>();
public static Microsoft.Extensions.Hosting.IHostApplicationBuilder AddAgent<TAgent,TAdapter>(this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder) where TAgent : class, Microsoft.Agents.Builder.IAgent where TAdapter : Microsoft.Agents.Hosting.AspNetCore.CloudAdapter;
static member AddAgent : Microsoft.Extensions.Hosting.IHostApplicationBuilder -> Microsoft.Extensions.Hosting.IHostApplicationBuilder (requires 'Agent : null and 'Agent :> Microsoft.Agents.Builder.IAgent and 'Adapter :> Microsoft.Agents.Hosting.AspNetCore.CloudAdapter)
<Extension()>
Public Function AddAgent(Of TAgent As {Class, IAgent}, TAdapter As {Class, IAgent}) (builder As IHostApplicationBuilder) As IHostApplicationBuilder

Type Parameters

TAgent
TAdapter

Parameters

Returns

The same instance of IHostApplicationBuilder to allow for method chaining.

Remarks

AgentApplicationOptions is automatically registered if not already present.

Applies to

AddAgent<TAgent>(IHostApplicationBuilder)

Adds an Agent which subclasses AgentApplication

builder.Services.AddSingleton<IStorage, MemoryStorage>();
builder.AddAgent<MyAgent>();
public static Microsoft.Extensions.Hosting.IHostApplicationBuilder AddAgent<TAgent>(this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder) where TAgent : class, Microsoft.Agents.Builder.IAgent;
static member AddAgent : Microsoft.Extensions.Hosting.IHostApplicationBuilder -> Microsoft.Extensions.Hosting.IHostApplicationBuilder (requires 'Agent : null and 'Agent :> Microsoft.Agents.Builder.IAgent)
<Extension()>
Public Function AddAgent(Of TAgent As {Class, IAgent}) (builder As IHostApplicationBuilder) As IHostApplicationBuilder

Type Parameters

TAgent

Parameters

Returns

The same instance of IHostApplicationBuilder to allow for method chaining.

Remarks

This will also call AddAgentCore(IHostApplicationBuilder) and uses CloudAdapter. The Agent is registered as Transient. AgentApplicationOptions is automatically registered if not already present.

Applies to