# PromptAgentBuilderExtensions Methods

- Package: [Aspire.Hosting.Foundry](/reference/api/csharp/aspire.hosting.foundry.md)
- Type: [PromptAgentBuilderExtensions](/reference/api/csharp/aspire.hosting.foundry/promptagentbuilderextensions.md)
- Kind: `Methods`
- Members: `19`

Extension methods for adding Microsoft Foundry prompt agents and tools to the distributed application model.

## AddAISearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string?)

- Name: `AddAISearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureAISearchToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L302-L310)

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.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<AzureAISearchToolResource> AddAISearchTool(
        this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
        string name,
        string? indexName = null)
    {
        // ...
    }
}
```

## Parameters

- `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.

## Returns

`IResourceBuilder<AzureAISearchToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## Remarks

After creating the tool, call [PromptAgentBuilderExtensions.WithReference(IResourceBuilder<AzureAISearchToolResource>, IResourceBuilder<AzureSearchResource>)](/reference/api/csharp/aspire.hosting.foundry/promptagentbuilderextensions/methods.md#withreference-iresourcebuilder-azureaisearchtoolresource-iresourcebuilder-azuresearchresource) to link it to the backing Azure AI Search resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddAzureFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, string, BinaryData, string, string, string, string)

- Name: `AddAzureFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, string, BinaryData, string, string, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureFunctionToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L558-L565)

Adds an Azure Function tool to a Microsoft Foundry project, enabling agents to invoke a serverless Azure Function with queue-based input/output bindings.

```csharp
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)
    {
        // ...
    }
}
```

## Parameters

- `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.

## Returns

`IResourceBuilder<AzureFunctionToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddAzureFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, string, string, string, string, string, string)

- Name: `AddAzureFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, string, string, string, string, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureFunctionToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L596-L598)

Adds an Azure Function tool to a Microsoft Foundry project, enabling agents to invoke a serverless Azure Function with queue-based input/output bindings.

```csharp
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)
    {
        // ...
    }
}
```

## Parameters

- `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.

## Returns

`IResourceBuilder<AzureFunctionToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddBingGroundingTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string)

- Name: `AddBingGroundingTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<BingGroundingToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L365-L370)

Adds a Bing Grounding tool to a Microsoft Foundry project, enabling agents to ground their responses using Bing Search results.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<BingGroundingToolResource> AddBingGroundingTool(
        this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `project` (`IResourceBuilder<AzureCognitiveServicesProjectResource>`)
  The `ApplicationModel.IResourceBuilder`1` for the Microsoft Foundry project.
- `name` (`string`)
  The name of the tool resource.

## Returns

`IResourceBuilder<BingGroundingToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## Remarks

After creating the tool, call one of the `WithReference` overloads to link it to a Bing Search resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddCodeInterpreterTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string)

- Name: `AddCodeInterpreterTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<CodeInterpreterToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L170-L175)

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.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<CodeInterpreterToolResource> AddCodeInterpreterTool(
        this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `project` (`IResourceBuilder<AzureCognitiveServicesProjectResource>`)
  The `ApplicationModel.IResourceBuilder`1` for the Microsoft Foundry project.
- `name` (`string`)
  The name of the tool resource.

## Returns

`IResourceBuilder<CodeInterpreterToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddComputerUseTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, int, int, string)

- Name: `AddComputerUseTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, int, int, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ComputerToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L269-L274)

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.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<ComputerToolResource> AddComputerUseTool(
        this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
        string name,
        int displayWidth = 1024,
        int displayHeight = 768,
        string environment = "browser")
    {
        // ...
    }
}
```

## Parameters

- `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".

## Returns

`IResourceBuilder<ComputerToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddFabricTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[])

- Name: `AddFabricTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<FabricToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L520-L525)

Adds a Microsoft Fabric data agent tool to a Microsoft Foundry project, enabling agents to query data through Fabric data agents.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<FabricToolResource> AddFabricTool(
        this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
        string name,
        params string[] projectConnectionIds)
    {
        // ...
    }
}
```

## Parameters

- `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.

## Returns

`IResourceBuilder<FabricToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddFileSearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[])

- Name: `AddFileSearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<FileSearchToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L194-L202)

Adds a File Search tool to a Microsoft Foundry project, enabling agents to search uploaded files and proprietary documents using vector search.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<FileSearchToolResource> AddFileSearchTool(
        this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
        string name,
        params string[] vectorStoreIds)
    {
        // ...
    }
}
```

