microsoft/semantic-kernel · error · AgentInvokeException
Polling timed out before completion.
Error message
Polling timed out before completion.
What it means
Raised as an AgentInvokeException when the polling loop that waits for a non-streaming OpenAI Responses run to reach "completed" exceeds agent.polling_options.run_polling_timeout. The Responses API returns runs that are processed server-side, so Semantic Kernel polls responses.retrieve until status == "completed"; if that does not happen within the configured deadline, this fires.
Source
Thrown at python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py:219
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}"
)
try:
response = await asyncio.wait_for(
cls._poll_until_completed(agent, response, polling_options or agent.polling_options),
timeout=agent.polling_options.run_polling_timeout.total_seconds(),
)
except asyncio.TimeoutError:
raise AgentInvokeException("Polling timed out before completion.")
# Type narrowing for subsequent usage
assert isinstance(response, Response) # nosec
# Extract reasoning content and yield as intermediate message (not visible to user)
reasoning_items = cls._get_reasoning_items_from_output(response.output) # type: ignore
if reasoning_items:
reasoning_message = ChatMessageContent(
role=AuthorRole.ASSISTANT,
items=cast(list[CMC_ITEM_TYPES], reasoning_items),
ai_model_id=agent.ai_model_id,
metadata=cls._get_metadata_from_response(response),
name=agent.name,
)
yield False, reasoning_message
# Check if tool calls are required
function_calls = cls._get_tool_calls_from_output(response.output) # type: ignoreView on GitHub (pinned to c028a0c7dc)
Solutions
- Increase agent.polling_options.run_polling_timeout to a larger timedelta.
- Tune polling_options polling interval/strategy via RunPollingOptions so polls are neither too sparse nor too aggressive.
- Reduce the run's complexity (fewer tools, smaller context) so it completes faster.
- Verify network connectivity/latency to the OpenAI endpoint; a slow link makes each retrieve poll expensive.
- If using Azure, check the deployment region/provisioned throughput for slowness.
Example fix
# before
agent = OpenAIResponsesAgent(
ai_model_id="gpt-4o",
client=client,
instructions="...",
)
# after - give long tool-using runs a larger polling budget
from semantic_kernel.agents.open_ai import RunPollingOptions
agent.polling_options = RunPollingOptions(run_polling_timeout=timedelta(minutes=5)) Defensive patterns
Strategy: retry
Validate before calling
# Confirm the polling timeout fits the worst-case run before invoking:
from datetime import timedelta
if agent.polling_options.run_polling_timeout < timedelta(seconds=30):
agent.polling_options.run_polling_timeout = timedelta(minutes=3) Try / catch
from semantic_kernel.exceptions import AgentInvokeException
attempt = 0
while True:
try:
async for is_final, msg in agent.invoke(thread=thread):
...
break
except AgentInvokeException as ex:
if "Polling timed out" not in str(ex) or attempt >= 2:
raise
attempt += 1 # retry after widening the budget
agent.polling_options.run_polling_timeout *= 2 Prevention
- Size run_polling_timeout to the slowest expected run (multi-tool, large output).
- Monitor average run completion times and adjust the budget accordingly.
- Keep the polling interval reasonable so retrieve calls are not too sparse.
When it happens
Trigger: asyncio.wait_for around _poll_until_completed (which loops calling agent.client.responses.retrieve until status == "completed") hits the timeout configured at agent.polling_options.run_polling_timeout. Happens on long-running runs (complex tool use, large outputs), slow backend, or a polling interval/time budget misconfiguration in RunPollingOptions.
Common situations: Default run_polling_timeout too short for heavy multi-step tool-calling runs; network latency to OpenAI inflating each retrieve round-trip; backend slowness during peak load; RunPollingOptions misconfigured with a tiny timeout; runs that legitimately need many tool invocations.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Agent did not reach status {status} within the specified tim
- Polling timed out for run id: `{run.id}` and thread id: `{th
- Agent did not reach status {status} within the specified tim
- Polling timed out for run id: `{run.id}` and thread id: `{th
- Run failed with status: `{response.status}` for agent `{agen
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/94f18536ac958a3a.
Report an issue: GitHub.