Usage support
✔️ (GA) indicates general availability, ✔️ (Preview) indicates public preview, and a dash (-) indicates the feature isn’t available.| Microsoft Foundry support | Python SDK | C# SDK | JavaScript SDK | Java SDK | REST API | Basic agent setup | Standard agent setup |
|---|---|---|---|---|---|---|---|
| ✔️ | ✔️ (GA) | ✔️ (Preview) | ✔️ (GA) | ✔️ (Preview) | ✔️ (GA) | ✔️ | ✔️ |
Prerequisites
Estimated setup time: 15-30 minutes if you have an existing search index- A basic or standard agent environment.
- Install the SDK package for your preferred language. C# and Java require the prerelease version. See the quickstart for details.
- Python:
pip install "azure-ai-projects>=2.0.0" - C#: Install the
Azure.AI.ProjectsNuGet package (prerelease) - JavaScript/TypeScript:
npm install @azure/ai-projects - Java: Add the
com.azure:azure-ai-agents:2.0.0-beta.1dependency to yourpom.xml
- Python:
- An Azure subscription and Microsoft Foundry project with:
- Project endpoint
- Model deployment name
- Authentication configured (for example,
DefaultAzureCredential)
- An Azure AI Search index configured for vector search with:
- One or more
Edm.Stringfields that are searchable and retrievable - One or more
Collection(Edm.Single)vector fields that are searchable - At least one retrievable text field that contains the content you want the agent to cite
- A retrievable field that contains a source URL (and optionally a title) so citations can include a link
- One or more
- A connection between your Foundry project and your Azure AI Search service (see Setup).
- For keyless authentication, assign the following Azure role-based access control (RBAC) roles to your project’s managed identity:
- Search Index Data Contributor
- Search Service Contributor
Configure tool parameters
| Azure AI Search tool parameter | Required | Notes |
|---|---|---|
project_connection_id | Yes | The resource ID of the project connection to Azure AI Search. |
index_name | Yes | The name of the index in your Azure AI Search resource. |
top_k | No | Defaults to 5. |
query_type | No | Defaults to vector_semantic_hybrid. Supported values: simple, vector, semantic, vector_simple_hybrid, vector_semantic_hybrid. |
filter | No | Applies to all queries the agent makes to the index. |
Code example
- You need the latest SDK package. C# and Java require the prerelease version. For more information, see the quickstart.
- If you’re using the REST sample, the connection ID is in the format
/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.CognitiveServices/accounts/{{foundryAccountName}}/projects/{{foundryProjectName}}/connections/{{connectionName}}. - If you’re using the Python, C#, or TypeScript sample, you can provide the connection name and retrieve the connection ID with the SDK.
Expected outcome
The agent queries the search index and returns a response with inline citations. Console output shows the agent ID, streaming delta updates as the response generates, URL citations with start and end indices, and the final complete response text. The agent is then successfully deleted.Full sample
The following sample code shows synchronous examples of how to use the Azure AI Search tool in Azure.AI.Projects.OpenAI to query an index. For asynchronous C# examples, see the GitHub repo. This example shows how to use the Azure AI Search tool with agents to query an index.Expected outcome
The agent queries the specified index for information about the sleeping bag. The response includes the temperature rating and a formatted citation with the document title and URL. The response status isCompleted, and the agent version is successfully deleted.
Use agents with Azure AI Search tool for streaming scenarios
This example shows how to use the Azure AI Search tool with agents to query an index in a streaming scenario.Expected outcome
The streaming response displays the agent’s response creation, text deltas as they stream in real-time, and a formatted citation when complete. The final output includes the sleeping bag temperature rating with document reference. The agent version is deleted after the query completes.Use agents with Azure AI Search tool
The following example shows how to use the Azure AI Search tool with the REST API to query an index. The example uses cURL, but you can use any HTTP client. Before running this sample, obtain a bearer token for authentication. Use the Azure CLI to get a token:Expected outcome
The API returns a JSON response containing the agent’s answer about mental health services from the Premera index. The response includes citations and references to the indexed documents that generated the answer. This sample demonstrates how to create an AI agent with Azure AI Search capabilities by using theAzureAISearchAgentTool and synchronous Azure AI Projects client. The agent can search indexed content and provide responses with citations from search results.
Expected outcome
The application creates an agent with Azure AI Search capabilities, prompts for user input, queries the search index, and streams the response with real-time delta updates. Console output includes the agent ID, streaming text deltas, URL citations with indices, and confirmation of successful agent deletion. The agent provides answers grounded in the indexed content with proper citations.Use Azure AI Search in a Java agent
Add the dependency to yourpom.xml:
Create an agent with Azure AI Search
Limitations
Keep these constraints in mind when using the Azure AI Search tool:- Virtual network access: Azure AI Search doesn’t support virtual network (vNET) configurations with agents at this time.
- The Azure AI Search tool can only target one index.
- Your Azure AI Search resource and your Microsoft Foundry Agent must be in the same tenant.
Verify results
After you run a sample, validate that the agent is grounding responses from your index.- Ask a question that you know is answered in a specific indexed document.
- Confirm the response includes citations formatted as
[message_idx:search_idx†source]. - If you’re streaming, confirm you see
url_citationannotations in the response with valid URLs. - Verify the cited content matches your source documents in the search index.
Setup
In this section, you create a connection between the Microsoft Foundry project that contains your agent and the Azure AI Search service that contains your index. If you already connected your project to your search service, skip this section. To create the connection, you need your search service endpoint and authentication method. The following steps guide you through gathering these details.Gather connection details
Before creating a project connection, gather your Azure AI Search service endpoint and authentication credentials. The project connection requires the endpoint of your search service and either key-based authentication or keyless authentication with Microsoft Entra ID. For keyless authentication, you must enable role-based access control (RBAC) and assign roles to your project’s managed identity. Although this method involves extra steps, it enhances security by eliminating the need for hard-coded API keys. Select the tab for your desired authentication method.- Key-based authentication
- Keyless authentication
- Sign in to the Azure portal and select your search service.
- To get the endpoint:
- From the left pane, select Overview.
- Make a note of the URL, which should look like
https://my-service.search.windows.net.