## Parameters

- `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.

## Returns

`IResourceBuilder<FileSearchToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, BinaryData, string?, bool?)

- Name: `AddFunctionTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string, BinaryData, string?, bool?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<FunctionToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L621-L627)

Adds a function calling tool to a Microsoft Foundry project, enabling agents to call application-defined functions with structured parameters.

```csharp
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)
    {
        // ...
    }
}
```

## Parameters

- `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.

## Returns

`IResourceBuilder<FunctionToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddImageGenerationTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string)

- Name: `AddImageGenerationTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ImageGenerationToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L241-L246)

Adds an Image Generation tool to a Microsoft Foundry project, enabling agents to generate and edit images.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<ImageGenerationToolResource> AddImageGenerationTool(
        this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `project` (`IResourceBuilder<AzureCognitiveServicesProjectResource>`)
  The `ApplicationModel.IResourceBuilder`1` for the Microsoft Foundry project.
- `name` (`string`)
  The name of the tool resource.

## Returns

`IResourceBuilder<ImageGenerationToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddPromptAgent(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, IResourceBuilder<FoundryDeploymentResource>, string?)

- Name: `AddPromptAgent(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, IResourceBuilder<FoundryDeploymentResource>, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzurePromptAgentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L66-L128)

Adds a prompt agent to a Microsoft Foundry project with the specified tools.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<AzurePromptAgentResource> AddPromptAgent(
        this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
        string name,
        IResourceBuilder<FoundryDeploymentResource> model,
        string? instructions = null)
    {
        // ...
    }
}
```

## Parameters

- `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.

## Returns

`IResourceBuilder<AzurePromptAgentResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the prompt agent resource.

## Remarks

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.

## Examples

```csharp
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);
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddSharePointTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[])

- Name: `AddSharePointTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<SharePointToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L496-L501)

Adds a SharePoint grounding tool to a Microsoft Foundry project, enabling agents to search data from SharePoint sites configured as Foundry project connections.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<SharePointToolResource> AddSharePointTool(
        this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
        string name,
        params string[] projectConnectionIds)
    {
        // ...
    }
}
```

## Parameters

- `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.

## Returns

`IResourceBuilder<SharePointToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddWebSearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string)

- Name: `AddWebSearchTool(IResourceBuilder<AzureCognitiveServicesProjectResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<WebSearchToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L219-L224)

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.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<WebSearchToolResource> AddWebSearchTool(
        this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `project` (`IResourceBuilder<AzureCognitiveServicesProjectResource>`)
  The `ApplicationModel.IResourceBuilder`1` for the Microsoft Foundry project.
- `name` (`string`)
  The name of the tool resource.

## Returns

`IResourceBuilder<WebSearchToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for the tool resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithCustomTool(IResourceBuilder<AzurePromptAgentResource>, IFoundryTool)

- Name: `WithCustomTool(IResourceBuilder<AzurePromptAgentResource>, IFoundryTool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzurePromptAgentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L676-L680)

Adds a custom tool implementation to a prompt agent using the [IFoundryTool](/reference/api/csharp/aspire.hosting.foundry/ifoundrytool.md) interface.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<AzurePromptAgentResource> WithCustomTool(
        this IResourceBuilder<AzurePromptAgentResource> builder,
        IFoundryTool tool)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzurePromptAgentResource>`)
  The prompt agent resource builder.
- `tool` ([IFoundryTool](/reference/api/csharp/aspire.hosting.foundry/ifoundrytool.md))
  The custom tool implementation.

## Returns

`IResourceBuilder<AzurePromptAgentResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining.

## Remarks

This is an advanced extensibility point for tools that don't fit the standard [FoundryToolResource](/reference/api/csharp/aspire.hosting.foundry/foundrytoolresource.md) model. For most scenarios, use the project-level `Add*Tool` methods and pass tool resources to [PromptAgentBuilderExtensions.AddPromptAgent(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, IResourceBuilder<FoundryDeploymentResource>, string?)](/reference/api/csharp/aspire.hosting.foundry/promptagentbuilderextensions/methods.md#addpromptagent-iresourcebuilder-azurecognitiveservicesprojectresource-string-iresourcebuilder-foundrydeploymentresource-string).

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithReference(IResourceBuilder<AzureAISearchToolResource>, IResourceBuilder<AzureSearchResource>)

- Name: `WithReference(IResourceBuilder<AzureAISearchToolResource>, IResourceBuilder<AzureSearchResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureAISearchToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L327-L344)

