{"record":{"id":"e8bd1abd5f96afc1","repo":"microsoft/autogen","slug":"incorrect-client-passed-to-openaiassistantagent-p","errorCode":null,"errorMessage":"Incorrect client passed to OpenAIAssistantAgent. Please use an OpenAI AsyncClient instance instead of an AutoGen ChatCompletionClient instance.","messagePattern":"Incorrect client passed to OpenAIAssistantAgent\\. Please use an OpenAI AsyncClient instance instead of an AutoGen ChatCompletionClient instance\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py","lineNumber":259,"sourceCode":"        instructions: str,\n        tools: Optional[\n            Iterable[\n                Union[\n                    Literal[\"code_interpreter\", \"file_search\"],\n                    Tool | Callable[..., Any] | Callable[..., Awaitable[Any]],\n                ]\n            ]\n        ] = None,\n        assistant_id: Optional[str] = None,\n        thread_id: Optional[str] = None,\n        metadata: Optional[Dict[str, str]] = None,\n        response_format: Optional[\"AssistantResponseFormatOptionParam\"] = None,\n        temperature: Optional[float] = None,\n        tool_resources: Optional[\"ToolResources\"] = None,\n        top_p: Optional[float] = None,\n    ) -> None:\n        if isinstance(client, ChatCompletionClient):\n            raise ValueError(\n                \"Incorrect client passed to OpenAIAssistantAgent. Please use an OpenAI AsyncClient instance instead of an AutoGen ChatCompletionClient instance.\"\n            )\n\n        super().__init__(name, description)\n        if tools is None:\n            tools = []\n\n        # Store original tools and converted tools separately\n        self._original_tools: List[Tool] = []\n        converted_tools: List[\"AssistantToolParam\"] = []\n        for tool in tools:\n            if isinstance(tool, str):\n                if tool == \"code_interpreter\":\n                    converted_tools.append(CodeInterpreterToolParam(type=\"code_interpreter\"))\n                elif tool == \"file_search\":\n                    converted_tools.append(FileSearchToolParam(type=\"file_search\"))\n            elif isinstance(tool, Tool):\n                self._original_tools.append(tool)","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py#L241-L277","documentation":"OpenAIAssistantAgent talks to the OpenAI Assistants API directly through the openai SDK's AsyncOpenAI client — it does not use AutoGen's ChatCompletionClient abstraction. The constructor explicitly rejects ChatCompletionClient instances (including AsyncOpenAIChatCompletionClient) with this ValueError to prevent the common mistake of passing the wrong client kind.","triggerScenarios":"OpenAIAssistantAgent(name=..., instructions=..., model=..., client=AsyncOpenAIChatCompletionClient(model=\"gpt-4o\", api_key=...)) — any autogen ChatCompletionClient subclass as client.","commonSituations":"Copying client setup from OpenAIChatCompletionAgent examples; refactoring an agent from the chat-completion style to the Assistants API without changing the client; tutorials that construct a chat completion client once and pass it everywhere.","solutions":["Pass an OpenAI AsyncClient: client = AsyncOpenAI(api_key=...) from the openai package.","Keep your ChatCompletionClient for OpenAIChatCompletionAgent / OpenAIAgent, and create a separate AsyncOpenAI for OpenAIAssistantAgent.","If you actually want the chat-completions style agent with AutoGen clients, use OpenAIChatCompletionAgent instead of OpenAIAssistantAgent."],"exampleFix":"# before\nfrom autogen_ext.models.openai import OpenAIChatCompletionClient\nagent = OpenAIAssistantAgent(\n    name=\"helper\", instructions=\"...\", model=\"gpt-4o\",\n    client=OpenAIChatCompletionClient(model=\"gpt-4o\"),\n)\n\n# after\nfrom openai import AsyncOpenAI\nagent = OpenAIAssistantAgent(\n    name=\"helper\", instructions=\"...\", model=\"gpt-4o\",\n    client=AsyncOpenAI(),  # uses OPENAI_API_KEY env var\n)","handlingStrategy":"type-guard","validationCode":"from openai import AsyncOpenAI\nassert isinstance(client, AsyncOpenAI), \"OpenAIAssistantAgent needs openai.AsyncOpenAI\"","typeGuard":"from openai import AsyncOpenAI\nfrom autogen_core.models import ChatCompletionClient\n\ndef is_assistant_client(client: object) -> bool:\n    return isinstance(client, AsyncOpenAI) and not isinstance(client, ChatCompletionClient)","tryCatchPattern":null,"preventionTips":["Create one AsyncOpenAI() client for Assistants-API agents and separate ChatCompletionClients for chat agents.","Name variables distinctly (assistant_client vs chat_client) to avoid mix-ups.","Type-annotate constructor args so mypy catches the swap."],"tags":["openai","assistants-api","client-setup","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}