{"record":{"id":"a9fcd4770336ed08","repo":"microsoft/semantic-kernel","slug":"agent-did-not-reach-status-status-within-the-spe-a9fcd4","errorCode":null,"errorMessage":"Agent did not reach status {status} within the specified time. Current status: {self.agent_model.agent_status}","messagePattern":"Agent did not reach status (.+?) within the specified time\\. Current status: (.+?)","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/bedrock/bedrock_agent_base.py","lineNumber":178,"sourceCode":"        except ClientError as e:\n            logger.error(f\"Failed to get agent {self.agent_model.agent_id}.\")\n            raise e\n\n    async def _wait_for_agent_status(\n        self,\n        status: BedrockAgentStatus,\n        interval: int = 2,\n        max_attempts: int = 5,\n    ) -> None:\n        \"\"\"Wait for the agent to reach a specific status.\"\"\"\n        for _ in range(max_attempts):\n            await self._get_agent()\n            if self.agent_model.agent_status == status:\n                return\n\n            await asyncio.sleep(interval)\n\n        raise TimeoutError(\n            f\"Agent did not reach status {status} within the specified time.\"\n            f\" Current status: {self.agent_model.agent_status}\"\n        )\n\n    # endregion Agent Management\n\n    # region Action Group Management\n    async def create_code_interpreter_action_group(self, **kwargs) -> BedrockActionGroupModel:\n        \"\"\"Create a code interpreter action group.\"\"\"\n        if not self.agent_model.agent_id:\n            raise ValueError(\"Agent does not exist. Please create the agent before creating an action group for it.\")\n\n        try:\n            response = await run_in_executor(\n                None,\n                partial(\n                    self.bedrock_client.create_agent_action_group,\n                    agentId=self.agent_model.agent_id,","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/bedrock/bedrock_agent_base.py#L160-L196","documentation":"Raised by _wait_for_agent_status as a TimeoutError when the agent does not reach the target BedrockAgentStatus within max_attempts * interval seconds (default 5 attempts * 2s = 10s). Each attempt calls _get_agent to refresh the status and sleeps if it hasn't matched. Bedrock agent preparation can take longer than the default window, especially under load.","triggerScenarios":"Triggered after max_attempts iterations of the polling loop in _wait_for_agent_status without self.agent_model.agent_status equaling the target status. Called during prepare_agent_and_wait_until_prepared (waits for PREPARING then PREPARED) and create_and_prepare_agent (waits for NOT_PREPARED).","commonSituations":"Bedrock agent preparation taking longer than 10s (common for complex agents with many action groups); AWS region under heavy load; the agent entered FAILED status (never reaches PREPARED); network latency inflating each _get_agent round-trip; default polling window too short for production agents.","solutions":["Retry the operation — Bedrock preparation is often just slow, and a second attempt usually succeeds.","If the agent is in FAILED status, check the AWS console for the failure reason (model access, role, etc.) before retrying.","Increase the polling window by calling _wait_for_agent_status with larger interval/max_attempts if accessible, or wait and re-invoke prepare.","Verify model access is granted and the IAM role is valid, as these cause persistent FAILED status."],"exampleFix":"// before\nawait agent.prepare_agent_and_wait_until_prepared()  # raises TimeoutError after 10s\n\n// after\n# Option 1: retry with backoff\nfor attempt in range(3):\n    try:\n        await agent.prepare_agent_and_wait_until_prepared()\n        break\n    except TimeoutError:\n        await asyncio.sleep(10)\n# Option 2: check status in AWS console; ensure model access + IAM role","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"import asyncio\n\nfor attempt in range(3):\n    try:\n        await agent.prepare_agent_and_wait_until_prepared()\n        break\n    except TimeoutError as e:\n        if \"did not reach status\" in str(e):\n            await asyncio.sleep(15)\n        else:\n            raise\nelse:\n    # check AWS console for FAILED status; verify model access + IAM role\n    raise","preventionTips":["Wrap prepare/create calls in a retry loop with backoff — Bedrock preparation often exceeds the default 10s window.","Confirm the agent is not in FAILED status (model access, IAM role) before retrying.","For large agents, expect longer preparation times and budget retry attempts accordingly.","Monitor the AWS console during agent creation to correlate status transitions."],"tags":["bedrock","timeout","agent-status","polling","preparation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}