microsoft/semantic-kernel · error · AgentInvokeException

No response messages were returned from the agent.

Error message

No response messages were returned from the agent.

What it means

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.

Source

Thrown at python/semantic_kernel/agents/open_ai/openai_responses_agent.py:935

        assert function_choice_behavior is not None  # nosec

        response_messages: list[ChatMessageContent] = []
        async for is_visible, response in ResponsesAgentThreadActions.invoke(
            agent=self,
            chat_history=chat_history,
            thread=thread,
            store_enabled=self.store_enabled,
            kernel=kernel,
            arguments=arguments,
            function_choice_behavior=function_choice_behavior,
            **response_level_params,  # type: ignore
        ):
            if is_visible and response.metadata.get("code") is not True:
                response.metadata["thread_id"] = thread.id
                response_messages.append(response)

        if not response_messages:
            raise AgentInvokeException("No response messages were returned from the agent.")
        final_message = response_messages[-1]
        await thread.on_new_message(final_message)
        return AgentResponseItem(message=final_message, thread=thread)

    @trace_agent_invocation
    @override
    async def invoke(
        self,
        messages: str | ChatMessageContent | list[str | ChatMessageContent] | None = None,
        *,
        thread: AgentThread | None = None,
        on_intermediate_message: Callable[[ChatMessageContent], Awaitable[None]] | None = None,
        arguments: KernelArguments | None = None,
        kernel: "Kernel | None" = None,
        include: list[
            Literal[
                "file_search_call.results", "message.input_image.image_url", "computer_call_output.output.image_url"
            ]

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Inspect the raw streamed items (use invoke() and log every is_visible/response pair) to see what was produced.
  2. Ensure function_choice_behavior allows a final synthesizing turn after tool calls.
  3. Check that the model is not returning only reasoning tokens; lower/adjust reasoning or use a model that emits final text.
  4. Catch AgentInvokeException and provide a fallback message to the user.

Example fix

// before
result = await agent.get_response(messages="summarize", thread=thread)

// after
from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException
try:
    result = await agent.get_response(messages="summarize", thread=thread)
except AgentInvokeException:
    result = None  # handle no-visible-message case
Defensive patterns

Strategy: try-catch

Validate before calling

# No deterministic pre-check; use invoke() to inspect items, or catch at get_response()
async for item in agent.invoke(messages='hi', thread=thread):
    pass  # observe what is yielded before relying on get_response()

Try / catch

from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException
try:
    result = await agent.get_response(messages=msg, thread=thread)
except AgentInvokeException as e:
    if 'No response messages' in str(e):
        result = None  # provide a fallback to the user
    raise

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/54b47f729c8d58fe. Report an issue: GitHub.