{"record":{"id":"54b47f729c8d58fe","repo":"microsoft/semantic-kernel","slug":"no-response-messages-were-returned-from-the-agent-54b47f","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_responses_agent.py","lineNumber":935,"sourceCode":"        assert function_choice_behavior is not None  # nosec\n\n        response_messages: list[ChatMessageContent] = []\n        async for is_visible, response in ResponsesAgentThreadActions.invoke(\n            agent=self,\n            chat_history=chat_history,\n            thread=thread,\n            store_enabled=self.store_enabled,\n            kernel=kernel,\n            arguments=arguments,\n            function_choice_behavior=function_choice_behavior,\n            **response_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        include: list[\n            Literal[\n                \"file_search_call.results\", \"message.input_image.image_url\", \"computer_call_output.output.image_url\"\n            ]","sourceCodeStart":917,"sourceCodeEnd":953,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/openai_responses_agent.py#L917-L953","documentation":"Raised by get_response() when, after iterating the full invoke loop, the response_messages list is empty. Messages are only appended when is_visible is True and response.metadata['code'] is not True, so this fires when every yielded item was filtered out as non-visible or code-internal. The agent produced output but none surfaced as a user-facing message.","triggerScenarios":"An invocation where all streamed/yielded responses are tool calls, reasoning, or other non-visible intermediate steps, and no final assistant text message is produced (e.g. the model only emitted function calls and the loop ended without a summarizing message).","commonSituations":"A function-calling loop that terminates on tool outputs without a final synthesis message, a model that returns only reasoning/incomplete responses, or content filters/metadata causing every message to be marked non-visible. Distinct from an API error — the call succeeded but yielded no consumable message.","solutions":["Inspect the raw streamed items (use invoke() and log every is_visible/response pair) to see what was produced.","Ensure function_choice_behavior allows a final synthesizing turn after tool calls.","Check that the model is not returning only reasoning tokens; lower/adjust reasoning or use a model that emits final text.","Catch AgentInvokeException and provide a fallback message to the user."],"exampleFix":"// before\nresult = await agent.get_response(messages=\"summarize\", thread=thread)\n\n// after\nfrom semantic_kernel.exceptions.agent_exceptions import AgentInvokeException\ntry:\n    result = await agent.get_response(messages=\"summarize\", thread=thread)\nexcept AgentInvokeException:\n    result = None  # handle no-visible-message case","handlingStrategy":"try-catch","validationCode":"# No deterministic pre-check; use invoke() to inspect items, or catch at get_response()\nasync for item in agent.invoke(messages='hi', thread=thread):\n    pass  # observe what is yielded before relying on get_response()","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException\ntry:\n    result = await agent.get_response(messages=msg, thread=thread)\nexcept AgentInvokeException as e:\n    if 'No response messages' in str(e):\n        result = None  # provide a fallback to the user\n    raise","preventionTips":["Ensure function_choice_behavior permits a final synthesis turn after tool calls.","Log every yielded (is_visible, response) pair from invoke() to diagnose empty output.","Provide a user-facing fallback message when no visible response is produced."],"tags":["invocation","response-messages","function-calling"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}