-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathDeploymentGroupChatManager.cs
More file actions
47 lines (40 loc) · 1.52 KB
/
DeploymentGroupChatManager.cs
File metadata and controls
47 lines (40 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 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);
}
}