{"record":{"id":"f809206823f9a091","repo":"microsoft/semantic-kernel","slug":"agent-is-not-of-the-expected-type-type-azureaiage","errorCode":null,"errorMessage":"Agent is not of the expected type {type(AzureAIAgent)}.","messagePattern":"Agent is not of the expected type (.+?)\\.","errorType":"exception","errorClass":"AgentChatException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/azure_ai/azure_ai_channel.py","lineNumber":62,"sourceCode":"        \"\"\"\n        for message in history:\n            await AgentThreadActions.create_message(self.client, self.thread_id, message)\n\n    @override\n    async def invoke(self, agent: \"Agent\", **kwargs) -> 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.azure_ai.azure_ai_agent import AzureAIAgent\n\n        if not isinstance(agent, AzureAIAgent):\n            raise AgentChatException(f\"Agent is not of the expected type {type(AzureAIAgent)}.\")\n\n        async for is_visible, message in AgentThreadActions.invoke(\n            agent=agent,\n            thread_id=self.thread_id,\n            arguments=agent.arguments,\n            kernel=agent.kernel,\n            **kwargs,\n        ):\n            yield is_visible, message\n\n    @override\n    async def invoke_stream(\n        self,\n        agent: \"Agent\",\n        messages: list[\"ChatMessageContent\"],\n        **kwargs,\n    ) -> AsyncIterable[\"ChatMessageContent\"]:\n        \"\"\"Invoke the agent stream.","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/azure_ai/azure_ai_channel.py#L44-L80","documentation":"Raised by AzureAIChannel.invoke when the agent passed to the channel is not an AzureAIAgent. Each channel type is specific to one agent implementation; the AzureAI channel drives Azure AI Agents API threads and cannot run a different agent type. Surfaced as AgentChatException.","triggerScenarios":"Adding a ChatCompletionAgent or OpenAIAssistantAgent to an AgentGroupChat whose channel resolved to an AzureAIChannel; mixing agent types in a group chat where the first agent created an AzureAI channel and a later agent is incompatible; passing a mock/wrong agent in tests.","commonSituations":"Building a multi-agent group chat with heterogeneous agent types without ensuring they share a compatible channel; refactoring that swapped an AzureAIAgent for another type but kept the same channel; incorrect agent construction returning a base Agent.","solutions":["Ensure every agent in an AgentGroupChat that shares a channel is an AzureAIAgent (or implement a compatible channel).","Use separate group chats or channels for different agent implementations.","Verify the agent object type before adding it to the chat."],"exampleFix":"// before\nchat = AgentGroupChat(azure_agent, chat_completion_agent)  // mixed types\n// after\nchat = AgentGroupChat(azure_agent_1, azure_agent_2)  // all AzureAIAgent","handlingStrategy":"type-guard","validationCode":"from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent\ndef assert_all_azure(agents):\n    for a in agents:\n        if not isinstance(a, AzureAIAgent):\n            raise TypeError(f'{type(a).__name__} cannot join an AzureAI channel group chat')\n    return agents","typeGuard":"def is_azure_agent(agent) -> bool:\n    from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent\n    return isinstance(agent, AzureAIAgent)","tryCatchPattern":"try:\n    async for msg in group_chat.invoke(): ...\nexcept AgentChatException as e:\n    if 'not of the expected type' in str(e):\n        log.error('Group chat contains a non-AzureAIAgent')\n    raise","preventionTips":["Keep group chats homogeneous: all AzureAIAgent or all of one compatible type.","Type-check agents before adding them to an AgentGroupChat.","Use separate chats for different agent implementations."],"tags":["azure-ai","channel","group-chat","type-mismatch","agent-chat"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}