Files
agent-framework/dotnet/samples/GettingStarted/Workflows/Agents/GroupChatToolApproval/DeploymentGroupChatManager.cs
T
Copilot c860385a8c Add C# GroupChat tool approval sample for multi-agent orchestrations (#3374)
* Initial plan

* Add C# GroupChat tool approval sample implementation

Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>

* Fix comment numbering for better code clarity

Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>

* Add GroupChatToolApproval project to solution

Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>

* Use Name property instead of Id for agent selection

Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>

* Fix file encoding - add UTF-8 BOM to C# files

Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>

* fix the sample

* Update dotnet/samples/GettingStarted/Workflows/Agents/GroupChatToolApproval/README.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* address PR review feedback

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
Co-authored-by: SergeyMenshykh <sergemenshikh@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-27 20:43:51 +00:00

48 lines
1.5 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Extensions.AI;
namespace WorkflowGroupChatToolApprovalSample;
/// <summary>
/// Custom GroupChatManager that selects the next speaker based on the conversation flow.
/// </summary>
/// <remarks>
/// This simple selector follows a predefined flow:
/// 1. QA Engineer runs tests
/// 2. DevOps Engineer checks staging and creates rollback plan
/// 3. DevOps Engineer deploys to production (triggers approval)
/// </remarks>
internal sealed class DeploymentGroupChatManager : GroupChatManager
{
private readonly IReadOnlyList<AIAgent> _agents;
public DeploymentGroupChatManager(IReadOnlyList<AIAgent> agents)
{
this._agents = agents;
}
protected override ValueTask<AIAgent> SelectNextAgentAsync(
IReadOnlyList<ChatMessage> history,
CancellationToken cancellationToken = default)
{
if (history.Count == 0)
{
throw new InvalidOperationException("Conversation is empty; cannot select next speaker.");
}
// First speaker after initial user message
if (this.IterationCount == 0)
{
AIAgent qaAgent = this._agents.First(a => a.Name == "QAEngineer");
return new ValueTask<AIAgent>(qaAgent);
}
// Subsequent speakers are DevOps Engineer
AIAgent devopsAgent = this._agents.First(a => a.Name == "DevOpsEngineer");
return new ValueTask<AIAgent>(devopsAgent);
}
}