An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
Thanks for your question!
You're working with Azure AI Foundry Agent Service and want to configure access to an Azure AI Search resource via a private endpoint, using a VM in SubnetA while the private endpoint resides in SubnetB of VNet1. You're aiming to use this setup as a knowledge source for an AI Agent and execute it from the VM using Python.
Azure AI Foundry supports private connectivity in two main ways:
1.Standard Agent Setup (Bring Your Own VNet)
- The agent runs inside your delegated subnet.
- It can directly reach services (like AI Search) via private endpoints.
2. Managed Private Endpoints (MPEs)
- Foundry can create a managed PE connection to your AI Search resource without you managing a BYO VNet.
- This is simpler if you don’t already need a custom VNet.
In your case, either works — but since you already have VNet1 and a VM, the Standard Agent Setup may give you more control, it allows full control over inbound/outbound traffic and supports secure access to private resources. Configurations Steps:
1.Networking
- Ensure SubnetA (VM) and SubnetB (PE) are in the same VNet, or if in different VNets, that VNet peering is configured.
- Disable public network access on your AI Search resource if you want to enforce PE-only access.
2.Private Endpoint for AI Search
- Create the PE in SubnetB using the AI Search Private Endpoint guide.
- Link a Private DNS Zone (
privatelink.search.windows.net) to VNet1 so your VM and Agent can resolve the private IP.
3.Agent Environment Setup
- Deploy your agent with the Standard VNet setup template.
- Delegate the agent’s subnet to
Microsoft.App/environment. - Ensure outbound traffic from the agent’s subnet can reach the AI Search PE.
- In your agent’s tool config, point to the AI Search private endpoint FQDN.
Important: The Agent, not the VM, queries AI Search. The VM only calls the Agent API. This means the Agent’s networking must be configured correctly.
4.Authentication & RBAC
- Assign the Agent’s Managed Identity or your VM’s service principal the Search Contributor (or higher) role on the AI Search resource.
- Without RBAC permissions, queries will fail even if networking is correct.
5.DNS & Connectivity Testing
From your VM in SubnetA:
nslookup <search-resource>.privatelink.search.windows.net
Should return the private IP.
You can also run:
curl https://<search-resource>.privatelink.search.windows.net
6.Running from the VM
Test Connectivity from VM → AI Search
Use the Azure Search SDK from your VM to confirm private endpoint resolution and connectivity:
from azure.search.documents import SearchClient
from azure.core.credentials import AzureKeyCredential
search_client = SearchClient(
endpoint="https://<your-search-service>.privatelink.search.windows.net",
index_name="your-index",
credential=AzureKeyCredential("<your-key>")
)
results = search_client.search("your query")
for result in results:
print(result)
Once your agent is deployed and networking is set up, you can call it from the VM using Python:
from azure.ai.foundry import FoundryClient
from azure.identity import DefaultAzureCredential
client = FoundryClient(
endpoint="https://<your-agent-endpoint>",
credential=DefaultAzureCredential()
)
response = client.agents.run_agent(
agent_id="your-agent-id",
input={"query": "What products are not in stock?"}
)
print(response)
If this works, your Agent’s networking and tool configuration are correct.
Limitations:
- Class A subnet support is limited to specific regions and may require allowlisting.
- Public access must be disabled on AI Search for full private endpoint enforcement.
- Agent subnet and PE subnet must be correctly delegated and isolated.
Helpful References:
1)https://learn.microsoft.com/en-us/azure/search/service-create-private-endpoint
2)https://learn.microsoft.com/en-us/azure/ai-foundry/agents/how-to/tools/azure-ai-search?tabs=azurecli
3)https://github.com/azure-ai-foundry/foundry-samples/blob/main/samples/microsoft/infrastructure-setup/15-private-network-standard-agent-setup/README.md
4)https://learn.microsoft.com/en-us/azure/ai-foundry/agents/how-to/virtual-networks
Please let me know if it works for you or if you any further question and feel free to accept this as an answer if this was helpful and upvote. Thank you for reaching out to the Microsoft QNA Portal. 😊