// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Azure.AI.Projects.Agents;
using Microsoft.Extensions.AI;
using OpenAI.Responses;
#pragma warning disable OPENAI001
namespace Microsoft.Agents.AI.Foundry;
///
/// Provides factory methods for creating instances from Microsoft Foundry and OpenAI response tools.
///
///
///
/// This class wraps (Azure.AI.Projects.Agents) and (OpenAI SDK) factory methods,
/// returning directly — eliminating the need for manual casting and .AsAITool() calls.
///
///
/// Instead of writing:
/// ((ResponseTool)ProjectsAgentTool.CreateOpenApiTool(definition)).AsAITool()
/// You can write:
/// FoundryAITool.CreateOpenApiTool(definition)
///
///
public static class FoundryAITool
{
///
/// Converts an existing into an .
///
/// The response tool to convert.
/// An wrapping the provided response tool.
public static AITool FromResponseTool(ResponseTool responseTool) => responseTool.AsAITool();
// --- Azure.AI.Projects.OpenAI ProjectsAgentTool factories ---
///
/// Creates an for OpenAPI tool invocations.
///
/// The OpenAPI function definition specifying the API endpoint, schema, and authentication.
/// An that calls the specified OpenAPI endpoint.
public static AITool CreateOpenApiTool(OpenApiFunctionDefinition definition)
=> ((ResponseTool)ProjectsAgentTool.CreateOpenApiTool(definition)).AsAITool();
///
/// Creates an for Bing Grounding search.
///
/// The Bing Grounding search configuration options.
/// An for Bing Grounding search.
public static AITool CreateBingGroundingTool(BingGroundingSearchToolOptions options)
=> ((ResponseTool)ProjectsAgentTool.CreateBingGroundingTool(options)).AsAITool();
///
/// Creates an for Bing Custom Search.
///
/// The Bing Custom Search configuration parameters.
/// An for Bing Custom Search.
public static AITool CreateBingCustomSearchTool(BingCustomSearchToolOptions parameters)
=> ((ResponseTool)ProjectsAgentTool.CreateBingCustomSearchTool(parameters)).AsAITool();
///
/// Creates an for Microsoft Fabric data agent.
///
/// The Fabric data agent configuration options.
/// An for Microsoft Fabric.
public static AITool CreateMicrosoftFabricTool(FabricDataAgentToolOptions options)
=> ((ResponseTool)ProjectsAgentTool.CreateMicrosoftFabricTool(options)).AsAITool();
///
/// Creates an for SharePoint grounding.
///
/// The SharePoint grounding configuration options.
/// An for SharePoint grounding.
public static AITool CreateSharepointTool(SharePointGroundingToolOptions options)
=> ((ResponseTool)ProjectsAgentTool.CreateSharepointTool(options)).AsAITool();
///
/// Creates an for Azure AI Search.
///
/// Optional Azure AI Search configuration options.
/// An for Azure AI Search.
public static AITool CreateAzureAISearchTool(AzureAISearchToolOptions? options = null)
=> ((ResponseTool)ProjectsAgentTool.CreateAzureAISearchTool(options)).AsAITool();
///
/// Creates an for browser automation.
///
/// The browser automation configuration parameters.
/// An for browser automation.
public static AITool CreateBrowserAutomationTool(BrowserAutomationToolOptions parameters)
=> ((ResponseTool)ProjectsAgentTool.CreateBrowserAutomationTool(parameters)).AsAITool();
///
/// Creates an for structured output capture.
///
/// The structured output definition.
/// An for structured output capture.
public static AITool CreateStructuredOutputsTool(StructuredOutputDefinition outputs)
=> ((ResponseTool)ProjectsAgentTool.CreateStructuredOutputsTool(outputs)).AsAITool();
///
/// Creates an for Agent-to-Agent (A2A) communication.
///
/// The base URI for the A2A agent.
/// Optional path to the agent card.
/// An for A2A communication.
public static AITool CreateA2ATool(Uri baseUri, string? agentCardPath = null)
=> ProjectsAgentTool.CreateA2ATool(baseUri, agentCardPath).AsAITool();
///
/// Creates an marker that references a Foundry Toolbox by name so
/// the hosted server side can resolve and expose its MCP tools for a single request.
///
/// The Foundry toolbox name.
/// Optional pinned toolbox version. When , the project's default version is used.
/// An marker backed by .
public static AITool CreateHostedMcpToolbox(string toolboxName, string? version = null)
=> new HostedMcpToolboxAITool(toolboxName, version);
// --- OpenAI SDK ResponseTool factories ---
///
/// Creates an for computer use (screen interaction).
///
/// The computer tool environment type.
/// The display width in pixels.
/// The display height in pixels.
/// An for computer use.
[Experimental("OPENAICUA001")]
public static AITool CreateComputerTool(ComputerToolEnvironment environment, int displayWidth, int displayHeight)
=> ResponseTool.CreateComputerTool(environment, displayWidth, displayHeight).AsAITool();
///
/// Creates an for function tool invocations.
///
/// The name of the function.
/// The function parameters schema as JSON.
/// Whether strict mode is enabled for parameter validation.
/// Optional description of the function.
/// An for function invocations.
public static AITool CreateFunctionTool(string functionName, BinaryData functionParameters, bool? strictModeEnabled, string? functionDescription = null)
=> ResponseTool.CreateFunctionTool(functionName, functionParameters, strictModeEnabled, functionDescription).AsAITool();
///
/// Creates an for file search over vector stores.
///
/// The IDs of vector stores to search.
/// Optional maximum number of results to return.
/// Optional ranking options for search results.
/// Optional filters for search results.
/// An for file search.
public static AITool CreateFileSearchTool(IEnumerable vectorStoreIds, int? maxResultCount = null, FileSearchToolRankingOptions? rankingOptions = null, BinaryData? filters = null)
=> ResponseTool.CreateFileSearchTool(vectorStoreIds, maxResultCount, rankingOptions, filters).AsAITool();
///
/// Creates an for web search.
///
/// Optional user location for search context.
/// Optional search context size.
/// Optional search filters.
/// An for web search.
public static AITool CreateWebSearchTool(WebSearchToolLocation? userLocation = null, WebSearchToolContextSize? searchContextSize = null, WebSearchToolFilters? filters = null)
=> ResponseTool.CreateWebSearchTool(userLocation, searchContextSize, filters).AsAITool();
///
/// Creates an for MCP (Model Context Protocol) server tools.
///
/// The label for the MCP server.
/// The URI of the MCP server.
/// Optional authorization token.
/// Optional server description.
/// Optional custom headers.
/// Optional filter for allowed tools.
/// Optional tool call approval policy.
/// An for MCP server tools.
public static AITool CreateMcpTool(string serverLabel, Uri serverUri, string? authorizationToken = null, string? serverDescription = null, IDictionary? headers = null, McpToolFilter? allowedTools = null, McpToolCallApprovalPolicy? toolCallApprovalPolicy = null)
=> ResponseTool.CreateMcpTool(serverLabel, serverUri, authorizationToken, serverDescription, headers, allowedTools, toolCallApprovalPolicy).AsAITool();
///
/// Creates an for MCP (Model Context Protocol) server tools using a connector ID.
///
/// The label for the MCP server.
/// The connector ID for the MCP server.
/// Optional authorization token.
/// Optional server description.
/// Optional custom headers.
/// Optional filter for allowed tools.
/// Optional tool call approval policy.
/// An for MCP server tools.
public static AITool CreateMcpTool(string serverLabel, McpToolConnectorId connectorId, string? authorizationToken = null, string? serverDescription = null, IDictionary? headers = null, McpToolFilter? allowedTools = null, McpToolCallApprovalPolicy? toolCallApprovalPolicy = null)
=> ResponseTool.CreateMcpTool(serverLabel, connectorId, authorizationToken, serverDescription, headers, allowedTools, toolCallApprovalPolicy).AsAITool();
///
/// Creates an for code interpreter.
///
/// The container configuration for the code interpreter.
/// An for code interpreter.
public static AITool CreateCodeInterpreterTool(CodeInterpreterToolContainer container)
=> ResponseTool.CreateCodeInterpreterTool(container).AsAITool();
///
/// Creates an for image generation.
///
/// The model to use for image generation.
/// Optional image quality setting.
/// Optional image size setting.
/// Optional output file format.
/// Optional output compression factor.
/// Optional moderation level.
/// Optional background setting.
/// Optional input fidelity setting.
/// Optional input image mask.
/// Optional partial image count.
/// An for image generation.
public static AITool CreateImageGenerationTool(string model, ImageGenerationToolQuality? quality = null, ImageGenerationToolSize? size = null, ImageGenerationToolOutputFileFormat? outputFileFormat = null, int? outputCompressionFactor = null, ImageGenerationToolModerationLevel? moderationLevel = null, ImageGenerationToolBackground? background = null, ImageGenerationToolInputFidelity? inputFidelity = null, ImageGenerationToolInputImageMask? inputImageMask = null, int? partialImageCount = null)
=> ResponseTool.CreateImageGenerationTool(model, quality, size, outputFileFormat, outputCompressionFactor, moderationLevel, background, inputFidelity, inputImageMask, partialImageCount).AsAITool();
}