{"record":{"id":"4e330992fc194670","repo":"microsoft/semantic-kernel","slug":"invalid-recipient-type-type-recipient-recipie","errorCode":null,"errorMessage":"Invalid recipient type: {type(recipient)}. Recipient must be an instance of AutoGenConversableAgent.","messagePattern":"Invalid recipient type: (.+?)\\. Recipient must be an instance of AutoGenConversableAgent\\.","errorType":"validation","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/autogen/autogen_conversable_agent.py","lineNumber":219,"sourceCode":"            kwargs: Additional keyword arguments\n\n        Yields:\n            An AgentResponseItem of type ChatMessageContent object with the response and the thread.\n        \"\"\"\n        thread = await self._ensure_thread_exists_with_messages(\n            messages=messages,\n            thread=thread,\n            construct_thread=lambda: AutoGenConversableAgentThread(),\n            expected_type=AutoGenConversableAgentThread,\n        )\n        assert thread.id is not None  # nosec\n\n        if summary_args is None:\n            summary_args = {}\n\n        if recipient is not None:\n            if not isinstance(recipient, AutoGenConversableAgent):\n                raise AgentInvokeException(\n                    f\"Invalid recipient type: {type(recipient)}. \"\n                    \"Recipient must be an instance of AutoGenConversableAgent.\"\n                )\n\n            messages = [message async for message in thread.get_messages()]\n            chat_result = await self.conversable_agent.a_initiate_chat(\n                recipient=recipient.conversable_agent,\n                clear_history=clear_history,\n                silent=silent,\n                cache=cache,\n                max_turns=max_turns,\n                summary_method=summary_method,\n                summary_args=summary_args,\n                message=messages[-1].content,  # type: ignore\n                **kwargs,\n            )\n\n            logger.info(f\"Called AutoGenConversableAgent.a_initiate_chat with recipient: {recipient}.\")","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/autogen/autogen_conversable_agent.py#L201-L237","documentation":"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.","triggerScenarios":"Passing `recipient=some_chat_completion_agent` (a ChatCompletionAgent) or a raw autogen.ConversableAgent instead of an AutoGenConversableAgent to invoke().","commonSituations":"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.","solutions":["Wrap the target in AutoGenConversableAgent before passing it as recipient.","Pass recipient=None and use single-agent invoke if you only have one agent.","Add an isinstance check before the call to fail fast with your own message."],"exampleFix":"# before\nawait agent.invoke(messages='hi', thread=thread, recipient=other_sk_agent)\n\n# after\nother = AutoGenConversableAgent(name='other', ...)\nawait agent.invoke(messages='hi', thread=thread, recipient=other)","handlingStrategy":"type-guard","validationCode":"from semantic_kernel.agents.autogen import AutoGenConversableAgent\nassert recipient is None or isinstance(recipient, AutoGenConversableAgent), 'recipient must be AutoGenConversableAgent'","typeGuard":"from semantic_kernel.agents.autogen import AutoGenConversableAgent\ndef is_valid_recipient(recipient: object) -> bool:\n    return recipient is None or isinstance(recipient, AutoGenConversableAgent)","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException\ntry:\n    await agent.invoke(messages='hi', thread=thread, recipient=recipient)\nexcept AgentInvokeException as e:\n    if 'Invalid recipient type' in str(e):\n        recipient = AutoGenConversableAgent(name='other', ...)\n        await agent.invoke(messages='hi', thread=thread, recipient=recipient)\n    else:\n        raise","preventionTips":["Only pass AutoGenConversableAgent instances as recipient.","Wrap foreign agents before initiate-chat calls."],"tags":["autogen","type-guard","multi-agent","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}