microsoft/semantic-kernel · error · AgentExecutionException
{type(agent)} service failed to complete the request
Error message
{type(agent)} service failed to complete the request What it means
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__.
Source
Thrown at python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py:631
instructions=merged_instructions or agent.instructions,
previous_response_id=previous_response_id,
store=store_output_enabled,
tools=tools, # type: ignore
stream=stream,
**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)View on GitHub (pinned to c028a0c7dc)
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.
Example fix
# before
response = await agent.invoke(thread=thread)
# after - catch AgentExecutionException, inspect cause, retry on transient
from semantic_kernel.exceptions import AgentExecutionException
import openai
try:
response = await agent.invoke(thread=thread)
except AgentExecutionException as ex:
cause = ex.__cause__
if isinstance(cause, openai.RateLimitError):
await asyncio.sleep(backoff)
response = await agent.invoke(thread=thread)
else:
raise Defensive patterns
Strategy: retry
Validate before calling
# Validate credentials/endpoint are set before invoking:
import os
assert os.environ.get("OPENAI_API_KEY"), "OPENAI_API_KEY not set"
assert agent.client.base_url, "client base_url not configured" Try / catch
from semantic_kernel.exceptions import AgentExecutionException
import openai
async def invoke_with_retry(agent, thread, attempts=3):
for i in range(attempts):
try:
return [m async for _, m in agent.invoke(thread=thread)]
except AgentExecutionException as ex:
cause = ex.__cause__
if isinstance(cause, openai.RateLimitError) and i < attempts - 1:
await asyncio.sleep(2 ** i)
continue
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Agent Failure - Run terminated: {run.Status} [{run.Id}]: {ru
- Agent Failure - Run not created for thread: ${threadId}
- Failed to retrieve messages for thread `{thread_id}`.
- Failed to search the collection.
- Astra DB not available. Status : {response}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/9a9a46cce46d651d.
Report an issue: GitHub.