{"record":{"id":"76653b4690200ef0","repo":"microsoft/semantic-kernel","slug":"nameof-a2aagent-is-not-for-use-with-nameof-age","errorCode":null,"errorMessage":"{nameof(A2AAgent)} is not for use with {nameof(AgentChat)}.","messagePattern":"(.+?) is not for use with (.+?)\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/A2A/A2AAgent.cs","lineNumber":113,"sourceCode":"            yield return new(result, agentThread);\n        }\n\n        // Notify the thread of any new messages that were assembled from the streaming response.\n        foreach (var chatMessage in chatMessages)\n        {\n            await this.NotifyThreadOfNewMessage(agentThread, chatMessage, cancellationToken).ConfigureAwait(false);\n\n            if (options?.OnIntermediateMessage is not null)\n            {\n                await options.OnIntermediateMessage(chatMessage).ConfigureAwait(false);\n            }\n        }\n    }\n\n    /// <inheritdoc/>\n    protected override Task<AgentChannel> CreateChannelAsync(CancellationToken cancellationToken)\n    {\n        throw new NotSupportedException($\"{nameof(A2AAgent)} is not for use with {nameof(AgentChat)}.\");\n    }\n\n    /// <inheritdoc/>\n    protected override IEnumerable<string> GetChannelKeys()\n    {\n        throw new NotSupportedException($\"{nameof(A2AAgent)} is not for use with {nameof(AgentChat)}.\");\n    }\n\n    /// <inheritdoc/>\n    protected override Task<AgentChannel> RestoreChannelAsync(string channelState, CancellationToken cancellationToken)\n    {\n        throw new NotSupportedException($\"{nameof(A2AAgent)} is not for use with {nameof(AgentChat)}.\");\n    }\n\n    #region private\n    private async IAsyncEnumerable<AgentResponseItem<ChatMessageContent>> InternalInvokeAsync(string name, ICollection<ChatMessageContent> messages, A2AAgentThread thread, AgentInvokeOptions options, [EnumeratorCancellation] CancellationToken cancellationToken)\n    {\n        Verify.NotNull(messages);","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/A2A/A2AAgent.cs#L95-L131","documentation":"A NotSupportedException thrown by A2AAgent.CreateChannelAsync, an Agent base-class override used by the AgentChat multi-agent orchestration channel system. A2AAgent is built on the A2A protocol (remote agent invocation) and does not implement the AgentChannel contract that AgentChat relies on, so any attempt to obtain a channel is explicitly rejected.","triggerScenarios":"Adding an A2AAgent to an AgentChat (e.g. AgentGroupChat) and invoking the chat, which triggers channel creation via CreateChannelAsync.","commonSituations":"Mixing A2A protocol agents with the channel-based AgentChat orchestration; copy-pasting an AgentGroupChat setup that worked for ChatCompletionAgent/OpenAIAssistantAgent and substituting an A2AAgent.","solutions":["Do not use A2AAgent with AgentChat/AgentGroupChat; invoke it directly via InvokeAsync/InvokeStreamingAsync.","Use a ChatCompletionAgent or other channel-capable agent for AgentChat scenarios.","If multi-agent orchestration is needed, drive each A2AAgent via its own InvokeAsync and assemble results manually."],"exampleFix":"// before - throws NotSupportedException\nvar chat = new AgentGroupChat(kernel) { ExecutionSettings = ... };\nchat.AddAgent(a2aAgent);\nawait chat.InvokeAsync();\n// after - invoke A2A agent directly\nawait foreach (var item in a2aAgent.InvokeAsync(messages, thread))\n    Console.WriteLine(item.Message.Content);","handlingStrategy":"type-guard","validationCode":"if (agent is A2AAgent) throw new InvalidOperationException(\"A2AAgent cannot be used with AgentChat; invoke it directly.\");\nchat.AddAgent(agent);","typeGuard":"static bool IsChatCompatible(Agent a) => a is not A2AAgent;","tryCatchPattern":"try { chat.AddAgent(agent); await chat.InvokeAsync(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"A2AAgent\")) { /* remove A2AAgent, invoke it directly */ }","preventionTips":["Never add an A2AAgent to AgentChat/AgentGroupChat.","Filter participant lists to exclude A2AAgent before constructing chats.","Invoke A2A agents directly via InvokeAsync/InvokeStreamingAsync."],"tags":["agents","a2a","agent-chat","not-supported","orchestration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}