Links an Azure AI Search tool to a backing `Azure.AzureSearchResource`, creating the necessary Foundry project connection and role assignments.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<AzureAISearchToolResource> WithReference(
        this IResourceBuilder<AzureAISearchToolResource> tool,
        IResourceBuilder<AzureSearchResource> search)
    {
        // ...
    }
}
```

## Parameters

- `tool` (`IResourceBuilder<AzureAISearchToolResource>`)
  The Azure AI Search tool resource builder.
- `search` (`IResourceBuilder<AzureSearchResource>`)
  The Azure AI Search resource to use for grounding.

## Returns

`IResourceBuilder<AzureAISearchToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithReference(IResourceBuilder<BingGroundingToolResource>, IResourceBuilder<BingGroundingConnectionResource>)

- Name: `WithReference(IResourceBuilder<BingGroundingToolResource>, IResourceBuilder<BingGroundingConnectionResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<BingGroundingToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L389)

Links a Bing Grounding tool to a Foundry project connection for the Bing Search service.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<BingGroundingToolResource> WithReference(
        this IResourceBuilder<BingGroundingToolResource> tool,
        IResourceBuilder<BingGroundingConnectionResource> bingConnection)
    {
        // ...
    }
}
```

## Parameters

- `tool` (`IResourceBuilder<BingGroundingToolResource>`)
  The Bing Grounding tool resource builder.
- `bingConnection` (`IResourceBuilder<BingGroundingConnectionResource>`)
  The Bing grounding connection resource builder created by [AzureCognitiveServicesProjectConnectionsBuilderExtensions.AddBingGroundingConnection(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string)](/reference/api/csharp/aspire.hosting.foundry/azurecognitiveservicesprojectconnectionsbuilderextensions/methods.md#addbinggroundingconnection-iresourcebuilder-azurecognitiveservicesprojectresource-string-string) or [AzureCognitiveServicesProjectConnectionsBuilderExtensions.AddBingGroundingConnection(IResourceBuilder<AzureCognitiveServicesProjectResource>, string, string)](/reference/api/csharp/aspire.hosting.foundry/azurecognitiveservicesprojectconnectionsbuilderextensions/methods.md#addbinggroundingconnection-iresourcebuilder-azurecognitiveservicesprojectresource-string-string).

## Returns

`IResourceBuilder<BingGroundingToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithReference(IResourceBuilder<BingGroundingToolResource>, string)

- Name: `WithReference(IResourceBuilder<BingGroundingToolResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<BingGroundingToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs)

Links a Bing Grounding tool to a Bing Search resource by using its Azure resource ID.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<BingGroundingToolResource> WithReference(
        this IResourceBuilder<BingGroundingToolResource> tool,
        string bingResourceId)
    {
        // ...
    }
}
```

## Parameters

- `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}`).

## Returns

`IResourceBuilder<BingGroundingToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithReference(IResourceBuilder<BingGroundingToolResource>, IResourceBuilder<ParameterResource>)

- Name: `WithReference(IResourceBuilder<BingGroundingToolResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<BingGroundingToolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs)

Links a Bing Grounding tool to a Bing Search resource by using a parameter that contains its Azure resource ID.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<BingGroundingToolResource> WithReference(
        this IResourceBuilder<BingGroundingToolResource> tool,
        IResourceBuilder<ParameterResource> bingResourceId)
    {
        // ...
    }
}
```

## Parameters

- `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.

## Returns

`IResourceBuilder<BingGroundingToolResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithTool(IResourceBuilder<AzurePromptAgentResource>, IResourceBuilder<FoundryToolResource>)

- Name: `WithTool(IResourceBuilder<AzurePromptAgentResource>, IResourceBuilder<FoundryToolResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzurePromptAgentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L143-L149)

Adds a tool to a prompt agent.

```csharp
public static class PromptAgentBuilderExtensions
{
    public static IResourceBuilder<AzurePromptAgentResource> WithTool(
        this IResourceBuilder<AzurePromptAgentResource> agent,
        IResourceBuilder<FoundryToolResource> tool)
    {
        // ...
    }
}
```

## Parameters

- `agent` (`IResourceBuilder<AzurePromptAgentResource>`)
  The prompt agent resource builder.
- `tool` (`IResourceBuilder<FoundryToolResource>`)
  The tool resource to attach to this agent.

## Returns

`IResourceBuilder<AzurePromptAgentResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
