microsoft/semantic-kernel · error · AgentThreadOperationException

The thread could not be created due to an error response fro

Error message

The thread could not be created due to an error response from the service.

What it means

Thrown during thread creation when CreateSessionAsync on the Bedrock Agent runtime returns an AmazonBedrockAgentRuntimeException. This is a wrapper (AgentThreadOperationException) that preserves the original AWS exception as its InnerException, giving callers a single exception type to catch for thread lifecycle failures while retaining diagnostic detail.

Source

Thrown at dotnet/src/Agents/Bedrock/BedrockAgentThread.cs:53

        return base.CreateAsync(cancellationToken);
    }

    /// <inheritdoc />
    protected override async Task<string?> CreateInternalAsync(CancellationToken cancellationToken)
    {
        const string ErrorMessage = "The thread could not be created due to an error response from the service.";

        try
        {
            var response = await this._runtimeClient.CreateSessionAsync(
                request: new(),
                cancellationToken: cancellationToken).ConfigureAwait(false);

            return response.SessionId;
        }
        catch (AmazonBedrockAgentRuntimeException ex)
        {
            throw new AgentThreadOperationException(ErrorMessage, ex);
        }
        catch (AggregateException ex)
        {
            throw new AgentThreadOperationException(ErrorMessage, ex);
        }
    }

    /// <inheritdoc />
    protected override async Task DeleteInternalAsync(CancellationToken cancellationToken)
    {
        const string ErrorMessage = "The thread could not be deleted due to an error response from the service.";

        try
        {
            var endSessionResponse = await this._runtimeClient.EndSessionAsync(
                request: new()
                {
                    SessionIdentifier = this.Id

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Inspect the InnerException (AmazonBedrockAgentRuntimeException) for the AWS ErrorCode and message to identify auth, permission, or throttling causes.
  2. Verify the IAM principal has `bedrock-agent-runtime:CreateSession` permission and that credentials are valid and non-expired.
  3. Confirm the IAmazonBedrockAgentRuntime client is configured with the correct region where the agent exists.
  4. Implement retry with exponential backoff for transient throttling/errors (the SDK's built-in retry may already apply; raise MaxRetries if needed).

Example fix

// before
try { await thread.CreateAsync(cancellationToken); }
catch (Exception ex) { /* too broad, loses structure */ }

// after
try { await thread.CreateAsync(cancellationToken); }
catch (AgentThreadOperationException ex) when (ex.InnerException is AmazonBedrockAgentRuntimeException aws)
{
    logger.LogError(aws, "Session create failed: {ErrorCode}", aws.ErrorCode);
    throw;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify credentials and permissions before thread creation
var sts = new AmazonSecurityTokenServiceClient();
var identity = await sts.GetCallerIdentityAsync(new GetCallerIdentityRequest());
logger.LogInformation("Using AWS identity: {Arn}", identity.Arn);
// then proceed to create the thread

Try / catch

try { await thread.CreateAsync(cancellationToken); }
catch (AgentThreadOperationException ex) when (ex.InnerException is AmazonBedrockAgentRuntimeException aws)
{
    logger.LogError(aws, "CreateSession failed: {Code} {Message}", aws.ErrorCode, aws.Message);
    // branch on ErrorCode: AccessDenied -> fix IAM; Throttling -> retry; etc.
}

Prevention

When it happens

Trigger: Calling CreateAsync on a BedrockAgentThread when the AWS Bedrock Agent Runtime service rejects the CreateSession call — invalid or expired AWS credentials, missing IAM permissions for `bedrock:CreateSession`, service throttling, or a regional outage.

Common situations: Credentials from a stale profile; the IAM role/policy lacks `bedrock-agent-runtime:CreateSession`; hitting a service quota; wrong region endpoint configured on the client.

Related errors


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