{"record":{"id":"1b51823e0f69a38c","repo":"microsoft/semantic-kernel","slug":"response-is-not-of-type-response","errorCode":null,"errorMessage":"Response is not of type Response","messagePattern":"Response is not of type Response","errorType":"exception","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py","lineNumber":194,"sourceCode":"            # Use the thread chat history\n            override_history = ChatHistory(messages=[*thread._chat_history.messages, *chat_history.messages])\n\n        previous_response_id = None\n        if thread.store_enabled and thread.response_id:\n            previous_response_id = thread.response_id\n\n        for request_index in range(function_choice_behavior.maximum_auto_invoke_attempts):\n            response = await cls._get_response(\n                agent=agent,\n                chat_history=override_history,\n                merged_instructions=merged_instructions,\n                previous_response_id=previous_response_id,\n                store_output_enabled=store_enabled,\n                tools=tools,\n                response_options=response_options,\n            )\n            if not isinstance(response, Response):\n                raise AgentInvokeException(\"Response is not of type Response\")\n\n            if store_enabled:\n                thread.response_id = response.id\n                # Chain subsequent requests to this response so tool outputs are associated correctly\n                previous_response_id = response.id\n\n            if response.status in cls.error_message_states:\n                error_message = \"\"\n                if response.error and response.error.message:\n                    error_message = response.error.message\n                incomplete_details = \"\"\n                if response.incomplete_details:\n                    incomplete_details = str(response.incomplete_details.reason)\n                raise AgentInvokeException(\n                    f\"Run failed with status: `{response.status}` for agent `{agent.name}` \"\n                    f\"with error: {error_message} or incomplete details: {incomplete_details}\"\n                )\n","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py#L176-L212","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pin the openai package version that semantic_kernel declares as compatible (check the project's requirements).","If using a custom client, ensure its responses.create() returns an openai Response instance.","Inspect type(response) by temporarily logging it before the guard fires.","Update semantic_kernel to a release aligned with your openai SDK version."],"exampleFix":"// before\n# openai==x.y.z (mismatched)\nclient = AsyncOpenAI(api_key=...)\nagent = OpenAIResponsesAgent(client=client, ...)\n\n// after\n# pin compatible version per semantic_kernel requirements\nclient = AsyncOpenAI(api_key=...)\nagent = OpenAIResponsesAgent(client=client, ...)","handlingStrategy":"type-guard","validationCode":"from openai import AsyncOpenAI\nfrom openai.types.responses import Response\nclient = AsyncOpenAI(api_key=...)\nresp = await client.responses.create(model='gpt-4o', input='test')\nassert isinstance(resp, Response), 'SDK returned unexpected type'","typeGuard":"from openai.types.responses import Response\ndef is_openai_response(obj) -> bool:\n    return isinstance(obj, Response)","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException\ntry:\n    async for item in agent.invoke(messages='hi', thread=thread):\n        ...\nexcept AgentInvokeException as e:\n    if 'not of type Response' in str(e):\n        # openai SDK version mismatch — pin compatible version\n        raise RuntimeError('openai SDK version incompatible with semantic_kernel')\n    raise","preventionTips":["Pin the openai package version declared compatible by semantic_kernel.","Ensure any custom AsyncOpenAI client returns real Response objects from responses.create().","Keep semantic_kernel and openai SDK versions aligned on upgrades."],"tags":["invocation","sdk-version","type-check"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}