microsoft/semantic-kernel · error · AgentChatException
Agent is not of the expected type {type(AzureAIAgent)}.
Error message
Agent is not of the expected type {type(AzureAIAgent)}. What it means
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.
Source
Thrown at python/semantic_kernel/agents/azure_ai/azure_ai_channel.py:62
"""
for message in history:
await AgentThreadActions.create_message(self.client, self.thread_id, message)
@override
async def invoke(self, agent: "Agent", **kwargs) -> AsyncIterable[tuple[bool, "ChatMessageContent"]]:
"""Invoke the agent.
Args:
agent: The agent to invoke.
kwargs: The keyword arguments.
Yields:
tuple[bool, ChatMessageContent]: The conversation messages.
"""
from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent
if not isinstance(agent, AzureAIAgent):
raise AgentChatException(f"Agent is not of the expected type {type(AzureAIAgent)}.")
async for is_visible, message in AgentThreadActions.invoke(
agent=agent,
thread_id=self.thread_id,
arguments=agent.arguments,
kernel=agent.kernel,
**kwargs,
):
yield is_visible, message
@override
async def invoke_stream(
self,
agent: "Agent",
messages: list["ChatMessageContent"],
**kwargs,
) -> AsyncIterable["ChatMessageContent"]:
"""Invoke the agent stream.View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before chat = AgentGroupChat(azure_agent, chat_completion_agent) // mixed types // after chat = AgentGroupChat(azure_agent_1, azure_agent_2) // all AzureAIAgent
Defensive patterns
Strategy: type-guard
Validate before calling
from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent
def assert_all_azure(agents):
for a in agents:
if not isinstance(a, AzureAIAgent):
raise TypeError(f'{type(a).__name__} cannot join an AzureAI channel group chat')
return agents Type guard
def is_azure_agent(agent) -> bool:
from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent
return isinstance(agent, AzureAIAgent) Try / catch
try:
async for msg in group_chat.invoke(): ...
except AgentChatException as e:
if 'not of the expected type' in str(e):
log.error('Group chat contains a non-AzureAIAgent')
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to delete thread: {e}
- Expected AzureAIAgentSettings, got {type(settings).__name__}
- Agent is not of the expected type {type(BedrockAgent)}.
- Agent is not of the expected type {type(OpenAIAssistantAgent
- Channel Keys must not be empty. Unable to generate channel h
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/f809206823f9a091.
Report an issue: GitHub.