{"record":{"id":"9a9a46cce46d651d","repo":"microsoft/semantic-kernel","slug":"type-agent-service-failed-to-complete-the-reque","errorCode":null,"errorMessage":"{type(agent)} service failed to complete the request","messagePattern":"(.+?) service failed to complete the request","errorType":"exception","errorClass":"AgentExecutionException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py","lineNumber":631,"sourceCode":"                instructions=merged_instructions or agent.instructions,\n                previous_response_id=previous_response_id,\n                store=store_output_enabled,\n                tools=tools,  # type: ignore\n                stream=stream,\n                **response_options,\n            )\n        except BadRequestError as ex:\n            if ex.code == \"content_filter\":\n                raise ContentFilterAIException(\n                    f\"{type(agent)} encountered a content error\",\n                    ex,\n                ) from ex\n            raise AgentExecutionException(\n                f\"{type(agent)} failed to complete the request\",\n                ex,\n            ) from ex\n        except Exception as ex:\n            raise AgentExecutionException(\n                f\"{type(agent)} service failed to complete the request\",\n                ex,\n            ) from ex\n        if response is None:\n            raise AgentInvokeException(\"Response is None\")\n        return response\n\n    @classmethod\n    async def _poll_until_completed(\n        cls: type[_T],\n        agent: \"OpenAIResponsesAgent\",\n        response: Response,\n        polling_options: \"RunPollingOptions\",\n    ):\n        count = 0\n        while response.status != \"completed\":\n            await asyncio.sleep(polling_options.get_polling_interval(count).total_seconds())\n            response = await agent.client.responses.retrieve(response.id)","sourceCodeStart":613,"sourceCodeEnd":649,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py#L613-L649","documentation":"Raised as an AgentExecutionException when agent.client.responses.create raises any Exception that is NOT a BadRequestError (i.e. not a 400). This is the catch-all for transport/auth/rate-limit/server errors from the OpenAI SDK during a non-streaming Responses create. The original exception is chained as the cause, so the real error is always inspectable via __cause__.","triggerScenarios":"responses.create throws e.g. openai.RateLimitError (429), openai.AuthenticationException (401), openai.APIConnectionError (network), openai.InternalServerError (5xx), or any other non-BadRequest SDK exception. Falls through the `except Exception` branch in _get_response.","commonSituations":"Invalid/expired API key (401); exceeding rate limits or quota (429); network outages/DNS failures to the API; OpenAI/Azure-side 5xx incidents; missing AZURE_OPENAI_ENDPOINT or wrong base_url; SDK version mismatch causing unexpected exception types; SSL/proxy misconfiguration.","solutions":["Inspect the chained __cause__ exception to identify the exact HTTP status (401/429/5xx) and message.","For 401/403, verify the API key / Azure credentials and endpoint configuration.","For 429, implement backoff/retry (respect Retry-After) or reduce request frequency.","For connection errors, check network/proxy/SSL settings and endpoint reachability.","Update the openai SDK to a compatible version if an unexpected exception type is surfacing."],"exampleFix":"# before\nresponse = await agent.invoke(thread=thread)\n# after - catch AgentExecutionException, inspect cause, retry on transient\nfrom semantic_kernel.exceptions import AgentExecutionException\nimport openai\ntry:\n    response = await agent.invoke(thread=thread)\nexcept AgentExecutionException as ex:\n    cause = ex.__cause__\n    if isinstance(cause, openai.RateLimitError):\n        await asyncio.sleep(backoff)\n        response = await agent.invoke(thread=thread)\n    else:\n        raise","handlingStrategy":"retry","validationCode":"# Validate credentials/endpoint are set before invoking:\nimport os\nassert os.environ.get(\"OPENAI_API_KEY\"), \"OPENAI_API_KEY not set\"\nassert agent.client.base_url, \"client base_url not configured\"","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import AgentExecutionException\nimport openai\nasync def invoke_with_retry(agent, thread, attempts=3):\n    for i in range(attempts):\n        try:\n            return [m async for _, m in agent.invoke(thread=thread)]\n        except AgentExecutionException as ex:\n            cause = ex.__cause__\n            if isinstance(cause, openai.RateLimitError) and i < attempts - 1:\n                await asyncio.sleep(2 ** i)\n                continue\n            raise","preventionTips":["Validate API credentials and endpoint configuration before running.","Implement exponential backoff for 429/5xx transient errors.","Verify network/proxy reachability to the API in your environment."],"tags":["openai-responses","network","auth","rate-limit","transient"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}