mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
5aa05ebe29
* .NET: Add File Search sample #3674 * Add FileSearch sample to solution and parent README - Add FoundryAgents_Step18_FileSearch to agent-framework-dotnet.slnx - Add FileSearch entry to FoundryAgents samples table in README.md - Fix README inaccuracy: sample creates one agent, not two Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Refactor FileSearch sample: local functions + DefaultAzureCredential - Refactor agent creation into switchable local functions - Use DefaultAzureCredential with WARNING comment (matching other samples) - Update README to reference DefaultAzureCredential Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix orphaned temp file in FileSearch sample Use Path.Combine + Path.GetRandomFileName instead of Path.GetTempFileName to avoid leaving an orphaned temp file on disk. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
5aa05ebe29
ยท
2026-02-19 10:36:43 +00:00
History
Using File Search with AI Agents
This sample demonstrates how to use the file search tool with AI agents. The file search tool allows agents to search through uploaded files stored in vector stores to answer user questions.
What this sample demonstrates
- Uploading files and creating vector stores
- Creating agents with file search capabilities
- Using HostedFileSearchTool (MEAI abstraction)
- Using native SDK file search tools (ResponseTool.CreateFileSearchTool)
- Handling file citation annotations
- Managing agent and resource lifecycle (creation and deletion)
Prerequisites
Before you begin, ensure you have the following prerequisites:
- .NET 10 SDK or later
- Azure Foundry service endpoint and deployment configured
- Azure CLI installed and authenticated (for Azure credential authentication)
Note: This demo uses DefaultAzureCredential for authentication. For local development, make sure you're logged in with az login and have access to the Azure Foundry resource. For more information, see the Azure Identity documentation.
Set the following environment variables:
$env:AZURE_FOUNDRY_PROJECT_ENDPOINT="https://your-foundry-service.services.ai.azure.com/api/projects/your-foundry-project" # Replace with your Azure Foundry resource endpoint
$env:AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME="gpt-4o-mini" # Optional, defaults to gpt-4o-mini
Run the sample
Navigate to the FoundryAgents sample directory and run:
cd dotnet/samples/GettingStarted/FoundryAgents
dotnet run --project .\FoundryAgents_Step18_FileSearch
Expected behavior
The sample will:
- Create a temporary text file with employee directory information
- Upload the file to Azure Foundry
- Create a vector store with the uploaded file
- Create an agent with file search capabilities using one of:
- Option 1: Using HostedFileSearchTool (MEAI abstraction)
- Option 2: Using native SDK file search tools
- Run a query against the agent to search through the uploaded file
- Display file citation annotations from responses
- Clean up resources (agent, vector store, and uploaded file)