{"record":{"id":"1693756be0d93a41","repo":"microsoft/semantic-kernel","slug":"agent-did-not-reach-status-status-within-the-spe","errorCode":null,"errorMessage":"Agent did not reach status {status} within the specified time.","messagePattern":"Agent did not reach status (.+?) within the specified time\\.","errorType":"exception","errorClass":"TimeoutException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/Bedrock/Extensions/BedrockAgentExtensions.cs","lineNumber":278,"sourceCode":"        Amazon.BedrockAgent.Model.Agent agent,\n        AgentStatus status,\n        int interval = 2,\n        int maxAttempts = 5,\n        CancellationToken cancellationToken = default)\n    {\n        for (var i = 0; i < maxAttempts; i++)\n        {\n            var getAgentResponse = await client.GetAgentAsync(new() { AgentId = agent.AgentId }, cancellationToken).ConfigureAwait(false);\n\n            if (getAgentResponse.Agent.AgentStatus == status)\n            {\n                return getAgentResponse.Agent;\n            }\n\n            await Task.Delay(interval * 1000, cancellationToken).ConfigureAwait(false);\n        }\n\n        throw new TimeoutException($\"Agent did not reach status {status} within the specified time.\");\n    }\n}\n","sourceCodeStart":260,"sourceCodeEnd":281,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/Bedrock/Extensions/BedrockAgentExtensions.cs#L260-L281","documentation":"Thrown after a bounded polling loop that repeatedly calls GetAgentAsync waiting for an agent to reach a target AgentStatus (e.g., PREPARED). The loop runs `maxAttempts` times with a fixed `interval` (in seconds) delay between checks. If the status never matches within the budgeted attempts, a TimeoutException is raised. This is used after agent creation or updates that trigger an asynchronous preparation step.","triggerScenarios":"Calling the WaitForAgentStatusAsync (or similarly named) extension after creating/updating a Bedrock agent, when the agent remains in PREPARING or another transitional state longer than maxAttempts * interval seconds. Common when the agent's knowledge base or action groups are large, causing slow preparation.","commonSituations":"Default polling budget too small for agents with large knowledge bases; AWS-side preparation delays; the agent stuck in a FAILED status (never reaches the target); incorrect target status passed.","solutions":["Increase the maxAttempts and/or interval parameters passed to the wait method to allow more time for preparation.","Check the agent's actual current status via GetAgentAsync — if it is FAILED, fix the underlying configuration rather than waiting longer.","Verify the agent's action groups, knowledge bases, and model ID are correctly configured so preparation can complete.","If this is in CI/automated flow, raise the timeout budget or poll status separately and handle FAILED explicitly."],"exampleFix":"// before\nawait agent.WaitForAgentStatusAsync(AgentStatus.Prepared, maxAttempts: 30, interval: 2, cancellationToken);\n\n// after — more time + explicit failure handling\nvar status = await GetAgentStatusSafelyAsync(agent);\nif (status == AgentStatus.Failed) throw new InvalidOperationException(\"Agent preparation failed; check configuration.\");\nawait agent.WaitForAgentStatusAsync(AgentStatus.Prepared, maxAttempts: 120, interval: 5, cancellationToken);","handlingStrategy":"retry","validationCode":"// Check current status first; bail early if already failed\nvar current = await client.GetAgentAsync(new() { AgentId = agent.AgentId }, cancellationToken);\nif (current.Agent.AgentStatus == AgentStatus.Failed)\n    throw new InvalidOperationException(\"Agent is in FAILED status; will never reach target.\");","typeGuard":"static bool IsTerminalFailure(AgentStatus s) => s == AgentStatus.Failed;","tryCatchPattern":"try\n{\n    await agent.WaitForAgentStatusAsync(AgentStatus.Prepared, maxAttempts: 120, interval: 5, cancellationToken);\n}\ncatch (TimeoutException ex)\n{\n    var s = await client.GetAgentAsync(new() { AgentId = agent.AgentId });\n    logger.LogError(\"Agent stuck at {Status} after polling. {Msg}\", s.Agent.AgentStatus, ex.Message);\n    throw;\n}","preventionTips":["Size maxAttempts and interval to your agent's complexity (large knowledge bases take longer to prepare).","Check for FAILED status explicitly before/independent of the polling loop.","Validate agent config (model ID, action groups, knowledge bases) so preparation can complete."],"tags":["bedrock","agents","timeout","polling","status","csharp"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}