microsoft/semantic-kernel · error · KernelException

Failed to handle Bedrock Agent stream event: {responseEvent}

Error message

Failed to handle Bedrock Agent stream event: {responseEvent}

What it means

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.

Source

Thrown at dotnet/src/Agents/Bedrock/Extensions/BedrockAgentInvokeExtensions.cs:59

            if (invokeAgentResponse.HttpStatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new HttpOperationException($"Failed to invoke agent. Status code: {invokeAgentResponse.HttpStatusCode}");
            }

            List<FunctionCallContent> functionCallContents = [];
            foreach (var responseEvent in invokeAgentResponse.Completion)
            {
                if (responseEvent is BedrockAgentRuntimeEventStreamException bedrockAgentRuntimeEventStreamException)
                {
                    throw new KernelException("Failed to handle Bedrock Agent stream event.", bedrockAgentRuntimeEventStreamException);
                }

                var chatMessageContent =
                    HandleChunkEvent(agent, responseEvent) ??
                    HandleFilesEvent(agent, responseEvent) ??
                    HandleReturnControlEvent(agent, responseEvent, arguments) ??
                    HandleTraceEvent(agent, responseEvent) ??
                    throw new KernelException($"Failed to handle Bedrock Agent stream event: {responseEvent}");
                if (chatMessageContent.Items.Count > 0 && chatMessageContent.Items[0] is FunctionCallContent functionCallContent)
                {
                    functionCallContents.AddRange(chatMessageContent.Items.Where(item => item is FunctionCallContent).Cast<FunctionCallContent>());
                }
                else
                {
                    yield return chatMessageContent;
                }
            }

            // This is used to cap the auto function invocation loop to prevent infinite loops.
            // It doesn't use the the `FunctionCallsProcessor` to process the functions because we do not need 
            // many of the features it offers and we want to keep the code simple.
            var functionChoiceBehaviorConfiguration = new FunctionCallsProcessor().GetConfiguration(
                FunctionChoiceBehavior.Auto(), [], requestIndex, agent.Kernel);

            if (functionCallContents.Count > 0 && functionChoiceBehaviorConfiguration!.AutoInvoke)
            {

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Upgrade the Microsoft.SemanticKernel.Agents.Bedrock NuGet package to the latest version that supports the new event type.
  2. Check the release notes / issue tracker for the specific event type reported in the message.
  3. 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.
  4. Report the event type to the library maintainers if no version supports it yet.

Example fix

// before — old package throws on new event
// install-package Microsoft.SemanticKernel.Agents.Bedrock -Version 1.x.0

// after — upgrade to a version that handles the event
// dotnet add package Microsoft.SemanticKernel.Agents.Bedrock --version 1.x.1
// then verify the event type string from the exception is covered in release notes
Defensive patterns

Strategy: validation

Validate before calling

// Check installed package version supports the event types you expect
var version = typeof(BedrockAgent).Assembly.GetName().Version;
logger.LogInformation("SemanticKernel Bedrock agents version: {Version}", version);
// consult release notes for supported Bedrock event types at that version

Try / catch

try { await foreach (var r in agent.InvokeAsync(request, thread, cancellationToken)) { ... } }
catch (KernelException ex) when (ex.Message.Contains("Failed to handle Bedrock Agent stream event"))
{
    logger.LogError("Unhandled Bedrock event type. Upgrade Microsoft.SemanticKernel.Agents.Bedrock. Detail: {Msg}", ex.Message);
    throw;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/175f25134a0918aa. Report an issue: GitHub.