{"record":{"id":"122b6b775f9dfe00","repo":"microsoft/autogen","slug":"no-content-in-the-last-message-last-message","errorCode":null,"errorMessage":"No content in the last message: {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/openai/_openai_assistant_agent.py","lineNumber":510,"sourceCode":"            if run.status == \"completed\":\n                break\n\n            await asyncio.sleep(0.5)\n\n        # Get messages after run completion\n        assistant_messages: AsyncCursorPage[Message] = await cancellation_token.link_future(\n            asyncio.ensure_future(\n                self._client.beta.threads.messages.list(thread_id=self._thread_id, order=\"desc\", limit=1)  # type: ignore[reportDeprecated]\n            )\n        )\n\n        if not assistant_messages.data:\n            raise ValueError(\"No messages received from assistant\")\n\n        # Get the last message's content\n        last_message = assistant_messages.data[0]\n        if not last_message.content:\n            raise ValueError(f\"No content in the last message: {last_message}\")\n\n        # Extract text content\n        text_content = [content for content in last_message.content if content.type == \"text\"]\n        if not text_content:\n            raise ValueError(f\"Expected text content in the last message: {last_message.content}\")\n\n        # Return the assistant's response as a Response with inner messages\n        chat_message = TextMessage(source=self.name, content=text_content[0].text.value)\n        yield Response(chat_message=chat_message, inner_messages=inner_messages)\n\n    async def handle_incoming_message(self, message: BaseChatMessage, cancellation_token: CancellationToken) -> None:\n        \"\"\"Handle regular text messages by adding them to the thread.\"\"\"\n        content: str | List[MessageContentPartParam] | None = None\n        llm_message = message.to_model_message()\n        if isinstance(llm_message.content, str):\n            content = llm_message.content\n        else:\n            content = []","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py#L492-L528","documentation":"The last message fetched from the assistant thread exists (assistant_messages.data is non-empty) but its content field is empty/None, so the agent cannot build a TextMessage. Content is normally a list of content-part objects (text, image_file, ...); an empty list means the assistant produced a message with no body.","triggerScenarios":"Assistant emits only an image_file content part that is later stripped, or a run ends after tool calls with an empty final message; edge cases in the Assistants API where the newest message is a placeholder with no content parts.","commonSituations":"Runs that finish via tool-call paths with no final textual answer; content filtering removing output; fetching limit=1 grabbing a non-final message when ordering/limitation behaves unexpectedly.","solutions":["Retry the turn — ask the model to produce a textual answer; add an instruction like 'Always finish with a short text summary.'","Inspect the thread manually: client.beta.threads.messages.list(thread_id=..., limit=5) to see what content parts the last messages actually carry.","Upgrade autogen-ext; handling of non-text final messages in on_messages_stream has been improved in later releases."],"exampleFix":"# before\ninstructions = \"You are a helpful assistant.\"\n\n# after\ninstructions = (\n    \"You are a helpful assistant. \"\n    \"Always conclude each turn with a plain-text answer to the user.\"\n)","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        follow_up = [TextMessage(source=\"user\", content=\"Please answer in plain text.\")]\n        resp = await agent.on_messages(msgs + follow_up, ct)\n    else:\n        raise","preventionTips":["Instruct the assistant to always finish with a text answer.","Inspect thread messages directly when output shape is uncertain.","Stay current on autogen-ext releases that improve non-text handling."],"tags":["openai","assistants-api","messages","content"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}