microsoft/semantic-kernel · error · AgentChatException

Agent is not of the expected type {type(OpenAIAssistantAgent

Error message

Agent is not of the expected type {type(OpenAIAssistantAgent)}.

What it means

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.

Source

Thrown at python/semantic_kernel/agents/channels/open_ai_assistant_channel.py:61

            if any(isinstance(item, FunctionCallContent) for item in message.items):
                continue
            await create_chat_message(self.client, self.thread_id, message)

    @override
    async def invoke(self, agent: "Agent", **kwargs: Any) -> 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.open_ai.openai_assistant_agent import OpenAIAssistantAgent

        if not isinstance(agent, OpenAIAssistantAgent):
            raise AgentChatException(f"Agent is not of the expected type {type(OpenAIAssistantAgent)}.")

        async for is_visible, message in AssistantThreadActions.invoke(agent=agent, thread_id=self.thread_id, **kwargs):
            yield is_visible, message

    @override
    async def invoke_stream(
        self, agent: "Agent", messages: list[ChatMessageContent], **kwargs: Any
    ) -> AsyncIterable["ChatMessageContent"]:
        """Invoke the agent stream.

        Args:
            agent: The agent to invoke.
            messages: The conversation messages.
            kwargs: The keyword arguments.

        Yields:
            tuple[bool, StreamingChatMessageContent]: The conversation messages.
        """

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Invoke only OpenAIAssistantAgent instances through the OpenAI Assistant channel.
  2. Keep group chat membership type-consistent, or rely on AgentGroupChat to route each agent to its own channel type.
  3. Verify the object passed is the concrete OpenAIAssistantAgent subclass.
  4. Audit agent construction so the intended subclass is produced.

Example fix

// before
await chat.invoke(agent=bedrock_agent)  # raises in openai assistant channel
// after
await chat.invoke(agent=openai_assistant_agent)
Defensive patterns

Strategy: type-guard

Validate before calling

from semantic_kernel.agents.open_ai.openai_assistant_agent import OpenAIAssistantAgent
def assert_assistant(agent):
    if not isinstance(agent, OpenAIAssistantAgent):
        raise TypeError(f'Expected OpenAIAssistantAgent, got {type(agent)}')
    return agent

Type guard

def is_openai_assistant_agent(agent) -> bool:
    from semantic_kernel.agents.open_ai.openai_assistant_agent import OpenAIAssistantAgent
    return isinstance(agent, OpenAIAssistantAgent)

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

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/927a282deb84469a. Report an issue: GitHub.