file_search_agent
Search through files and documents using AI to find specific information based on your query, returning relevant results from specified vector stores.
Instructions
Use an AI agent specialized in searching through files and documents to find relevant information.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| max_results | No | The maximum number of document results to return. | |
| query | Yes | The search query or question to find in the documents. | |
| vector_store_ids | Yes | The IDs of the vector stores to search in. This is required for file search to work. |
Implementation Reference
- src/agents_mcp_server/server.py:228-260 (handler)Primary handler and registration for the 'file_search_agent' tool. Creates and runs an Agent instance equipped with FileSearchTool to execute file searches based on the provided query and vector store IDs.@mcp.tool( name="file_search_agent", description="Use an AI agent specialized in searching through files and documents to find relevant information.", ) async def file_search( query: str = Field(..., description="The search query or question to find in the documents."), vector_store_ids: List[str] = Field( ..., description="The IDs of the vector stores to search in. This is required for file search to work.", ), max_results: int = Field(5, description="The maximum number of document results to return."), ) -> AgentResponse: """Use a specialized file search agent powered by OpenAI to find information in documents.""" try: agent = Agent( name="File Search Assistant", instructions=file_search_instructions, tools=[FileSearchTool(max_num_results=max_results, vector_store_ids=vector_store_ids)], ) with trace("File search agent execution"): result = await Runner.run(agent, query) return AgentResponse( response=result.final_output, raw_response={"items": [str(item) for item in result.new_items]}, ) except Exception as e: print(f"Error running file search agent: {e}") return AgentResponse( response=f"An error occurred while searching files: {str(e)}", raw_response=None )
- Input schema definition using Pydantic Fields for the file_search_agent tool parameters.query: str = Field(..., description="The search query or question to find in the documents."), vector_store_ids: List[str] = Field( ..., description="The IDs of the vector stores to search in. This is required for file search to work.", ), max_results: int = Field(5, description="The maximum number of document results to return."), ) -> AgentResponse:
- Helper string containing the instructions/prompt for the File Search Assistant Agent used in the tool.file_search_instructions = """You are a file search assistant. Your primary goal is to search through files and documents to find relevant information based on the user's query. Guidelines: 1. Always use the file search tool to find documents 2. Quote relevant sections from documents when appropriate 3. Summarize document content clearly 4. If multiple documents are found, compare and contrast their information 5. If no relevant documents are found, clearly state this """
- Output schema for agent responses, used by file_search_agent and other tools.class AgentResponse(BaseModel): """Response from an OpenAI agent.""" response: str = Field(..., description="The response from the agent") raw_response: Optional[Dict[str, Any]] = Field( None, description="The raw response data from the agent, if available" )