@@ -351,6 +351,63 @@ async def main():
351351asyncio.run(main())
352352```
353353
354+ ### File Search
355+
356+ Enable your agent to search through uploaded documents and files:
357+
358+ ``` python
359+ import asyncio
360+ from agent_framework import ChatAgent, HostedFileSearchTool, HostedVectorStoreContent
361+ from agent_framework.azure import AzureOpenAIResponsesClient
362+ from azure.identity import AzureCliCredential
363+
364+ async def create_vector_store (client : AzureOpenAIResponsesClient) -> tuple[str , HostedVectorStoreContent]:
365+ """ Create a vector store with sample documents."""
366+ file = await client.client.files.create(
367+ file = (" todays_weather.txt" , b " The weather today is sunny with a high of 75F." ),
368+ purpose = " assistants"
369+ )
370+ vector_store = await client.client.vector_stores.create(
371+ name = " knowledge_base" ,
372+ expires_after = {" anchor" : " last_active_at" , " days" : 1 },
373+ )
374+ result = await client.client.vector_stores.files.create_and_poll(
375+ vector_store_id = vector_store.id,
376+ file_id = file .id
377+ )
378+ if result.last_error is not None :
379+ raise Exception (f " Vector store file processing failed with status: { result.last_error.message} " )
380+
381+ return file .id, HostedVectorStoreContent(vector_store_id = vector_store.id)
382+
383+ async def delete_vector_store (client : AzureOpenAIResponsesClient, file_id : str , vector_store_id : str ) -> None :
384+ """ Delete the vector store after using it."""
385+ await client.client.vector_stores.delete(vector_store_id = vector_store_id)
386+ await client.client.files.delete(file_id = file_id)
387+
388+ async def main ():
389+ print (" === Azure OpenAI Responses Client with File Search Example ===\n " )
390+
391+ # Initialize Responses client
392+ client = AzureOpenAIResponsesClient(credential = AzureCliCredential())
393+
394+ file_id, vector_store = await create_vector_store(client)
395+
396+ async with ChatAgent(
397+ chat_client = client,
398+ instructions = " You are a helpful assistant that can search through files to find information." ,
399+ tools = [HostedFileSearchTool(inputs = vector_store)],
400+ ) as agent:
401+ query = " What is the weather today? Do a file search to find the answer."
402+ print (f " User: { query} " )
403+ result = await agent.run(query)
404+ print (f " Agent: { result} \n " )
405+
406+ await delete_vector_store(client, file_id, vector_store.vector_store_id)
407+
408+ asyncio.run(main())
409+ ```
410+
354411### Model Context Protocol (MCP) Tools
355412
356413#### Local MCP Tools
0 commit comments