{"record":{"id":"175f25134a0918aa","repo":"microsoft/semantic-kernel","slug":"failed-to-handle-bedrock-agent-stream-event-resp","errorCode":null,"errorMessage":"Failed to handle Bedrock Agent stream event: {responseEvent}","messagePattern":"Failed to handle Bedrock Agent stream event: (.+?)","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/Bedrock/Extensions/BedrockAgentInvokeExtensions.cs","lineNumber":59,"sourceCode":"            if (invokeAgentResponse.HttpStatusCode != System.Net.HttpStatusCode.OK)\n            {\n                throw new HttpOperationException($\"Failed to invoke agent. Status code: {invokeAgentResponse.HttpStatusCode}\");\n            }\n\n            List<FunctionCallContent> functionCallContents = [];\n            foreach (var responseEvent in invokeAgentResponse.Completion)\n            {\n                if (responseEvent is BedrockAgentRuntimeEventStreamException bedrockAgentRuntimeEventStreamException)\n                {\n                    throw new KernelException(\"Failed to handle Bedrock Agent stream event.\", bedrockAgentRuntimeEventStreamException);\n                }\n\n                var chatMessageContent =\n                    HandleChunkEvent(agent, responseEvent) ??\n                    HandleFilesEvent(agent, responseEvent) ??\n                    HandleReturnControlEvent(agent, responseEvent, arguments) ??\n                    HandleTraceEvent(agent, responseEvent) ??\n                    throw new KernelException($\"Failed to handle Bedrock Agent stream event: {responseEvent}\");\n                if (chatMessageContent.Items.Count > 0 && chatMessageContent.Items[0] is FunctionCallContent functionCallContent)\n                {\n                    functionCallContents.AddRange(chatMessageContent.Items.Where(item => item is FunctionCallContent).Cast<FunctionCallContent>());\n                }\n                else\n                {\n                    yield return chatMessageContent;\n                }\n            }\n\n            // This is used to cap the auto function invocation loop to prevent infinite loops.\n            // It doesn't use the the `FunctionCallsProcessor` to process the functions because we do not need \n            // many of the features it offers and we want to keep the code simple.\n            var functionChoiceBehaviorConfiguration = new FunctionCallsProcessor().GetConfiguration(\n                FunctionChoiceBehavior.Auto(), [], requestIndex, agent.Kernel);\n\n            if (functionCallContents.Count > 0 && functionChoiceBehaviorConfiguration!.AutoInvoke)\n            {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/Bedrock/Extensions/BedrockAgentInvokeExtensions.cs#L41-L77","documentation":"Thrown when a response event from the InvokeAgentAsync stream is not recognized by any of the event handlers (HandleChunkEvent, HandleFilesEvent, HandleReturnControlEvent, HandleTraceEvent). This means the Bedrock runtime emitted an event type this version of the library does not yet support. The event's string representation is included in the message to aid diagnosis.","triggerScenarios":"AWS introduces a new Bedrock Agent stream event type (e.g., a new trace sub-type, a new artifact event, a new guardrail event) that the installed version of the Semantic Kernel Bedrock agent package cannot map. Triggered purely by receiving such an event during invocation.","commonSituations":"Using an older version of the Microsoft.SemanticKernel.Agents.Bedrock package after AWS added new event types; testing against a Bedrock preview feature that emits novel events; regional feature differences.","solutions":["Upgrade the Microsoft.SemanticKernel.Agents.Bedrock NuGet package to the latest version that supports the new event type.","Check the release notes / issue tracker for the specific event type reported in the message.","If upgrade is not possible, filter or disable the Bedrock feature producing the unsupported event (e.g., disable advanced tracing or guardrails) as a workaround.","Report the event type to the library maintainers if no version supports it yet."],"exampleFix":"// before — old package throws on new event\n// install-package Microsoft.SemanticKernel.Agents.Bedrock -Version 1.x.0\n\n// after — upgrade to a version that handles the event\n// dotnet add package Microsoft.SemanticKernel.Agents.Bedrock --version 1.x.1\n// then verify the event type string from the exception is covered in release notes","handlingStrategy":"validation","validationCode":"// Check installed package version supports the event types you expect\nvar version = typeof(BedrockAgent).Assembly.GetName().Version;\nlogger.LogInformation(\"SemanticKernel Bedrock agents version: {Version}\", version);\n// consult release notes for supported Bedrock event types at that version","typeGuard":null,"tryCatchPattern":"try { await foreach (var r in agent.InvokeAsync(request, thread, cancellationToken)) { ... } }\ncatch (KernelException ex) when (ex.Message.Contains(\"Failed to handle Bedrock Agent stream event\"))\n{\n    logger.LogError(\"Unhandled Bedrock event type. Upgrade Microsoft.SemanticKernel.Agents.Bedrock. Detail: {Msg}\", ex.Message);\n    throw;\n}","preventionTips":["Keep the Microsoft.SemanticKernel.Agents.Bedrock package up to date to track new Bedrock event types.","Watch release notes when AWS adds Bedrock agent features (guardrails, new trace types).","Pin the package version in CI and test against the Bedrock features you use."],"tags":["bedrock","agents","streaming","version-mismatch","event-handling","csharp"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}