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 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.

Source

Thrown at python/semantic_kernel/agents/azure_ai/azure_ai_agent.py:740

            "metadata": metadata,
        }
        run_level_params = {k: v for k, v in run_level_params.items() if v is not None}

        response_messages: list[ChatMessageContent] = []
        async for is_visible, response in AgentThreadActions.invoke(
            agent=self,
            thread_id=thread.id,
            kernel=kernel,
            arguments=arguments,
            function_choice_behavior=function_choice_behavior,
            **run_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,
        model: str | None = None,
        instructions_override: str | None = None,
        additional_instructions: str | None = None,
        additional_messages: list[ThreadMessageOptions] | None = None,

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Inspect intermediate messages via on_intermediate_message / invoke() streaming to see what the run actually produced.
  2. Ensure function_choice_behavior lets the model produce a final assistant message after tool calls (auto with required auto).
  3. Check the run status/logs for content_filtered or incomplete statuses from the service.
  4. Retry the call; if persistent, simplify the prompt/tools to isolate whether the model returns text.

Example fix

// before
resp = await agent.get_response(messages, thread=thread)  // raises if no visible msg
// after
async for msg in agent.invoke(messages, thread=thread):
    print(msg.message.content)  // inspect all steps
# or supply on_intermediate_message to capture tool/code outputs
Defensive patterns

Strategy: try-catch

Try / catch

from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException
try:
    resp = await agent.get_response(messages, thread=thread)
except AgentInvokeException as e:
    if 'No response messages' in str(e):
        log.warning('Run produced no visible message; inspect intermediate steps')
        async for msg in agent.invoke(messages, thread=thread,
                                      on_intermediate_message=handle):
            ...  # fall back to streaming/intermediate inspection
    else:
        raise

Prevention

When it happens

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

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

Related errors


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