microsoft/semantic-kernel · error · AgentInvokeException

Invalid recipient type: {type(recipient)}. Recipient must be

Error message

Invalid recipient type: {type(recipient)}. Recipient must be an instance of AutoGenConversableAgent.

What it means

Thrown by AutoGenConversableAgent.invoke when a `recipient` argument is supplied but is not an instance of AutoGenConversableAgent. The multi-agent a_initiate_chat handshake requires two AutoGenConversableAgent wrappers so their underlying conversable_agent objects can chat; any other type is refused.

Source

Thrown at python/semantic_kernel/agents/autogen/autogen_conversable_agent.py:219

            kwargs: Additional keyword arguments

        Yields:
            An AgentResponseItem of type ChatMessageContent object with the response and the thread.
        """
        thread = await self._ensure_thread_exists_with_messages(
            messages=messages,
            thread=thread,
            construct_thread=lambda: AutoGenConversableAgentThread(),
            expected_type=AutoGenConversableAgentThread,
        )
        assert thread.id is not None  # nosec

        if summary_args is None:
            summary_args = {}

        if recipient is not None:
            if not isinstance(recipient, AutoGenConversableAgent):
                raise AgentInvokeException(
                    f"Invalid recipient type: {type(recipient)}. "
                    "Recipient must be an instance of AutoGenConversableAgent."
                )

            messages = [message async for message in thread.get_messages()]
            chat_result = await self.conversable_agent.a_initiate_chat(
                recipient=recipient.conversable_agent,
                clear_history=clear_history,
                silent=silent,
                cache=cache,
                max_turns=max_turns,
                summary_method=summary_method,
                summary_args=summary_args,
                message=messages[-1].content,  # type: ignore
                **kwargs,
            )

            logger.info(f"Called AutoGenConversableAgent.a_initiate_chat with recipient: {recipient}.")

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Wrap the target in AutoGenConversableAgent before passing it as recipient.
  2. Pass recipient=None and use single-agent invoke if you only have one agent.
  3. Add an isinstance check before the call to fail fast with your own message.

Example fix

# before
await agent.invoke(messages='hi', thread=thread, recipient=other_sk_agent)

# after
other = AutoGenConversableAgent(name='other', ...)
await agent.invoke(messages='hi', thread=thread, recipient=other)
Defensive patterns

Strategy: type-guard

Validate before calling

from semantic_kernel.agents.autogen import AutoGenConversableAgent
assert recipient is None or isinstance(recipient, AutoGenConversableAgent), 'recipient must be AutoGenConversableAgent'

Type guard

from semantic_kernel.agents.autogen import AutoGenConversableAgent
def is_valid_recipient(recipient: object) -> bool:
    return recipient is None or isinstance(recipient, AutoGenConversableAgent)

Try / catch

from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException
try:
    await agent.invoke(messages='hi', thread=thread, recipient=recipient)
except AgentInvokeException as e:
    if 'Invalid recipient type' in str(e):
        recipient = AutoGenConversableAgent(name='other', ...)
        await agent.invoke(messages='hi', thread=thread, recipient=recipient)
    else:
        raise

Prevention

When it happens

Trigger: Passing `recipient=some_chat_completion_agent` (a ChatCompletionAgent) or a raw autogen.ConversableAgent instead of an AutoGenConversableAgent to invoke().

Common situations: Mixing Semantic Kernel agent types in a group chat; passing the wrapped autogen object instead of the SK wrapper; refactoring that changed the recipient type.

Related errors


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