// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Agents.AI.Foundry.Hosting;
using Microsoft.Extensions.AI;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;
#pragma warning disable OPENAI001
#pragma warning disable AAIP001 // AgentToolboxes is experimental in Azure.AI.Projects.Agents
namespace Azure.AI.Projects;
///
/// Provides extension methods on for fetching
/// Foundry toolbox definitions as server-side tools.
///
///
/// These extensions mirror Python's FoundryChatClient.get_toolbox() pattern,
/// allowing a single call on the project client to retrieve tools ready for use
/// with AsAIAgent(model, instructions, tools: ...).
///
[Experimental(DiagnosticIds.Experiments.AIOpenAIResponses)]
public static class AIProjectClientToolboxExtensions
{
///
/// Fetches a toolbox from the Foundry project and returns its tools as instances
/// ready for use as server-side tools in the Responses API.
///
/// The to use. Cannot be .
/// The name of the toolbox to fetch.
///
/// The specific toolbox version to fetch. When , the toolbox's
/// default version is resolved automatically.
///
/// A token to monitor for cancellation requests.
/// A read-only list of instances from the toolbox.
///
/// Thrown when or is .
///
public static async Task> GetToolboxToolsAsync(
this AIProjectClient projectClient,
string name,
string? version = null,
CancellationToken cancellationToken = default)
{
Throw.IfNull(projectClient);
Throw.IfNullOrWhitespace(name);
var toolboxClient = projectClient.AgentAdministrationClient.GetAgentToolboxes();
var toolboxVersion = await FoundryToolbox.GetToolboxVersionCoreAsync(toolboxClient, name, version, cancellationToken).ConfigureAwait(false);
return toolboxVersion.ToAITools();
}
}