diff --git a/dotnet/samples/03-workflows/_StartHere/03_AgentWorkflowPatterns/Program.cs b/dotnet/samples/03-workflows/_StartHere/03_AgentWorkflowPatterns/Program.cs index ae8208e964..a562226740 100644 --- a/dotnet/samples/03-workflows/_StartHere/03_AgentWorkflowPatterns/Program.cs +++ b/dotnet/samples/03-workflows/_StartHere/03_AgentWorkflowPatterns/Program.cs @@ -72,6 +72,8 @@ await RunWorkflowAsync( await RunWorkflowAsync( AgentWorkflowBuilder.CreateGroupChatBuilderWith(agents => new RoundRobinGroupChatManager(agents) { MaximumIterationCount = 5 }) .AddParticipants(from lang in (string[])["French", "Spanish", "English"] select GetTranslationAgent(lang, client)) + .WithName("Translation Round Robin Workflow") + .WithDescription("A workflow where three translation agents take turns responding in a round-robin fashion.") .Build(), [new(ChatRole.User, "Hello, world!")]); break; diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/GroupChatWorkflowBuilder.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/GroupChatWorkflowBuilder.cs index 79a7b35498..66e4429e35 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/GroupChatWorkflowBuilder.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/GroupChatWorkflowBuilder.cs @@ -16,6 +16,8 @@ public sealed class GroupChatWorkflowBuilder { private readonly Func, GroupChatManager> _managerFactory; private readonly HashSet _participants = new(AIAgentIDEqualityComparer.Instance); + private string _name = string.Empty; + private string _description = string.Empty; internal GroupChatWorkflowBuilder(Func, GroupChatManager> managerFactory) => this._managerFactory = managerFactory; @@ -42,6 +44,28 @@ public GroupChatWorkflowBuilder AddParticipants(params IEnumerable agen return this; } + /// + /// Sets the human-readable name for the workflow. + /// + /// The name of the workflow. + /// This instance of the . + public GroupChatWorkflowBuilder WithName(string name) + { + this._name = name; + return this; + } + + /// + /// Sets the description for the workflow. + /// + /// The description of what the workflow does. + /// This instance of the . + public GroupChatWorkflowBuilder WithDescription(string description) + { + this._description = description; + return this; + } + /// /// Builds a composed of agents that operate via group chat, with the next /// agent to process messages selected by the group chat manager. @@ -65,6 +89,16 @@ public Workflow Build() ExecutorBinding host = groupChatHostFactory.BindExecutor(nameof(GroupChatHost)); WorkflowBuilder builder = new(host); + if (!string.IsNullOrEmpty(this._name)) + { + builder = builder.WithName(this._name); + } + + if (!string.IsNullOrEmpty(this._description)) + { + builder = builder.WithDescription(this._description); + } + foreach (var participant in agentMap.Values) { builder diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AgentWorkflowBuilderTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AgentWorkflowBuilderTests.cs index 01ce7c3441..77d8d0a88d 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AgentWorkflowBuilderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AgentWorkflowBuilderTests.cs @@ -88,6 +88,50 @@ public void GroupChatManager_MaximumIterationCount_Invalid_Throws() Assert.Equal(int.MaxValue, manager.MaximumIterationCount); } + [Fact] + public void BuildGroupChat_WithNameAndDescription_SetsWorkflowNameAndDescription() + { + const string WorkflowName = "Test Group Chat"; + const string WorkflowDescription = "A test group chat workflow"; + + var workflow = AgentWorkflowBuilder + .CreateGroupChatBuilderWith(agents => new RoundRobinGroupChatManager(agents) { MaximumIterationCount = 2 }) + .AddParticipants(new DoubleEchoAgent("agent1"), new DoubleEchoAgent("agent2")) + .WithName(WorkflowName) + .WithDescription(WorkflowDescription) + .Build(); + + Assert.Equal(WorkflowName, workflow.Name); + Assert.Equal(WorkflowDescription, workflow.Description); + } + + [Fact] + public void BuildGroupChat_WithNameOnly_SetsWorkflowName() + { + const string WorkflowName = "Named Group Chat"; + + var workflow = AgentWorkflowBuilder + .CreateGroupChatBuilderWith(agents => new RoundRobinGroupChatManager(agents) { MaximumIterationCount = 2 }) + .AddParticipants(new DoubleEchoAgent("agent1")) + .WithName(WorkflowName) + .Build(); + + Assert.Equal(WorkflowName, workflow.Name); + Assert.Null(workflow.Description); + } + + [Fact] + public void BuildGroupChat_WithoutNameOrDescription_DefaultsToNull() + { + var workflow = AgentWorkflowBuilder + .CreateGroupChatBuilderWith(agents => new RoundRobinGroupChatManager(agents) { MaximumIterationCount = 2 }) + .AddParticipants(new DoubleEchoAgent("agent1")) + .Build(); + + Assert.Null(workflow.Name); + Assert.Null(workflow.Description); + } + [Theory] [InlineData(1)] [InlineData(2)]