// Copyright (c) Microsoft. All rights reserved. using Microsoft.Agents.AI.DurableTask; using Microsoft.Azure.Functions.Worker; using Microsoft.DurableTask.Client; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.Agents.AI.Hosting.AzureFunctions; /// /// Extension methods for the class. /// public static class DurableTaskClientExtensions { /// /// Converts a to a durable agent proxy. /// /// The to convert. /// The for the current function invocation. /// The name of the agent. /// A durable agent proxy. /// Thrown when or is null. /// Thrown when is null or empty. /// /// Thrown when durable agents have not been configured on the service collection. /// /// /// Thrown when the agent has not been registered. /// public static AIAgent AsDurableAgentProxy( this DurableTaskClient durableClient, FunctionContext context, string agentName) { ArgumentNullException.ThrowIfNull(durableClient); ArgumentNullException.ThrowIfNull(context); ArgumentException.ThrowIfNullOrEmpty(agentName); // Validate that the agent is registered DurableTask.ServiceCollectionExtensions.ValidateAgentIsRegistered(context.InstanceServices, agentName); DefaultDurableAgentClient agentClient = ActivatorUtilities.CreateInstance( context.InstanceServices, durableClient); return new DurableAIAgentProxy(agentName, agentClient); } }