{"record":{"id":"927a282deb84469a","repo":"microsoft/semantic-kernel","slug":"agent-is-not-of-the-expected-type-type-openaiassi","errorCode":null,"errorMessage":"Agent is not of the expected type {type(OpenAIAssistantAgent)}.","messagePattern":"Agent is not of the expected type (.+?)\\.","errorType":"exception","errorClass":"AgentChatException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/channels/open_ai_assistant_channel.py","lineNumber":61,"sourceCode":"            if any(isinstance(item, FunctionCallContent) for item in message.items):\n                continue\n            await create_chat_message(self.client, self.thread_id, message)\n\n    @override\n    async def invoke(self, agent: \"Agent\", **kwargs: Any) -> AsyncIterable[tuple[bool, \"ChatMessageContent\"]]:\n        \"\"\"Invoke the agent.\n\n        Args:\n            agent: The agent to invoke.\n            kwargs: The keyword arguments.\n\n        Yields:\n            tuple[bool, ChatMessageContent]: The conversation messages.\n        \"\"\"\n        from semantic_kernel.agents.open_ai.openai_assistant_agent import OpenAIAssistantAgent\n\n        if not isinstance(agent, OpenAIAssistantAgent):\n            raise AgentChatException(f\"Agent is not of the expected type {type(OpenAIAssistantAgent)}.\")\n\n        async for is_visible, message in AssistantThreadActions.invoke(agent=agent, thread_id=self.thread_id, **kwargs):\n            yield is_visible, message\n\n    @override\n    async def invoke_stream(\n        self, agent: \"Agent\", messages: list[ChatMessageContent], **kwargs: Any\n    ) -> AsyncIterable[\"ChatMessageContent\"]:\n        \"\"\"Invoke the agent stream.\n\n        Args:\n            agent: The agent to invoke.\n            messages: The conversation messages.\n            kwargs: The keyword arguments.\n\n        Yields:\n            tuple[bool, StreamingChatMessageContent]: The conversation messages.\n        \"\"\"","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/channels/open_ai_assistant_channel.py#L43-L79","documentation":"Raised by OpenAIAssistantChannel.invoke (an AgentChatException) when the supplied agent is not an instance of OpenAIAssistantAgent. The OpenAI Assistants thread channel delegates to AssistantThreadActions which only operate on an OpenAIAssistantAgent, so other agent types are rejected.","triggerScenarios":"Invoking a non-OpenAIAssistantAgent (e.g. BedrockAgent, ChatCompletionAgent) through an OpenAIAssistantChannel; adding an agent of the wrong type to a group chat configured for OpenAI Assistants.","commonSituations":"AgentGroupChat mixing incompatible agent types so the wrong channel receives a foreign agent; refactoring an agent's base class without updating chat wiring; a factory returning a wrong concrete agent type.","solutions":["Invoke only OpenAIAssistantAgent instances through the OpenAI Assistant channel.","Keep group chat membership type-consistent, or rely on AgentGroupChat to route each agent to its own channel type.","Verify the object passed is the concrete OpenAIAssistantAgent subclass.","Audit agent construction so the intended subclass is produced."],"exampleFix":"// before\nawait chat.invoke(agent=bedrock_agent)  # raises in openai assistant channel\n// after\nawait chat.invoke(agent=openai_assistant_agent)","handlingStrategy":"type-guard","validationCode":"from semantic_kernel.agents.open_ai.openai_assistant_agent import OpenAIAssistantAgent\ndef assert_assistant(agent):\n    if not isinstance(agent, OpenAIAssistantAgent):\n        raise TypeError(f'Expected OpenAIAssistantAgent, got {type(agent)}')\n    return agent","typeGuard":"def is_openai_assistant_agent(agent) -> bool:\n    from semantic_kernel.agents.open_ai.openai_assistant_agent import OpenAIAssistantAgent\n    return isinstance(agent, OpenAIAssistantAgent)","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentChatException\ntry:\n    await chat.invoke(agent=agent)\nexcept AgentChatException as e:\n    if 'expected type' in str(e): raise TypeError(e)\n    raise","preventionTips":["Match assistant agents with the assistant channel","Confirm concrete subclass from factories"],"tags":["openai","assistant","channel","agent-type","group-chat","type-guard"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}