// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Agents.AI.Workflows;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.Agents.AI.Hosting;
///
/// Provides extension methods for to enable additional workflow configuration scenarios.
///
public static class HostedWorkflowBuilderExtensions
{
///
/// Registers the workflow as an AI agent in the dependency injection container.
///
/// The instance to extend.
/// An that can be used to further configure the agent.
public static IHostedAgentBuilder AddAsAIAgent(this IHostedWorkflowBuilder builder)
=> builder.AddAsAIAgent(name: null);
///
/// Registers the workflow as an AI agent in the dependency injection container.
///
/// The instance to extend.
/// The optional name for the AI agent. If not specified, the workflow name is used.
/// An that can be used to further configure the agent.
public static IHostedAgentBuilder AddAsAIAgent(this IHostedWorkflowBuilder builder, string? name)
{
var workflowName = builder.Name;
var agentName = name ?? workflowName;
return builder.HostApplicationBuilder.AddAIAgent(agentName, (sp, key) =>
sp.GetRequiredKeyedService(workflowName).AsAIAgent(name: key));
}
}