AgentHostingServiceCollectionExtensions.AddAIAgent Method
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.
Overloads
| Name | Description |
|---|---|
| AddAIAgent(IServiceCollection, String, Func<IServiceProvider,String,AIAgent>) |
Adds an AI agent to the service collection using a custom factory delegate. |
| AddAIAgent(IServiceCollection, String, String) |
Adds an AI agent to the service collection using only a name and instructions, resolving the chat client from dependency injection. |
| AddAIAgent(IServiceCollection, String, String, IChatClient) |
Adds an AI agent to the service collection with a provided chat client instance. |
| AddAIAgent(IServiceCollection, String, String, Object) |
Adds an AI agent to the service collection using a chat client resolved by an optional keyed service. |
| AddAIAgent(IServiceCollection, String, String, String, Object) |
Adds an AI agent to the service collection using a chat client (optionally keyed) and a description. |
AddAIAgent(IServiceCollection, String, Func<IServiceProvider,String,AIAgent>)
Adds an AI agent to the service collection using a custom factory delegate.
public static Microsoft.Agents.AI.Hosting.IHostedAgentBuilder AddAIAgent(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, Func<IServiceProvider,string,Microsoft.Agents.AI.AIAgent> createAgentDelegate);
static member AddAIAgent : Microsoft.Extensions.DependencyInjection.IServiceCollection * string * Func<IServiceProvider, string, Microsoft.Agents.AI.AIAgent> -> Microsoft.Agents.AI.Hosting.IHostedAgentBuilder
<Extension()>
Public Function AddAIAgent (services As IServiceCollection, name As String, createAgentDelegate As Func(Of IServiceProvider, String, AIAgent)) As IHostedAgentBuilder
Parameters
- services
- IServiceCollection
The service collection to configure.
- name
- String
The name of the agent.
- createAgentDelegate
- Func<IServiceProvider,String,AIAgent>
A factory delegate that creates the AI agent instance. The delegate receives the service provider and agent key as parameters.
Returns
The same IServiceCollection instance so that additional calls can be chained.
Exceptions
Thrown when services, name, or createAgentDelegate is null.
Thrown when the agent factory delegate returns null or an agent whose Name does not match name.
Applies to
AddAIAgent(IServiceCollection, String, String)
Adds an AI agent to the service collection using only a name and instructions, resolving the chat client from dependency injection.
public static Microsoft.Agents.AI.Hosting.IHostedAgentBuilder AddAIAgent(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, string? instructions);
static member AddAIAgent : Microsoft.Extensions.DependencyInjection.IServiceCollection * string * string -> Microsoft.Agents.AI.Hosting.IHostedAgentBuilder
<Extension()>
Public Function AddAIAgent (services As IServiceCollection, name As String, instructions As String) As IHostedAgentBuilder
Parameters
- services
- IServiceCollection
The service collection to configure.
- name
- String
The name of the agent.
- instructions
- String
The instructions for the agent.
Returns
The same IServiceCollection instance so that additional calls can be chained.
Exceptions
Thrown when services or name is null.
Applies to
AddAIAgent(IServiceCollection, String, String, IChatClient)
Adds an AI agent to the service collection with a provided chat client instance.
public static Microsoft.Agents.AI.Hosting.IHostedAgentBuilder AddAIAgent(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, string? instructions, Microsoft.Extensions.AI.IChatClient chatClient);
static member AddAIAgent : Microsoft.Extensions.DependencyInjection.IServiceCollection * string * string * Microsoft.Extensions.AI.IChatClient -> Microsoft.Agents.AI.Hosting.IHostedAgentBuilder
<Extension()>
Public Function AddAIAgent (services As IServiceCollection, name As String, instructions As String, chatClient As IChatClient) As IHostedAgentBuilder
Parameters
- services
- IServiceCollection
The service collection to configure.
- name
- String
The name of the agent.
- instructions
- String
The instructions for the agent.
- chatClient
- IChatClient
The chat client which the agent will use for inference.
Returns
The same IServiceCollection instance so that additional calls can be chained.
Exceptions
Thrown when services or name is null.
Applies to
AddAIAgent(IServiceCollection, String, String, Object)
Adds an AI agent to the service collection using a chat client resolved by an optional keyed service.
public static Microsoft.Agents.AI.Hosting.IHostedAgentBuilder AddAIAgent(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, string? instructions, object? chatClientServiceKey);
static member AddAIAgent : Microsoft.Extensions.DependencyInjection.IServiceCollection * string * string * obj -> Microsoft.Agents.AI.Hosting.IHostedAgentBuilder
<Extension()>
Public Function AddAIAgent (services As IServiceCollection, name As String, instructions As String, chatClientServiceKey As Object) As IHostedAgentBuilder
Parameters
- services
- IServiceCollection
The service collection to configure.
- name
- String
The name of the agent.
- instructions
- String
The instructions for the agent.
- chatClientServiceKey
- Object
The key to use when resolving the chat client from the service provider. If null, a non-keyed service will be resolved.
Returns
The same IServiceCollection instance so that additional calls can be chained.
Exceptions
Thrown when services or name is null.
Applies to
AddAIAgent(IServiceCollection, String, String, String, Object)
Adds an AI agent to the service collection using a chat client (optionally keyed) and a description.
public static Microsoft.Agents.AI.Hosting.IHostedAgentBuilder AddAIAgent(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, string? instructions, string? description, object? chatClientServiceKey);
static member AddAIAgent : Microsoft.Extensions.DependencyInjection.IServiceCollection * string * string * string * obj -> Microsoft.Agents.AI.Hosting.IHostedAgentBuilder
<Extension()>
Public Function AddAIAgent (services As IServiceCollection, name As String, instructions As String, description As String, chatClientServiceKey As Object) As IHostedAgentBuilder
Parameters
- services
- IServiceCollection
The service collection to configure.
- name
- String
The name of the agent.
- instructions
- String
The instructions for the agent.
- description
- String
A description of the agent.
- chatClientServiceKey
- Object
The key to use when resolving the chat client from the service provider. If null, a non-keyed service will be resolved.
Returns
The same IServiceCollection instance so that additional calls can be chained.
Exceptions
Thrown when services or name is null.