{"record":{"id":"e15f68262b456cc2","repo":"microsoft/semantic-kernel","slug":"nameof-copilotstudioagent-is-not-for-use-with","errorCode":null,"errorMessage":"{nameof(CopilotStudioAgent)} is not for use with {nameof(AgentChat)}.","messagePattern":"(.+?) is not for use with (.+?)\\.","errorType":"validation","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/Copilot/CopilotStudioAgent.cs","lineNumber":127,"sourceCode":"            {\n                await options.OnIntermediateMessage(result).ConfigureAwait(false);\n            }\n\n            StreamingChatMessageContent streamedResult = new(result.Role, content: null)\n            {\n                Items = [.. ContentProcessor.ConvertToStreaming(result.Items, this.Logger)],\n                InnerContent = result.InnerContent,\n                Metadata = result.Metadata,\n            };\n\n            yield return new(streamedResult, agentThread);\n        }\n    }\n\n    /// <inheritdoc/>\n    protected override IEnumerable<string> GetChannelKeys()\n    {\n        throw new NotSupportedException($\"{nameof(CopilotStudioAgent)} is not for use with {nameof(AgentChat)}.\");\n    }\n\n    /// <inheritdoc/>\n    protected override Task<AgentChannel> CreateChannelAsync(CancellationToken cancellationToken)\n    {\n        throw new NotSupportedException($\"{nameof(CopilotStudioAgent)} 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(CopilotStudioAgent)} is not for use with {nameof(AgentChat)}.\");\n    }\n\n    private IAsyncEnumerable<ChatMessageContent> InvokeInternalAsync(ICollection<ChatMessageContent> messages, CopilotStudioAgentThread thread, CancellationToken cancellationToken)\n    {\n        string question = string.Join(Environment.NewLine, messages.Select(m => m.Content));\n","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/Copilot/CopilotStudioAgent.cs#L109-L145","documentation":"Thrown by CopilotStudioAgent.GetChannelKeys() to signal that CopilotStudioAgent does not participate in the multi-agent AgentChat channel coordination system. The Copilot Studio integration is designed for direct single-agent invocation only; it overrides the channel-related abstract members to throw NotSupportedException to make the limitation explicit at the point AgentChat would try to use them.","triggerScenarios":"Adding a CopilotStudioAgent to an AgentChat (multi-agent chat) instance, which internally calls GetChannelKeys() to coordinate channels across agents. Because Copilot Studio uses its own conversation/session model, it cannot be wired into the shared channel abstraction.","commonSituations":"Migrating from a single-agent OpenAI/Bedrock setup to a multi-agent AgentChat and including a Copilot Studio agent; following a multi-agent sample and substituting CopilotStudioAgent.","solutions":["Do not use CopilotStudioAgent with AgentChat. Invoke it directly via InvokeAsync/InvokeStreamingAsync with a CopilotStudioAgentThread.","If multi-agent orchestration is needed, host the Copilot Studio agent behind a custom adapter that is not registered with AgentChat.","Use a different agent type that supports the AgentChat channel model for multi-agent scenarios."],"exampleFix":"// before — not supported\nvar chat = new AgentChat { };\nchat.AddAgent(copilotAgent); // triggers GetChannelKeys -> NotSupportedException\n\n// after — invoke directly\nvar thread = new CopilotStudioAgentThread(client);\nawait foreach (var r in copilotAgent.InvokeAsync(messages, thread)) { ... }","handlingStrategy":"validation","validationCode":"// Do not register CopilotStudioAgent with AgentChat\nif (agent is CopilotStudioAgent)\n    throw new InvalidOperationException(\"CopilotStudioAgent cannot be used with AgentChat. Invoke directly.\");","typeGuard":"static bool SupportsAgentChat(Microsoft.SemanticKernel.Agents.Agent a) =>\n    a is not CopilotStudioAgent;","tryCatchPattern":"try { chat.AddAgent(agent); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"AgentChat\"))\n{\n    logger.LogError(\"CopilotStudioAgent does not support AgentChat. Use direct InvokeAsync instead.\");\n    throw;\n}","preventionTips":["Keep CopilotStudioAgent out of any AgentChat configuration.","Invoke CopilotStudioAgent directly with a CopilotStudioAgentThread.","Document in your codebase that Copilot Studio agents are single-agent, direct-invoke only."],"tags":["copilot","agents","agent-chat","not-supported","csharp"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}