Skip to content
Docs Try Aspire
Docs Try

PromptAgentBuilderExtensions Methods

Class Methods 19 members
Extension methods for adding Microsoft Foundry prompt agents and tools to the distributed application model.
AddAISearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string?) Section titled AddAISearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string?) extension IResourceBuilder<AzureAISearchToolResource>
Adds an Azure AI Search tool to a Microsoft Foundry project, enabling agents to ground their responses using data from an Azure AI Search index.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<AzureAISearchToolResource> AddAISearchTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
string? indexName = null)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
indexName string? optional Optional name of the search index to query. If not specified, the agent must be told which index to use.
IResourceBuilder<AzureAISearchToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
After creating the tool, call PromptAgentBuilderExtensions.WithReference to link it to the backing Azure AI Search resource.
AddAzureFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, string, BinaryData, string, string, string, string) Section titled AddAzureFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, string, BinaryData, string, string, string, string) extension IResourceBuilder<AzureFunctionToolResource>
Adds an Azure Function tool to a Microsoft Foundry project, enabling agents to invoke a serverless Azure Function with queue-based input/output bindings.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<AzureFunctionToolResource> AddAzureFunctionTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
string functionName,
string description,
BinaryData parameters,
string inputQueueEndpoint,
string inputQueueName,
string outputQueueEndpoint,
string outputQueueName)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
functionName string The name of the Azure Function.
description string A description of what the function does.
parameters BinaryData The JSON schema defining the function parameters.
inputQueueEndpoint string The Azure Storage Queue endpoint for input binding.
inputQueueName string The queue name for input binding.
outputQueueEndpoint string The Azure Storage Queue endpoint for output binding.
outputQueueName string The queue name for output binding.
IResourceBuilder<AzureFunctionToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
AddAzureFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, string, string, string, string, string, string) Section titled AddAzureFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, string, string, string, string, string, string) extension IResourceBuilder<AzureFunctionToolResource>
Adds an Azure Function tool to a Microsoft Foundry project, enabling agents to invoke a serverless Azure Function with queue-based input/output bindings.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<AzureFunctionToolResource> AddAzureFunctionTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
string functionName,
string description,
string parametersJson,
string inputQueueEndpoint,
string inputQueueName,
string outputQueueEndpoint,
string outputQueueName)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
functionName string The name of the Azure Function.
description string A description of what the function does.
parametersJson string The JSON schema defining the function parameters as a JSON string.
inputQueueEndpoint string The Azure Storage Queue endpoint for input binding.
inputQueueName string The queue name for input binding.
outputQueueEndpoint string The Azure Storage Queue endpoint for output binding.
outputQueueName string The queue name for output binding.
IResourceBuilder<AzureFunctionToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
AddBingGroundingTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string) Section titled AddBingGroundingTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string) extension IResourceBuilder<BingGroundingToolResource>
Adds a Bing Grounding tool to a Microsoft Foundry project, enabling agents to ground their responses using Bing Search results.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<BingGroundingToolResource> AddBingGroundingTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
IResourceBuilder<BingGroundingToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
After creating the tool, call one of the WithReference overloads to link it to a Bing Search resource.
AddCodeInterpreterTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string) Section titled AddCodeInterpreterTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string) extension IResourceBuilder<CodeInterpreterToolResource>
Adds a Code Interpreter tool to a Microsoft Foundry project, enabling agents to write and run Python code in a sandboxed environment for data analysis, math, and chart generation.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<CodeInterpreterToolResource> AddCodeInterpreterTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
IResourceBuilder<CodeInterpreterToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
AddComputerUseTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, int, int, string) Section titled AddComputerUseTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, int, int, string) extension IResourceBuilder<ComputerToolResource>
Adds a Computer Use tool to a Microsoft Foundry project, enabling agents to interact with a computer desktop by taking screenshots, moving the mouse, clicking, and typing.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<ComputerToolResource> AddComputerUseTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
int displayWidth = 1024,
int displayHeight = 768,
string environment = "browser")
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
displayWidth int optional The width of the display in pixels.
displayHeight int optional The height of the display in pixels.
environment string optional The environment identifier. Defaults to "browser".
IResourceBuilder<ComputerToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
AddFabricTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[]) Section titled AddFabricTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[]) extension IResourceBuilder<FabricToolResource>
Adds a Microsoft Fabric data agent tool to a Microsoft Foundry project, enabling agents to query data through Fabric data agents.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<FabricToolResource> AddFabricTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
params string[] projectConnectionIds)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
projectConnectionIds string[] The Foundry project connection IDs for the Fabric data agents.
IResourceBuilder<FabricToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
AddFileSearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[]) Section titled AddFileSearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[]) extension IResourceBuilder<FileSearchToolResource>
Adds a File Search tool to a Microsoft Foundry project, enabling agents to search uploaded files and proprietary documents using vector search.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<FileSearchToolResource> AddFileSearchTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
params string[] vectorStoreIds)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
vectorStoreIds string[] Optional vector store IDs to search. If empty, the agent's default stores are used.
IResourceBuilder<FileSearchToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
AddFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, BinaryData, string?, bool?) Section titled AddFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, BinaryData, string?, bool?) extension IResourceBuilder<FunctionToolResource>
Adds a function calling tool to a Microsoft Foundry project, enabling agents to call application-defined functions with structured parameters.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<FunctionToolResource> AddFunctionTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
string functionName,
BinaryData parameters,
string? description = null,
bool? strictModeEnabled = null)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
functionName string The name of the function.
parameters BinaryData The JSON schema defining the function parameters.
description string? optional A description of what the function does.
strictModeEnabled bool? optional Whether to enable strict mode for parameter validation.
IResourceBuilder<FunctionToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
AddImageGenerationTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string) Section titled AddImageGenerationTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string) extension IResourceBuilder<ImageGenerationToolResource>
Adds an Image Generation tool to a Microsoft Foundry project, enabling agents to generate and edit images.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<ImageGenerationToolResource> AddImageGenerationTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
IResourceBuilder<ImageGenerationToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
AddPromptAgent(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, IResourceBuilder<FoundryDeploymentResource>, string?) Section titled AddPromptAgent(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, IResourceBuilder<FoundryDeploymentResource>, string?) extension IResourceBuilder<AzurePromptAgentResource>
Adds a prompt agent to a Microsoft Foundry project with the specified tools.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<AzurePromptAgentResource> AddPromptAgent(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
IResourceBuilder<FoundryDeploymentResource> model,
string? instructions = null)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the parent Microsoft Foundry project resource.
name string The name of the prompt agent. This will be the agent name in Foundry.
model IResourceBuilder<FoundryDeploymentResource> The model deployment to use for this agent.
instructions string? optional Optional system instructions for the agent.
IResourceBuilder<AzurePromptAgentResource> A reference to the ApplicationModel.IResourceBuilder`1 for the prompt agent resource.

Prompt agents are always deployed to Azure Foundry, even during local development ( aspire run). Local services communicate with the cloud-provisioned agent using the project endpoint and agent name injected as environment variables.

Tools are project-level resources created with Add*Tool methods and can be reused across multiple agents in the same project.

var foundry = builder.AddFoundry("aif");
var project = foundry.AddProject("proj");
var chat = project.AddModelDeployment("gpt41", FoundryModel.OpenAI.Gpt41);
var bing = project.AddBingGroundingTool("bing").WithReference(bingConnection);
var aiSearch = project.AddAISearchTool("search").WithReference(searchResource);
var codeInterp = project.AddCodeInterpreterTool("code-interp");
project.AddPromptAgent("joker-agent", chat,
instructions: "You are good at telling jokes.")
.WithTool(bing)
.WithTool(aiSearch)
.WithTool(codeInterp);
AddSharePointTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[]) Section titled AddSharePointTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[]) extension IResourceBuilder<SharePointToolResource>
Adds a SharePoint grounding tool to a Microsoft Foundry project, enabling agents to search data from SharePoint sites configured as Foundry project connections.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<SharePointToolResource> AddSharePointTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
params string[] projectConnectionIds)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
projectConnectionIds string[] The Foundry project connection IDs for the SharePoint sites.
IResourceBuilder<SharePointToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
AddWebSearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string) Section titled AddWebSearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string) extension IResourceBuilder<WebSearchToolResource>
Adds a Web Search tool to a Microsoft Foundry project, enabling agents to retrieve real-time information from the public web and return answers with inline citations.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<WebSearchToolResource> AddWebSearchTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name)
{
// ...
}
}
project IResourceBuilder<AzureCognitiveServicesProjectResource> The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
name string The name of the tool resource.
IResourceBuilder<WebSearchToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the tool resource.
WithCustomTool(IResourceBuilder<AzurePromptAgentResource>, IFoundryTool) Section titled WithCustomTool(IResourceBuilder<AzurePromptAgentResource>, IFoundryTool) extension IResourceBuilder<AzurePromptAgentResource>
Adds a custom tool implementation to a prompt agent using the IFoundryTool interface.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<AzurePromptAgentResource> WithCustomTool(
this IResourceBuilder<AzurePromptAgentResource> builder,
IFoundryTool tool)
{
// ...
}
}
builder IResourceBuilder<AzurePromptAgentResource> The prompt agent resource builder.
tool IFoundryTool The custom tool implementation.
IResourceBuilder<AzurePromptAgentResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
This is an advanced extensibility point for tools that don't fit the standard FoundryToolResource model. For most scenarios, use the project-level Add*Tool methods and pass tool resources to PromptAgentBuilderExtensions.AddPromptAgent.
WithReference(IResourceBuilder<AzureAISearchToolResource>, IResourceBuilder<AzureSearchResource>) Section titled WithReference(IResourceBuilder<AzureAISearchToolResource>, IResourceBuilder<AzureSearchResource>) extension IResourceBuilder<AzureAISearchToolResource>
Links an Azure AI Search tool to a backing Azure.AzureSearchResource, creating the necessary Foundry project connection and role assignments.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<AzureAISearchToolResource> WithReference(
this IResourceBuilder<AzureAISearchToolResource> tool,
IResourceBuilder<AzureSearchResource> search)
{
// ...
}
}
tool IResourceBuilder<AzureAISearchToolResource> The Azure AI Search tool resource builder.
search IResourceBuilder<AzureSearchResource> The Azure AI Search resource to use for grounding.
IResourceBuilder<AzureAISearchToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
WithReference(IResourceBuilder<BingGroundingToolResource>, IResourceBuilder<BingGroundingConnectionResource>) Section titled WithReference(IResourceBuilder<BingGroundingToolResource>, IResourceBuilder<BingGroundingConnectionResource>) extension IResourceBuilder<BingGroundingToolResource>
Links a Bing Grounding tool to a Foundry project connection for the Bing Search service.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<BingGroundingToolResource> WithReference(
this IResourceBuilder<BingGroundingToolResource> tool,
IResourceBuilder<BingGroundingConnectionResource> bingConnection)
{
// ...
}
}
tool IResourceBuilder<BingGroundingToolResource> The Bing Grounding tool resource builder.
bingConnection IResourceBuilder<BingGroundingConnectionResource> The Bing grounding connection resource builder created by AzureCognitiveServicesProjectConnectionsBuilderExtensions.AddBingGroundingConnection or AzureCognitiveServicesProjectConnectionsBuilderExtensions.AddBingGroundingConnection.
IResourceBuilder<BingGroundingToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
WithReference(IResourceBuilder<BingGroundingToolResource>, string) Section titled WithReference(IResourceBuilder<BingGroundingToolResource>, string) extension IResourceBuilder<BingGroundingToolResource>
Links a Bing Grounding tool to a Bing Search resource by using its Azure resource ID.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<BingGroundingToolResource> WithReference(
this IResourceBuilder<BingGroundingToolResource> tool,
string bingResourceId)
{
// ...
}
}
tool IResourceBuilder<BingGroundingToolResource> The Bing Grounding tool resource builder.
bingResourceId string The full Azure resource ID of the Bing Search resource (e.g., /subscriptions/{subId}/resourceGroups/{rg}/providers/Microsoft.Bing/accounts/{name}).
IResourceBuilder<BingGroundingToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
WithReference(IResourceBuilder<BingGroundingToolResource>, IResourceBuilder<ParameterResource>) Section titled WithReference(IResourceBuilder<BingGroundingToolResource>, IResourceBuilder<ParameterResource>) extension IResourceBuilder<BingGroundingToolResource>
Links a Bing Grounding tool to a Bing Search resource by using a parameter that contains its Azure resource ID.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<BingGroundingToolResource> WithReference(
this IResourceBuilder<BingGroundingToolResource> tool,
IResourceBuilder<ParameterResource> bingResourceId)
{
// ...
}
}
tool IResourceBuilder<BingGroundingToolResource> The Bing Grounding tool resource builder.
bingResourceId IResourceBuilder<ParameterResource> A parameter resource containing the full Azure resource ID of the Bing Search resource.
IResourceBuilder<BingGroundingToolResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
WithTool(IResourceBuilder<AzurePromptAgentResource>, IResourceBuilder<FoundryToolResource>) Section titled WithTool(IResourceBuilder<AzurePromptAgentResource>, IResourceBuilder<FoundryToolResource>) extension IResourceBuilder<AzurePromptAgentResource>
Adds a tool to a prompt agent.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<AzurePromptAgentResource> WithTool(
this IResourceBuilder<AzurePromptAgentResource> agent,
IResourceBuilder<FoundryToolResource> tool)
{
// ...
}
}
agent IResourceBuilder<AzurePromptAgentResource> The prompt agent resource builder.
tool IResourceBuilder<FoundryToolResource> The tool resource to attach to this agent.
IResourceBuilder<AzurePromptAgentResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.