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

Source

Thrown at python/semantic_kernel/agents/open_ai/openai_assistant_agent.py:844

            "polling_options": polling_options,
        }
        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 AssistantThreadActions.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,
        additional_instructions: str | None = None,
        additional_messages: list[ChatMessageContent] | None = None,
        instructions_override: str | None = None,
        kernel: "Kernel | None" = None,
        max_completion_tokens: int | None = None,

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Inspect the raw invoke stream (AssistantThreadActions.invoke) to see what message types were actually produced.
  2. If using code_interpreter, follow up to prompt the model to emit a text summary, or read the code message metadata explicitly.
  3. Ensure function_choice_behavior is set to Auto and the run completes with a final assistant message.
  4. Retry the invocation; transient empty runs can occur with certain tool configurations.

Example fix

# before
resp = await agent.get_response('run this code', thread=thread)

# after
# debug what was yielded
async for is_visible, msg in AssistantThreadActions.invoke(agent=agent, thread_id=thread.id, kernel=kernel, arguments=KernelArguments()):
    print(is_visible, msg.metadata)
# then adjust prompt/function_choice_behavior so a visible final message is produced
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException
try:
    resp = await agent.get_response(prompt, thread=thread)
except AgentInvokeException as e:
    if 'No response messages' in str(e):
        resp = await agent.get_response(prompt + '\nPlease summarize the result.', thread=thread)

Prevention

When it happens

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

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

Related errors


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