Azure foundry file search - setup and deploying as a remote agent (not ephemeral agent)
File search allow us to feed information into our model
In this implementation we are deploying agent in Azure Foundry and it uses chatgpt-5-mini. I created the file search manually. You agent can only have 1 index. File search is not RAG.
With RAG you use Azure AI Search. File search is pretty generic. It requires basic setup where you don't necessary have to create a storage account manually to host your file.
As you can see here, I am uploading zippolock product info and it automatically create an index and embedd the info for me. There are limits to the file that you will be uploading.
And then I save this as an agent as shown here :-
Ensuring we have the right pypi dependencies
dependencies = [
"agent-framework>=1.13.0",
"azure-ai-projects", # Main Azure Foundry SDK
"azure-identity", # For authentication
]
And then we can use the following code to query what is zippolock. The magic is to INSTRUCT the agent to call your filesearch toolbox with this command here :- "use myfilesearch toolbox and
find out what is zippolock?"
import asyncio
import httpx
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from agent_framework import MCPStreamableHTTPTool
from agent_framework_foundry import FoundryChatClient
# ── Configuration ─────────────────────────────────────────────────────────────
endpoint = "https://your-foundry-instance.services.ai.azure.com/api/projects/proj-default"
toolbox_name = "myfilesearch"
toolbox_version = "1"
model_deployment = "gpt-5.4-mini"
from urllib.parse import urlparse
_parsed = urlparse(endpoint)
toolbox_url = f"{endpoint.rstrip('/')}/toolboxes/{toolbox_name}/versions/{toolbox_version}/mcp?api-version=v1"
# ── Reusable functions (can be pulled into a hosted agent main.py) ────────────
# Toolbox MCP auth
class _ToolboxAuth(httpx.Auth):
"""Injects a fresh bearer token on every request."""
def __init__(self, token_provider):
self._get_token = token_provider
def auth_flow(self, request):
request.headers["Authorization"] = f"Bearer {self._get_token()}"
yield request
# [START msft_agentframework_toolbox]
_agent = None
_toolbox = None
async def create_agent_with_toolbox():
"""Create an Agent Framework agent wired to a Foundry toolbox via MCP."""
global _agent, _toolbox
credential = DefaultAzureCredential()
token_provider = get_bearer_token_provider(
credential, "https://ai.azure.com/.default"
)
http_client = httpx.AsyncClient(
auth=_ToolboxAuth(token_provider),
headers={"Foundry-Features": "Toolboxes=V1Preview"},
timeout=120.0,
)
_toolbox = MCPStreamableHTTPTool(
name=toolbox_name,
url=toolbox_url,
http_client=http_client,
load_prompts=False,
)
chat_client = FoundryChatClient(
project_endpoint=endpoint,
model=model_deployment,
credential=credential,
)
_agent = chat_client.as_agent(
name="toolbox-agent",
instructions="You are a helpful assistant with access to Azure AI Foundry toolbox tools.",
tools=[_toolbox],
)
async def call_agent_with_toolbox(user_input: str):
"""Send a message to the toolbox agent and print the response."""
response = await _agent.run(messages=user_input, stream=False)
print(response.text)
async def close_agent():
"""Close the toolbox MCP connection cleanly."""
if _toolbox:
await _toolbox.close()
# [END msft_agentframework_toolbox]
# ── Script entry point ────────────────────────────────────────────────────
async def main():
await create_agent_with_toolbox()
try:
await call_agent_with_toolbox("use myfilesearch toolbox and
find out what is zippolock?")
finally:
await close_agent()
asyncio.run(main())
And the output is :-
Comments