Skip to content
DocsTry Aspire
DocsTry

PromptAgentBuilderExtensions Methods

ClassMethods19 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?)extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe name of the tool resource.
indexNamestring?optionalOptional 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)extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe name of the tool resource.
functionNamestringThe name of the Azure Function.
descriptionstringA description of what the function does.
parametersBinaryDataThe JSON schema defining the function parameters.
inputQueueEndpointstringThe Azure Storage Queue endpoint for input binding.
inputQueueNamestringThe queue name for input binding.
outputQueueEndpointstringThe Azure Storage Queue endpoint for output binding.
outputQueueNamestringThe 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)extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe name of the tool resource.
functionNamestringThe name of the Azure Function.
descriptionstringA description of what the function does.
parametersJsonstringThe JSON schema defining the function parameters as a JSON string.
inputQueueEndpointstringThe Azure Storage Queue endpoint for input binding.
inputQueueNamestringThe queue name for input binding.
outputQueueEndpointstringThe Azure Storage Queue endpoint for output binding.
outputQueueNamestringThe 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)extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe 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)extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe 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)extensionIResourceBuilder<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")
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe name of the tool resource.
displayWidthintoptionalThe width of the display in pixels.
displayHeightintoptionalThe height of the display in pixels.
environmentstringoptionalThe 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[])extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe name of the tool resource.
projectConnectionIdsstring[]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[])extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe name of the tool resource.
vectorStoreIdsstring[]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?)extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe name of the tool resource.
functionNamestringThe name of the function.
parametersBinaryDataThe JSON schema defining the function parameters.
descriptionstring?optionalA description of what the function does.
strictModeEnabledbool?optionalWhether 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)extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe 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?)extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the parent Microsoft Foundry project resource.
namestringThe name of the prompt agent. This will be the agent name in Foundry.
modelIResourceBuilder<FoundryDeploymentResource>The model deployment to use for this agent.
instructionsstring?optionalOptional 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[])extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe name of the tool resource.
projectConnectionIdsstring[]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)extensionIResourceBuilder<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)
{
// ...
}
}
projectIResourceBuilder<AzureCognitiveServicesProjectResource>The ApplicationModel.IResourceBuilder`1 for the Microsoft Foundry project.
namestringThe 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)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzurePromptAgentResource>The prompt agent resource builder.
toolIFoundryToolThe 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>)extensionIResourceBuilder<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)
{
// ...
}
}
toolIResourceBuilder<AzureAISearchToolResource>The Azure AI Search tool resource builder.
searchIResourceBuilder<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>)extensionIResourceBuilder<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)
{
// ...
}
}
toolIResourceBuilder<BingGroundingToolResource>The Bing Grounding tool resource builder.
bingConnectionIResourceBuilder<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)extensionIResourceBuilder<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)
{
// ...
}
}
toolIResourceBuilder<BingGroundingToolResource>The Bing Grounding tool resource builder.
bingResourceIdstring 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>)extensionIResourceBuilder<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)
{
// ...
}
}
toolIResourceBuilder<BingGroundingToolResource>The Bing Grounding tool resource builder.
bingResourceIdIResourceBuilder<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>)extensionIResourceBuilder<AzurePromptAgentResource>
Adds a tool to a prompt agent.
public static class PromptAgentBuilderExtensions
{
public static IResourceBuilder<AzurePromptAgentResource> WithTool(
this IResourceBuilder<AzurePromptAgentResource> agent,
IResourceBuilder<FoundryToolResource> tool)
{
// ...
}
}
agentIResourceBuilder<AzurePromptAgentResource>The prompt agent resource builder.
toolIResourceBuilder<FoundryToolResource>The tool resource to attach to this agent.
IResourceBuilder<AzurePromptAgentResource>A reference to the ApplicationModel.IResourceBuilder`1 for chaining.