{"record":{"id":"20b1e9327594330e","repo":"microsoft/semantic-kernel","slug":"the-message-could-not-be-added-to-the-thread-due-t-20b1e9","errorCode":null,"errorMessage":"The message could not be added to the thread due to an error response from the service.","messagePattern":"The message could not be added to the thread due to an error response from the service\\.","errorType":"exception","errorClass":"AgentThreadOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/AzureAI/AzureAIChannel.cs","lineNumber":33,"sourceCode":"/// A <see cref=\"AgentChannel\"/> specialization for use with <see cref=\"AzureAIAgent\"/>.\n/// </summary>\ninternal sealed class AzureAIChannel(PersistentAgentsClient client, string threadId)\n    : AgentChannel<AzureAIAgent>\n{\n    /// <inheritdoc/>\n    protected override async Task ReceiveAsync(IEnumerable<ChatMessageContent> history, CancellationToken cancellationToken)\n    {\n        const string ErrorMessage = \"The message could not be added to the thread due to an error response from the service.\";\n\n        foreach (ChatMessageContent message in history)\n        {\n            try\n            {\n                await AgentThreadActions.CreateMessageAsync(client, threadId, message, cancellationToken).ConfigureAwait(false);\n            }\n            catch (RequestFailedException ex)\n            {\n                throw new AgentThreadOperationException(ErrorMessage, ex);\n            }\n            catch (AggregateException ex)\n            {\n                throw new AgentThreadOperationException(ErrorMessage, ex);\n            }\n        }\n    }\n\n    /// <inheritdoc/>\n    protected override IAsyncEnumerable<(bool IsVisible, ChatMessageContent Message)> InvokeAsync(\n        AzureAIAgent agent,\n        CancellationToken cancellationToken)\n    {\n        return ActivityExtensions.RunWithActivityAsync(\n            () => ModelDiagnostics.StartAgentInvocationActivity(agent.Id, agent.GetDisplayName(), agent.Description, agent.Kernel, []),\n            () => AgentThreadActions.InvokeAsync(agent, client, threadId, invocationOptions: null, this.Logger, agent.Kernel, agent.Arguments, cancellationToken),\n            cancellationToken);\n    }","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/AzureAI/AzureAIChannel.cs#L15-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    await chat.InvokeAsync(ct);\n}\ncatch (AgentThreadOperationException ex) when (ex.InnerException is RequestFailedException rfe)\n{\n    _logger.LogError(\"Channel message broadcast failed: {Status}\", rfe.Status);\n    throw;\n}","preventionTips":["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."],"tags":["azureai-channel","multi-agent","network","service-error","agentthreadoperationexception"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}