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 by AzureAIAgentThread.CreateInternalAsync when the Azure AI Agents service returns a RequestFailedException during thread creation (CreateThreadAsync). The original Azure SDK exception is wrapped in an AgentThreadOperationException (which inherits from KernelException) with a standard message. The inner exception contains the HTTP status code, error details, and request ID from the service.

Source

Thrown at dotnet/src/Agents/AzureAI/AzureAIAgentThread.cs:90

    }

    /// <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 agentThreadResponse = await this._client.Threads.CreateThreadAsync(
                this._messages,
                this._toolResources,
                this._metadata,
                cancellationToken: cancellationToken).ConfigureAwait(false);
            return agentThreadResponse.Value.Id;
        }
        catch (RequestFailedException 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
        {
            await this._client.Threads.DeleteThreadAsync(this.Id, cancellationToken).ConfigureAwait(false);
        }
        catch (RequestFailedException ex) when (ex.Status == 404)
        {

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Inspect ex.InnerException (the RequestFailedException) for the HTTP status code and service error message.
  2. Verify the PersistentAgentsClient is configured with a valid endpoint and credentials.
  3. For 429 (rate limit), implement exponential backoff retry around CreateAsync.
  4. For 401/403, refresh credentials or check API key/Azure AD token validity.
  5. Validate that ToolResources and messages passed to the thread constructor are well-formed.
Defensive patterns

Strategy: retry

Try / catch

try
{
    await thread.CreateAsync(ct);
}
catch (AgentThreadOperationException ex) when (ex.InnerException is RequestFailedException rfe)
{
    _logger.LogError("Thread creation failed: {Status} {Error}", rfe.Status, rfe.Message);
    if (rfe.Status == 429) { /* retry with backoff */ }
    else throw;
}

Prevention

When it happens

Trigger: CreateThreadAsync on the PersistentAgentsClient fails with a RequestFailedException — causes include authentication failures (401/403), invalid endpoint configuration, quota/rate-limit exceeded (429), service errors (5xx), or malformed tool resources. The catch block for RequestFailedException fires for all non-404 service errors during thread creation.

Common situations: Expired or invalid API keys / Azure AD tokens. Wrong Azure AI endpoint. Exceeded thread creation quotas. Network connectivity issues to Azure. Malformed ToolResources or ThreadMessageOptions passed to the AzureAIAgentThread constructor. Azure service transient outages.

Related errors


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