{"record":{"id":"499933c0b0bf341c","repo":"microsoft/semantic-kernel","slug":"unexpected-reply-type-from-a-generate-reply-ty","errorCode":null,"errorMessage":"Unexpected reply type from `a_generate_reply`: {type(reply)}","messagePattern":"Unexpected reply type from `a_generate_reply`: (.+?)","errorType":"exception","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/autogen/autogen_conversable_agent.py","lineNumber":314,"sourceCode":"                    items.append(\n                        FunctionResultContent(\n                            id=tool_response.get(\"tool_call_id\"),\n                            result=tool_response.get(\"content\"),\n                        )\n                    )\n\n        return ChatMessageContent(role=role, items=items, name=name)  # type: ignore\n\n    async def _create_reply_content(\n        self, reply: str | dict[str, Any], thread: AgentThread\n    ) -> AgentResponseItem[ChatMessageContent]:\n        response: ChatMessageContent\n        if isinstance(reply, str):\n            response = ChatMessageContent(content=reply, role=AuthorRole.ASSISTANT)\n        elif isinstance(reply, dict):\n            response = ChatMessageContent(**reply)\n        else:\n            raise AgentInvokeException(f\"Unexpected reply type from `a_generate_reply`: {type(reply)}\")\n\n        await thread.on_new_message(response)\n\n        return AgentResponseItem(\n            message=response,\n            thread=thread,\n        )\n","sourceCodeStart":296,"sourceCodeEnd":322,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/autogen/autogen_conversable_agent.py#L296-L322","documentation":"Thrown by AutoGenConversableAgent._create_reply_content when the reply returned by the AutoGen conversable_agent's a_generate_reply is neither a str nor a dict. The translator only knows how to map those two shapes into a ChatMessageContent, so any other object (e.g. a custom autogen message class, None, a list) is rejected.","triggerScenarios":"A customized autogen ConversableAgent whose reply producer returns a non-str/non-dict object; an autogen version/extension that returns a richer message type; a None reply from a misconfigured reply function.","commonSituations":"Registering custom reply functions on the underlying conversable_agent that return objects; version mismatch between autogen and the SK wrapper's expectations.","solutions":["Ensure the underlying ConversableAgent's reply functions return a plain str or a dict compatible with ChatMessageContent kwargs.","Normalize the reply before invoke by wrapping/replacing custom reply logic.","Pin compatible autogen and semantic-kernel versions."],"exampleFix":"# before\n# custom reply function returns an object\nconv.register_reply(lambda *a, **k: MyMsgObject(...))\n\n# after\nconv.register_reply(lambda *a, **k: {'content': 'hello', 'role': 'assistant'})","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"def reply_is_supported(reply: object) -> bool:\n    return isinstance(reply, (str, dict))","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException\ntry:\n    async for r in agent.invoke(messages=msg, thread=thread):\n        ...\nexcept AgentInvokeException as e:\n    if 'Unexpected reply type' in str(e):\n        logger.error('Underlying autogen agent returned an unsupported reply shape; check custom reply functions')\n    raise","preventionTips":["Keep custom autogen reply functions returning str or dict.","Pin autogen and semantic-kernel to compatible versions."],"tags":["autogen","reply","type-mismatch","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}