microsoft/semantic-kernel · error · AgentInvokeException

Response is not of type Response

Error message

Response is not of type Response

What it means

Raised by ResponsesAgentThreadActions.invoke() when the object returned by _get_response() is not an instance of the openai Response type. The loop expects a concrete Response to read .id, .status, .error, etc.; a different type means the underlying client call returned something unexpected (error object, raw dict, or a different model class). This is an internal contract violation between the SDK wrapper and the agent.

Source

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

            # Use the thread chat history
            override_history = ChatHistory(messages=[*thread._chat_history.messages, *chat_history.messages])

        previous_response_id = None
        if thread.store_enabled and thread.response_id:
            previous_response_id = thread.response_id

        for request_index in range(function_choice_behavior.maximum_auto_invoke_attempts):
            response = await cls._get_response(
                agent=agent,
                chat_history=override_history,
                merged_instructions=merged_instructions,
                previous_response_id=previous_response_id,
                store_output_enabled=store_enabled,
                tools=tools,
                response_options=response_options,
            )
            if not isinstance(response, Response):
                raise AgentInvokeException("Response is not of type Response")

            if store_enabled:
                thread.response_id = response.id
                # Chain subsequent requests to this response so tool outputs are associated correctly
                previous_response_id = response.id

            if response.status in cls.error_message_states:
                error_message = ""
                if response.error and response.error.message:
                    error_message = response.error.message
                incomplete_details = ""
                if response.incomplete_details:
                    incomplete_details = str(response.incomplete_details.reason)
                raise AgentInvokeException(
                    f"Run failed with status: `{response.status}` for agent `{agent.name}` "
                    f"with error: {error_message} or incomplete details: {incomplete_details}"
                )

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pin the openai package version that semantic_kernel declares as compatible (check the project's requirements).
  2. If using a custom client, ensure its responses.create() returns an openai Response instance.
  3. Inspect type(response) by temporarily logging it before the guard fires.
  4. Update semantic_kernel to a release aligned with your openai SDK version.

Example fix

// before
# openai==x.y.z (mismatched)
client = AsyncOpenAI(api_key=...)
agent = OpenAIResponsesAgent(client=client, ...)

// after
# pin compatible version per semantic_kernel requirements
client = AsyncOpenAI(api_key=...)
agent = OpenAIResponsesAgent(client=client, ...)
Defensive patterns

Strategy: type-guard

Validate before calling

from openai import AsyncOpenAI
from openai.types.responses import Response
client = AsyncOpenAI(api_key=...)
resp = await client.responses.create(model='gpt-4o', input='test')
assert isinstance(resp, Response), 'SDK returned unexpected type'

Type guard

from openai.types.responses import Response
def is_openai_response(obj) -> bool:
    return isinstance(obj, Response)

Try / catch

from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException
try:
    async for item in agent.invoke(messages='hi', thread=thread):
        ...
except AgentInvokeException as e:
    if 'not of type Response' in str(e):
        # openai SDK version mismatch — pin compatible version
        raise RuntimeError('openai SDK version incompatible with semantic_kernel')
    raise

Prevention

When it happens

Trigger: An openai SDK version mismatch where client.responses.create returns a different type than `Response`, a monkeypatch/custom client that yields a non-Response object, or a degraded response the SDK wrapped in an error-like object without raising. The check runs on every iteration of the auto-invoke loop.

Common situations: Upgrading/downgrading the openai package without matching semantic_kernel's expected version, passing a custom AsyncOpenAI-compatible client whose responses.create returns a different model, or an SDK regression. The type guard `isinstance(response, Response)` fails before any field access.

Related errors


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