microsoft/semantic-kernel · error · AgentInvokeException
Unexpected reply type from `a_generate_reply`: {type(reply)}
Error message
Unexpected reply type from `a_generate_reply`: {type(reply)} What it means
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.
Source
Thrown at python/semantic_kernel/agents/autogen/autogen_conversable_agent.py:314
items.append(
FunctionResultContent(
id=tool_response.get("tool_call_id"),
result=tool_response.get("content"),
)
)
return ChatMessageContent(role=role, items=items, name=name) # type: ignore
async def _create_reply_content(
self, reply: str | dict[str, Any], thread: AgentThread
) -> AgentResponseItem[ChatMessageContent]:
response: ChatMessageContent
if isinstance(reply, str):
response = ChatMessageContent(content=reply, role=AuthorRole.ASSISTANT)
elif isinstance(reply, dict):
response = ChatMessageContent(**reply)
else:
raise AgentInvokeException(f"Unexpected reply type from `a_generate_reply`: {type(reply)}")
await thread.on_new_message(response)
return AgentResponseItem(
message=response,
thread=thread,
)
View on GitHub (pinned to c028a0c7dc)
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.
Example fix
# before
# custom reply function returns an object
conv.register_reply(lambda *a, **k: MyMsgObject(...))
# after
conv.register_reply(lambda *a, **k: {'content': 'hello', 'role': 'assistant'}) Defensive patterns
Strategy: try-catch
Type guard
def reply_is_supported(reply: object) -> bool:
return isinstance(reply, (str, dict)) Try / catch
from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException
try:
async for r in agent.invoke(messages=msg, thread=thread):
...
except AgentInvokeException as e:
if 'Unexpected reply type' in str(e):
logger.error('Underlying autogen agent returned an unsupported reply shape; check custom reply functions')
raise Prevention
- Keep custom autogen reply functions returning str or dict.
- Pin autogen and semantic-kernel to compatible versions.
When it happens
Trigger: 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.
Common situations: Registering custom reply functions on the underlying conversable_agent that return objects; version mismatch between autogen and the SK wrapper's expectations.
Related errors
- {self.__class__.__name__} currently only supports agent thre
- Cannot retrieve chat history, since the thread has been dele
- Cannot reduce chat history, since the thread is not currentl
- Invalid recipient type: {type(recipient)}. Recipient must be
- The AutoGenConversableAgent does not support streaming.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/499933c0b0bf341c.
Report an issue: GitHub.