// 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. /// The DI service lifetime for the agent registration. Defaults to . /// An that can be used to further configure the agent. public static IHostedAgentBuilder AddAsAIAgent(this IHostedWorkflowBuilder builder, ServiceLifetime lifetime = ServiceLifetime.Singleton) => builder.AddAsAIAgent(name: null, lifetime: lifetime); /// /// 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. /// The DI service lifetime for the agent registration. Defaults to . /// An that can be used to further configure the agent. public static IHostedAgentBuilder AddAsAIAgent(this IHostedWorkflowBuilder builder, string? name, ServiceLifetime lifetime = ServiceLifetime.Singleton) { var workflowName = builder.Name; var agentName = name ?? workflowName; return builder.HostApplicationBuilder.AddAIAgent(agentName, (sp, key) => sp.GetRequiredKeyedService(workflowName).AsAIAgent(name: key), lifetime); } }