{"record":{"id":"0df0b15e1a049a58","repo":"microsoft/semantic-kernel","slug":"agent-failure-run-terminated-run-status-run","errorCode":null,"errorMessage":"Agent Failure - Run terminated: {run.Status} [{run.Id}]: {run.LastError?.Message ?? \"Unknown\"}","messagePattern":"Agent Failure - Run terminated: (.+?) \\[(.+?)\\]: (.+?)","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/AzureAI/Internal/AgentThreadActions.cs","lineNumber":181,"sourceCode":"        FunctionCallsProcessor functionProcessor = new(logger);\n        // This matches current behavior.  Will be configurable upon integrating with `FunctionChoice` (#6795/#5200)\n        FunctionChoiceBehaviorOptions functionOptions = new() { AllowConcurrentInvocation = true, AllowParallelCalls = true };\n\n        // Evaluate status and process steps and messages, as encountered.\n        HashSet<string> processedStepIds = [];\n        Dictionary<string, FunctionResultContent> functionSteps = [];\n        do\n        {\n            // Check for cancellation\n            cancellationToken.ThrowIfCancellationRequested();\n\n            // Poll run and steps until actionable\n            await PollRunStatusAsync().ConfigureAwait(false);\n\n            // Is in terminal state?\n            if (s_failureStatuses.Contains(run.Status))\n            {\n                throw new KernelException($\"Agent Failure - Run terminated: {run.Status} [{run.Id}]: {run.LastError?.Message ?? \"Unknown\"}\");\n            }\n\n            List<RunStep> steps = [];\n            await foreach (var step in client.GetStepsAsync(run, cancellationToken: cancellationToken).ConfigureAwait(false))\n            {\n                steps.Add(step);\n            }\n\n            // Is tool action required?\n            if (run.Status == RunStatus.RequiresAction)\n            {\n                logger.LogAzureAIAgentProcessingRunSteps(nameof(InvokeAsync), run.Id, threadId);\n\n                // Execute functions in parallel and post results at once.\n                FunctionCallContent[] functionCalls = [.. steps.SelectMany(step => ParseFunctionStep(agent, step))];\n                if (functionCalls.Length > 0)\n                {\n                    // Emit function-call content","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/AzureAI/Internal/AgentThreadActions.cs#L163-L199","documentation":"Thrown inside the non-streaming InvokeAsync poll loop (AgentThreadActions) when, after polling, the Azure AI agent run reached one of the failure statuses: Cancelled, Expired, or Failed (the s_failureStatuses set). The message includes the run status, run Id, and the LastError message (or 'Unknown'). This is a runtime/agent-execution failure, not a configuration error.","triggerScenarios":"An assistant run on the Azure AI service transitions to RunStatus.Failed, RunStatus.Cancelled, or RunStatus.Expired during invocation. Common upstream causes: content-filter trigger, token/quota exhaustion, model error, the run being explicitly cancelled, or the run expiring after inactivity.","commonSituations":"Prompt content tripped the content filter; Azure OpenAI quota hit; long-running run expired; concurrent cancellation token fired but the service reported Cancelled; transient backend error surfaced as Failed.","solutions":["Inspect the run.LastError.Message in the exception to identify the upstream cause.","For content-filter failures, revise the prompt/input content.","For quota/rate-limit failures, retry with backoff and check subscription usage.","For Expired, reduce run duration or re-invoke; for Cancelled, check whether a cancellation token was triggered.","Correlate using the run.Id with Azure service logs/diagnostics."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await agent.InvokeAsync(messages, thread, ct); }\ncatch (KernelException ex) when (ex.Message.Contains(\"Run terminated\"))\n{\n    // ex.Message contains run.Status, run.Id, and LastError.Message\n    logger.LogError(\"Azure AI run failed: {Msg}\", ex.Message);\n    // apply backoff/retry for transient statuses, or surface content-filter errors\n}","preventionTips":["Log run.Id and LastError for every run failure to enable correlation.","Implement retry with exponential backoff for Failed/Expired, but fix content-filter root causes instead of retrying.","Monitor Azure subscription quota to avoid Expired/Failed from throttling."],"tags":["runtime","azureai","agent-run","network","transient"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}