microsoft/semantic-kernel · error · AgentChatException
Agent is not of the expected type {type(BedrockAgent)}.
Error message
Agent is not of the expected type {type(BedrockAgent)}. What it means
Raised by BedrockAgentChannel.invoke (an AgentChatException) when the supplied agent is not an instance of BedrockAgent. Channels are agent-type-specific; the Bedrock channel only knows how to drive a BedrockAgent, so any other agent type is rejected before invocation.
Source
Thrown at python/semantic_kernel/agents/channels/bedrock_agent_channel.py:59
thread: "BedrockAgentThread"
MESSAGE_PLACEHOLDER: ClassVar[str] = "[SILENCE]"
@override
async def invoke(self, agent: "Agent", **kwargs: Any) -> AsyncIterable[tuple[bool, ChatMessageContent]]:
"""Perform a discrete incremental interaction between a single Agent and AgentChat.
Args:
agent: The agent to interact with.
kwargs: Additional keyword arguments.
Returns:
An async iterable of ChatMessageContent with a boolean indicating if the
message should be visible external to the agent.
"""
from semantic_kernel.agents.bedrock.bedrock_agent import BedrockAgent
if not isinstance(agent, BedrockAgent):
raise AgentChatException(f"Agent is not of the expected type {type(BedrockAgent)}.")
if not self.messages:
# This is not supposed to happen, as the channel won't get invoked
# before it has received messages. This is just extra safety.
raise AgentChatException("No chat history available.")
# Preprocess chat history
await self._ensure_history_alternates()
await self._ensure_last_message_is_user()
async for response in agent.invoke(
messages=self.messages[-1].content,
thread=self.thread,
sessionState=await self._parse_chat_history_to_session_state(),
):
# All messages from Bedrock agents are user facing, i.e., function calls are not returned as messages
self.messages.append(response.message)
yield True, response.message
View on GitHub (pinned to c028a0c7dc)
Solutions
- Ensure only BedrockAgent instances are invoked through the BedrockAgentChannel / added to that agent group chat.
- Separate agents by type into compatible groups, or use AgentGroupChat which routes each agent to its own channel.
- Verify the agent object you pass is the concrete BedrockAgent subclass, not a parent or sibling type.
- Check that agent construction returns the intended subclass (no factory returning a wrong type).
Example fix
// before chat = AgentGroupChat(agent=chat_completion_agent) # wrong channel/type await chat.invoke() # raises in bedrock channel // after chat = AgentGroupChat(agent=bedrock_agent) # matching types await chat.invoke()
Defensive patterns
Strategy: type-guard
Validate before calling
from semantic_kernel.agents.bedrock.bedrock_agent import BedrockAgent
def assert_bedrock(agent):
if not isinstance(agent, BedrockAgent):
raise TypeError(f'Expected BedrockAgent, got {type(agent)}')
return agent Type guard
def is_bedrock_agent(agent) -> bool:
from semantic_kernel.agents.bedrock.bedrock_agent import BedrockAgent
return isinstance(agent, BedrockAgent) Try / catch
from semantic_kernel.exceptions.agent_exceptions import AgentChatException
try:
await chat.invoke(agent=agent)
except AgentChatException as e:
if 'expected type' in str(e): raise TypeError(e)
raise Prevention
- Keep AgentGroupChat membership type-consistent
- Validate agent concrete type before adding to a chat
When it happens
Trigger: Registering/invoking a non-Bedrock agent (e.g. ChatCompletionAgent, OpenAIAssistantAgent) through an AgentGroupChat or channel that was created for a BedrockAgent; mixing agent types in a group chat where the channel type mismatches.
Common situations: Adding agents of different concrete types to an AgentGroupChat and letting the wrong channel receive a foreign agent; refactoring that swaps an agent's base type without updating the group; incorrect agent construction returning a base Agent instead of BedrockAgent.
Related errors
- Agent is not of the expected type {type(OpenAIAssistantAgent
- Agent is not of the expected type {type(AzureAIAgent)}.
- No chat history available.
- Channel Keys must not be empty. Unable to generate channel h
- No file found in the response.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/c4e4856c1ad501d4.
Report an issue: GitHub.