{"record":{"id":"e2c09f1c59a8e84d","repo":"microsoft/autogen","slug":"file-search-is-not-enabled-for-this-assistant-add-e2c09f","errorCode":null,"errorMessage":"File search is not enabled for this assistant. Add a file_search tool when creating the assistant.","messagePattern":"File search is not enabled for this assistant\\. Add a file_search tool when creating the assistant\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py","lineNumber":633,"sourceCode":"\n        await cancellation_token.link_future(\n            asyncio.ensure_future(\n                self._client.beta.threads.update(  # type: ignore[reportDeprecated]\n                    thread_id=self._thread_id,\n                    tool_resources=cast(thread_update_params.ToolResources, tool_resources.model_dump()),\n                )\n            )\n        )\n\n    async def on_upload_for_file_search(\n        self, file_paths: str | Iterable[str], cancellation_token: CancellationToken\n    ) -> None:\n        \"\"\"Handle file uploads for file search.\"\"\"\n        await self._ensure_initialized()\n\n        # Check if file_search is enabled in tools\n        if not any(tool.get(\"type\") == \"file_search\" for tool in self._api_tools):\n            raise ValueError(\n                \"File search is not enabled for this assistant. Add a file_search tool when creating the assistant.\"\n            )\n\n        # Create vector store if not already created\n        if self._vector_store_id is None:\n            vector_store: VectorStore = await cancellation_token.link_future(\n                asyncio.ensure_future(self._client.vector_stores.create())\n            )\n            self._vector_store_id = vector_store.id\n\n            # Update assistant with vector store ID\n            await cancellation_token.link_future(\n                asyncio.ensure_future(\n                    self._client.beta.assistants.update(\n                        assistant_id=self._get_assistant_id,\n                        tool_resources={\"file_search\": {\"vector_store_ids\": [self._vector_store_id]}},\n                    )\n                )","sourceCodeStart":615,"sourceCodeEnd":651,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py#L615-L651","documentation":"on_upload_for_file_search uploads files into an OpenAI vector store and attaches it to the assistant. It requires that a file_search tool be part of the assistant's tool configuration (checked against self._api_tools); without file_search enabled the upload has nothing to attach to, so it refuses with this ValueError.","triggerScenarios":"Creating OpenAIAssistantAgent(..., tools=[...]) without a file_search tool entry (or without tool_resources containing file_search), then calling await agent.on_upload_for_file_search(paths, ct).","commonSituations":"Adding file upload to an existing agent that was configured for function tools only; forgetting that file_search must be declared at assistant creation, not at upload time.","solutions":["Include file_search when creating the agent: tools=[\"file_search\", ...] (string form works for the assistant agent).","If using tool_resources/file search resources, ensure the file_search tool itself is registered too.","Recreate the assistant with the updated tool set rather than uploading to a non-file-search assistant."],"exampleFix":"# before\nagent = OpenAIAssistantAgent(\n    name=\"docs\", instructions=\"...\", model=\"gpt-4o\", client=cl, tools=[]\n)\nawait agent.on_upload_for_file_search(\"report.pdf\", ct)  # raises\n\n# after\nagent = OpenAIAssistantAgent(\n    name=\"docs\", instructions=\"...\", model=\"gpt-4o\", client=cl,\n    tools=[\"file_search\"],\n)\nawait agent.on_upload_for_file_search(\"report.pdf\", ct)","handlingStrategy":"validation","validationCode":"file_search_enabled = any(\n    (t.get(\"type\") if isinstance(t, dict) else t) == \"file_search\" for t in tools\n)\nif not file_search_enabled:\n    raise ConfigError(\"add 'file_search' to tools before uploading files\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare file_search in the agent's tools at creation time.","Gate upload UIs/features on the agent's tool configuration.","Remember tool capability is fixed at assistant creation, not at upload."],"tags":["openai","assistants-api","file-search","configuration"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}