{"record":{"id":"cef3a8d065689bd3","repo":"microsoft/autogen","slug":"unexpected-event-type-type-event","errorCode":null,"errorMessage":"Unexpected event type: {type(event)}","messagePattern":"Unexpected event type: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py","lineNumber":1228,"sourceCode":"                        for call in function_calls\n                    ]\n                )\n                # Signal the end of streaming by putting None in the queue.\n                stream_queue.put_nowait(None)\n                return results\n\n            task = asyncio.create_task(_execute_tool_calls(current_model_result.content, stream))\n\n            while True:\n                event = await stream.get()\n                if event is None:\n                    # End of streaming, break the loop.\n                    break\n                if isinstance(event, BaseAgentEvent) or isinstance(event, BaseChatMessage):\n                    yield event\n                    inner_messages.append(event)\n                else:\n                    raise RuntimeError(f\"Unexpected event type: {type(event)}\")\n\n            # Wait for all tool calls to complete.\n            executed_calls_and_results = await task\n            exec_results = [result for _, result in executed_calls_and_results]\n\n            # Yield ToolCallExecutionEvent\n            tool_call_result_msg = ToolCallExecutionEvent(\n                content=exec_results,\n                source=agent_name,\n            )\n            event_logger.debug(tool_call_result_msg)\n            await model_context.add_message(FunctionExecutionResultMessage(content=exec_results))\n            inner_messages.append(tool_call_result_msg)\n            yield tool_call_result_msg\n\n            # STEP 4C: Check for handoff\n            handoff_output = cls._check_and_handle_handoff(\n                model_result=current_model_result,","sourceCodeStart":1210,"sourceCodeEnd":1246,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py#L1210-L1246","documentation":"While tool calls execute, AssistantAgent consumes an event stream from the internal tool-execution flow and requires every item to be a BaseAgentEvent or BaseChatMessage. This error means an object of some other type (raw string, Response, tool result, etc.) was emitted into that stream, breaking the agent-chat event protocol.","triggerScenarios":"Overriding or customizing AssistantAgent's tool-execution/reflection path so it yields non-event objects; mixing autogen-core / autogen-agentchat / autogen-ext versions so the stream produces types the loop does not recognize.","commonSituations":"Subclassed agents or custom tool-call executors that yield strings or plain dicts; package version drift after partial upgrades where event class identities diverge.","solutions":["Make the custom tool-execution/reflection generator yield only BaseAgentEvent or BaseChatMessage instances (e.g. ToolCallExecutionEvent, ToolCallRequestEvent, TextMessage).","Print or log type(event) at the failure point to identify exactly which object is leaking into the stream.","Align versions: reinstall autogen-core, autogen-agentchat and autogen-ext from the same release so isinstance checks match."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"from autogen_agentchat.base import Response\nfrom autogen_agentchat.messages import BaseAgentEvent, BaseChatMessage\n\ndef is_stream_event(obj) -> bool:\n    return isinstance(obj, (BaseAgentEvent, BaseChatMessage))","tryCatchPattern":"try:\n    async for msg in agent.on_messages_stream(input_msgs, ct):\n        handle(msg)\nexcept RuntimeError as e:\n    if \"Unexpected event type\" in str(e):\n        log.error(f\"Non-event object entered the tool-execution stream: {e}\")\n    raise","preventionTips":["Never yield raw strings, dicts, or Response objects from custom tool-execution/reflection overrides.","Keep autogen-core and autogen-agentchat versions aligned so isinstance checks agree.","Add a type assertion inside custom generators before yielding."],"tags":["streaming","tool-calls","events","version-mismatch"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}