Files
agent-framework/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/DefaultFunctionsAgentOptionsProvider.cs
Shyju Krishnankutty 49d69b3bf5 .NET: Expose workflows as MCP tools when hosting on Azure functions (#4768)
* Expose workflow as MCP Tool

* Expose workflow as MCP Tool

* Cleanup

* PR feedback fixes

* update changelog to include PR numner

* Improvements to error handling.

* Adding a sample project demonstrating how to setup Agents and Workflows together.

* Ensure duplicate agent registrations are properly handled.
2026-03-25 15:43:15 +00:00

34 lines
1.7 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Diagnostics.CodeAnalysis;
namespace Microsoft.Agents.AI.Hosting.AzureFunctions;
/// <summary>
/// Provides access to agent-specific options for functions agents by name.
/// Returns <see langword="false"/> when no explicit options have been configured for an agent,
/// which distinguishes standalone agents from those auto-registered by workflows.
/// </summary>
internal sealed class DefaultFunctionsAgentOptionsProvider(IReadOnlyDictionary<string, FunctionsAgentOptions> functionsAgentOptions)
: IFunctionsAgentOptionsProvider
{
private readonly IReadOnlyDictionary<string, FunctionsAgentOptions> _functionsAgentOptions =
functionsAgentOptions ?? throw new ArgumentNullException(nameof(functionsAgentOptions));
/// <summary>
/// Attempts to retrieve the options associated with the specified agent name.
/// Returns <see langword="false"/> when no options have been explicitly configured for the agent.
/// </summary>
/// <param name="agentName">The name of the agent whose options are to be retrieved. Cannot be null or empty.</param>
/// <param name="options">
/// When this method returns <see langword="true"/>, contains the options for the specified agent;
/// otherwise, <see langword="null"/>.
/// </param>
/// <returns><see langword="true"/> if options were found for the agent; otherwise, <see langword="false"/>.</returns>
public bool TryGet(string agentName, [NotNullWhen(true)] out FunctionsAgentOptions? options)
{
ArgumentException.ThrowIfNullOrEmpty(agentName);
return this._functionsAgentOptions.TryGetValue(agentName, out options);
}
}