{"record":{"id":"2774c0cd9e02283a","repo":"microsoft/semantic-kernel","slug":"no-response-messages-were-returned-from-the-agent-2774c0","errorCode":null,"errorMessage":"No response messages were returned from the agent.","messagePattern":"No response messages were returned from the agent\\.","errorType":"exception","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/openai_assistant_agent.py","lineNumber":844,"sourceCode":"            \"polling_options\": polling_options,\n        }\n        run_level_params = {k: v for k, v in run_level_params.items() if v is not None}\n\n        response_messages: list[ChatMessageContent] = []\n        async for is_visible, response in AssistantThreadActions.invoke(\n            agent=self,\n            thread_id=thread.id,\n            kernel=kernel,\n            arguments=arguments,\n            function_choice_behavior=function_choice_behavior,\n            **run_level_params,  # type: ignore\n        ):\n            if is_visible and response.metadata.get(\"code\") is not True:\n                response.metadata[\"thread_id\"] = thread.id\n                response_messages.append(response)\n\n        if not response_messages:\n            raise AgentInvokeException(\"No response messages were returned from the agent.\")\n        final_message = response_messages[-1]\n        await thread.on_new_message(final_message)\n        return AgentResponseItem(message=final_message, thread=thread)\n\n    @trace_agent_invocation\n    @override\n    async def invoke(\n        self,\n        messages: str | ChatMessageContent | list[str | ChatMessageContent] | None = None,\n        *,\n        thread: AgentThread | None = None,\n        on_intermediate_message: Callable[[ChatMessageContent], Awaitable[None]] | None = None,\n        arguments: KernelArguments | None = None,\n        additional_instructions: str | None = None,\n        additional_messages: list[ChatMessageContent] | None = None,\n        instructions_override: str | None = None,\n        kernel: \"Kernel | None\" = None,\n        max_completion_tokens: int | None = None,","sourceCodeStart":826,"sourceCodeEnd":862,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/openai_assistant_agent.py#L826-L862","documentation":"Raised as an AgentInvokeException by get_response() after the AssistantThreadActions.invoke loop completes with zero visible response messages. Only messages flagged is_visible and without metadata 'code' == True are collected; if every yielded message was a hidden/code/tool message, response_messages stays empty and the agent cannot return a final user-facing message.","triggerScenarios":"A run that produced only tool/code-interpreter outputs and no visible assistant text; a run that ended in a status yielding no content messages; filters excluding all messages; the model returning only function-call frames that are not surfaced as visible.","commonSituations":"Code interpreter runs whose only output is a code block; function-calling heavy runs where no final synthesis message is emitted; truncated runs; misconfigured function_choice_behavior suppressing the final message.","solutions":["Inspect the raw invoke stream (AssistantThreadActions.invoke) to see what message types were actually produced.","If using code_interpreter, follow up to prompt the model to emit a text summary, or read the code message metadata explicitly.","Ensure function_choice_behavior is set to Auto and the run completes with a final assistant message.","Retry the invocation; transient empty runs can occur with certain tool configurations."],"exampleFix":"# before\nresp = await agent.get_response('run this code', thread=thread)\n\n# after\n# debug what was yielded\nasync for is_visible, msg in AssistantThreadActions.invoke(agent=agent, thread_id=thread.id, kernel=kernel, arguments=KernelArguments()):\n    print(is_visible, msg.metadata)\n# then adjust prompt/function_choice_behavior so a visible final message is produced","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException\ntry:\n    resp = await agent.get_response(prompt, thread=thread)\nexcept AgentInvokeException as e:\n    if 'No response messages' in str(e):\n        resp = await agent.get_response(prompt + '\\nPlease summarize the result.', thread=thread)","preventionTips":["Prompt the model to emit a final text message.","Inspect the invoke stream when empty.","Ensure function_choice_behavior=Auto completes the run."],"tags":["runtime","agents","openai-assistant","invoke","empty-response"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}