microsoft/semantic-kernel · error · AgentThreadOperationException
The message could not be added to the thread due to an error
Error message
The message could not be added to the thread due to an error response from the service.
What it means
Thrown by AzureAIChannel.ReceiveAsync when AgentThreadActions.CreateMessageAsync fails with a RequestFailedException during multi-agent channel synchronization. AzureAIChannel.ReceiveAsync iterates over the chat history and posts each message to the Azure AI thread. This error surfaces when the service rejects one of those message-creation calls.
Source
Thrown at dotnet/src/Agents/AzureAI/AzureAIChannel.cs:33
/// A <see cref="AgentChannel"/> specialization for use with <see cref="AzureAIAgent"/>.
/// </summary>
internal sealed class AzureAIChannel(PersistentAgentsClient client, string threadId)
: AgentChannel<AzureAIAgent>
{
/// <inheritdoc/>
protected override async Task ReceiveAsync(IEnumerable<ChatMessageContent> history, CancellationToken cancellationToken)
{
const string ErrorMessage = "The message could not be added to the thread due to an error response from the service.";
foreach (ChatMessageContent message in history)
{
try
{
await AgentThreadActions.CreateMessageAsync(client, threadId, message, cancellationToken).ConfigureAwait(false);
}
catch (RequestFailedException ex)
{
throw new AgentThreadOperationException(ErrorMessage, ex);
}
catch (AggregateException ex)
{
throw new AgentThreadOperationException(ErrorMessage, ex);
}
}
}
/// <inheritdoc/>
protected override IAsyncEnumerable<(bool IsVisible, ChatMessageContent Message)> InvokeAsync(
AzureAIAgent agent,
CancellationToken cancellationToken)
{
return ActivityExtensions.RunWithActivityAsync(
() => ModelDiagnostics.StartAgentInvocationActivity(agent.Id, agent.GetDisplayName(), agent.Description, agent.Kernel, []),
() => AgentThreadActions.InvokeAsync(agent, client, threadId, invocationOptions: null, this.Logger, agent.Kernel, agent.Arguments, cancellationToken),
cancellationToken);
}View on GitHub (pinned to c028a0c7dc)
Solutions
- Inspect the InnerException (RequestFailedException) for status code and service error.
- Refresh credentials if 401/403.
- Implement retry/backoff around the AgentChat invocation for 429 responses.
- Ensure all agents share valid, non-deleted threads.
- Reduce message frequency if rate-limited.
Defensive patterns
Strategy: try-catch
Try / catch
try
{
await chat.InvokeAsync(ct);
}
catch (AgentThreadOperationException ex) when (ex.InnerException is RequestFailedException rfe)
{
_logger.LogError("Channel message broadcast failed: {Status}", rfe.Status);
throw;
} Prevention
- Monitor Azure AI service health during multi-agent scenarios.
- Ensure credentials are fresh for all agents sharing the chat.
- Implement retry around the entire chat invocation for transient failures.
When it happens
Trigger: During AgentChat multi-agent broadcasting, the AzureAIChannel receives history messages from other agents and tries to persist each to the Azure AI thread. If any CreateMessageAsync call fails with a RequestFailedException (non-transient or un-retried), it is wrapped as AgentThreadOperationException.
Common situations: Multi-agent AgentChat where one agent produces a message that fails to persist to another agent's Azure AI thread. Auth token expired mid-conversation. Rate limiting during high-frequency inter-agent messaging. Message format incompatibility. Thread deleted externally.
Related errors
- The thread could not be created due to an error response fro
- The thread could not be deleted due to an error response fro
- The message could not be added to the thread due to an error
- The thread could not be created due to an error response fro
- The thread could not be deleted due to an error response fro
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/20b1e9327594330e.
Report an issue: GitHub.