{"record":{"id":"b08933ee1ad69c13","repo":"microsoft/semantic-kernel","slug":"no-response-messages-were-returned-from-the-agent","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/azure_ai/azure_ai_agent.py","lineNumber":740,"sourceCode":"            \"metadata\": metadata,\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 AgentThreadActions.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        kernel: Kernel | None = None,\n        model: str | None = None,\n        instructions_override: str | None = None,\n        additional_instructions: str | None = None,\n        additional_messages: list[ThreadMessageOptions] | None = None,","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/azure_ai/azure_ai_agent.py#L722-L758","documentation":"Raised by AzureAIAgent.get_response when, after the invoke loop completes, no visible response messages were collected. Messages are only counted when is_visible is true and metadata 'code' is not True, so a run that produced only tool/code-interpreter outputs (or no outputs at all) leaves the list empty. Surfaced as AgentInvokeException.","triggerScenarios":"The agent run completes but every step was a code-interpreter or tool execution with no final assistant text; the model returned an empty or tool-only completion; the run errored mid-way producing no visible message; filtering removed all messages because they were marked code.","commonSituations":"Code-interpreter-heavy agent that emits only code outputs in a given turn; a misconfigured function_choice_behavior that lets the run end after tool calls without a synthesizing assistant message; model/endpoint issue returning empty completions; the run hit a content filter returning no text.","solutions":["Inspect intermediate messages via on_intermediate_message / invoke() streaming to see what the run actually produced.","Ensure function_choice_behavior lets the model produce a final assistant message after tool calls (auto with required auto).","Check the run status/logs for content_filtered or incomplete statuses from the service.","Retry the call; if persistent, simplify the prompt/tools to isolate whether the model returns text."],"exampleFix":"// before\nresp = await agent.get_response(messages, thread=thread)  // raises if no visible msg\n// after\nasync for msg in agent.invoke(messages, thread=thread):\n    print(msg.message.content)  // inspect all steps\n# or supply on_intermediate_message to capture tool/code outputs","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException\ntry:\n    resp = await agent.get_response(messages, thread=thread)\nexcept AgentInvokeException as e:\n    if 'No response messages' in str(e):\n        log.warning('Run produced no visible message; inspect intermediate steps')\n        async for msg in agent.invoke(messages, thread=thread,\n                                      on_intermediate_message=handle):\n            ...  # fall back to streaming/intermediate inspection\n    else:\n        raise","preventionTips":["Use on_intermediate_message or invoke() to capture all steps, not just the final message.","Confirm function_choice_behavior allows a final assistant message after tool calls.","Watch for content_filter or incomplete run statuses from the service."],"tags":["azure-ai","invocation","agent-response","runtime","debugging"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}