microsoft/semantic-kernel · error · AgentInvokeException

Response is None

Error message

Response is None

What it means

Raised as an AgentInvokeException("Response is None") defensively at the end of _get_response, after the try/except around responses.create. It guards the (theoretically possible but rare) case where the SDK returns None instead of raising, so downstream code that assumes a Response object does not fail with an AttributeError.

Source

Thrown at python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py:636

                **response_options,
            )
        except BadRequestError as ex:
            if ex.code == "content_filter":
                raise ContentFilterAIException(
                    f"{type(agent)} encountered a content error",
                    ex,
                ) from ex
            raise AgentExecutionException(
                f"{type(agent)} failed to complete the request",
                ex,
            ) from ex
        except Exception as ex:
            raise AgentExecutionException(
                f"{type(agent)} service failed to complete the request",
                ex,
            ) from ex
        if response is None:
            raise AgentInvokeException("Response is None")
        return response

    @classmethod
    async def _poll_until_completed(
        cls: type[_T],
        agent: "OpenAIResponsesAgent",
        response: Response,
        polling_options: "RunPollingOptions",
    ):
        count = 0
        while response.status != "completed":
            await asyncio.sleep(polling_options.get_polling_interval(count).total_seconds())
            response = await agent.client.responses.retrieve(response.id)
            count += 1
        return response

    @classmethod
    async def get_messages(

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. If testing with a mock client, ensure responses.create returns a valid Response object (or raises).
  2. Upgrade the openai SDK to a stable release if using a custom client.
  3. Inspect logs for the request that produced a None response to identify the trigger.
  4. If using a proxy/gateway, confirm it returns a well-formed Responses payload.

Example fix

# In tests, ensure the fake client returns a Response:
mock_client.responses.create = AsyncMock(return_value=make_response(status="completed"))
Defensive patterns

Strategy: validation

Validate before calling

# In tests, ensure the fake client returns a Response object:
assert mock_client.responses.create.return_value is not None

Type guard

from openai.types.responses import Response
def is_valid_response(obj) -> bool:
    return isinstance(obj, Response) and getattr(obj, "status", None) is not None

Try / catch

from semantic_kernel.exceptions import AgentInvokeException
try:
    async for _, m in agent.invoke(thread=thread):
        ...
except AgentInvokeException as ex:
    if str(ex) == "Response is None":
        # indicates SDK/mock regression - investigate the client
        ...

Prevention

When it happens

Trigger: agent.client.responses.create completes without raising but returns None (or a falsy value). This should not happen with the current OpenAI SDK under normal operation; it would indicate a SDK bug, a custom/mock client returning None, or an unusual transport edge case.

Common situations: Using a mock/fake client in tests that forgets to return a Response; an openai SDK regression; a custom AsyncOpenAI-compatible client that returns None on certain errors instead of raising; SDK version skew.

Related errors


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