- To get the API key:
- From the left pane, select Settings > Keys.
- Select Both to enable both key-based and keyless authentication, which is recommended for most scenarios.

- Make a note of one of the keys under Manage admin keys.
Create a project connection
Create the project connection by using the search service details you gathered. Use one of the following options.- Foundry portal
- Azure CLI
- Python SDK
- REST API
- Bicep
- Go to the Foundry portal.
- Open your project, then select Operate > Admin.
- Select your project name in the Manage all projects list.
- Select Add connection.
- Select Azure AI Search from the list of available services.
- Browse for and select your Azure AI Search service, then select the type of Authentication to use.
- Select Add connection.
Confirm the connection ID
If you use the REST or TypeScript sample, you need the project connection ID. PythonTroubleshooting
| Issue | Cause | Resolution |
|---|---|---|
| ”Workspace not found” when creating a connection | Incorrect --workspace-name or workspace_name value | The workspace name corresponds to your Foundry project name, not the Foundry resource name. Use the Foundry portal or REST API as alternatives. See Create a project connection. |
| Response has no citations | Agent instructions don’t request citations | Update your agent instructions to explicitly request citations in responses. |
| Response has no citations (streaming) | Annotations not captured | Confirm you receive url_citation annotations when streaming. Check your stream processing logic. |
| Tool can’t access the index (401/403) | Missing RBAC roles (keyless auth) | Assign the Search Index Data Contributor and Search Service Contributor roles to the Foundry project’s managed identity. See Azure RBAC in Foundry. |
| Tool can’t access the index (401/403) | Invalid or disabled API key | Confirm the API key is correct and enabled in the Azure AI Search resource. |
| Tool returns “index not found” | Index name mismatch | Confirm the index name matches the exact index name in your Azure AI Search resource (case-sensitive). |
| Tool returns “index not found” | Wrong connection endpoint | Confirm the project connection points to the Azure AI Search resource that contains the index. |
| Search returns no results | Query doesn’t match indexed content | Verify the index contains the expected data. Use Azure AI Search’s test query feature to validate. |
| Slow search performance | Index not optimized | Review index configuration, consider adding semantic ranking, or optimize the index schema. |