{"record":{"id":"f611a1bb5b7f66ae","repo":"microsoft/autogen","slug":"no-content-in-the-last-message","errorCode":null,"errorMessage":"No content in the last message","messagePattern":"No content in the last message","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/agents/azure/_azure_ai_agent.py","lineNumber":810,"sourceCode":"        ):\n            if cancellation_token.is_cancelled():\n                trace_logger.debug(\"Message retrieval cancelled by token.\")\n                break\n            agent_messages.append(msg)\n            if len(agent_messages) >= message_limit:\n                break\n        if not agent_messages:\n            raise ValueError(\"No messages received from assistant\")\n\n        # Get the last message from the agent (role=AGENT)\n        last_message: Optional[ThreadMessage] = next(\n            (m for m in agent_messages if getattr(m, \"role\", None) == \"agent\"), None\n        )\n        if not last_message:\n            trace_logger.debug(\"No message with AGENT role found, falling back to first message\")\n            last_message = agent_messages[0]  # Fallback to first message\n        if not getattr(last_message, \"content\", None):\n            raise ValueError(\"No content in the last message\")\n\n        # Extract text content\n        message_text = \"\"\n        for text_message in last_message.text_messages:\n            message_text += text_message.text.value\n\n        # Extract citations\n        citations: list[Any] = []\n\n        # Try accessing annotations directly\n\n        annotations = getattr(last_message, \"annotations\", [])\n\n        if isinstance(annotations, list) and annotations:\n            annotations = cast(List[MessageTextUrlCitationAnnotation], annotations)\n\n            trace_logger.debug(f\"Found {len(annotations)} annotations\")\n            for annotation in annotations:","sourceCodeStart":792,"sourceCodeEnd":828,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/agents/azure/_azure_ai_agent.py#L792-L828","documentation":"The assistant's last message was found but its content attribute is empty/None, so there is no text to turn into a chat message. The agent refuses to return an empty response and raises rather than emitting a blank TextMessage.","triggerScenarios":"A thread message whose content is an empty list/None — e.g. a message that only carried tool_call metadata, or a message partially deleted; the role-based fallback picks agent_messages[0] which may also be contentless.","commonSituations":"Runs that end immediately after tool calls (the tool-call message has no content); message truncation on the service side; racing with deletion/cleanup of thread messages.","solutions":["Retry the turn — often transient when the service is still committing messages; add a small delay before on_messages when polling showed a just-completed run.","Inspect the thread via the raw SDK to see the actual message shapes and confirm the run truly produced text.","If the run only performed tool calls, send a follow-up turn so the model produces a textual reply.","Upgrade autogen-ext; last-message selection logic has evolved."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = await agent.on_messages(msgs, ct)\nexcept ValueError as e:\n    if \"No content in the last message\" in str(e):\n        await asyncio.sleep(1)\n        resp = await agent.on_messages(msgs, ct)  # one retry\n    else:\n        raise","preventionTips":["Add a small delay between run completion and message retrieval.","If the run only made tool calls, send a follow-up turn to elicit a textual reply.","Inspect thread messages with the raw SDK when this recurs."],"tags":["azure","messaging","azure-ai-agent"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}