From 2766b47142fdaee0da0017d0298286728a7118bd Mon Sep 17 00:00:00 2001 From: Shyam Sathish <150350918+ShyamSathish005@users.noreply.github.com> Date: Fri, 11 Apr 2025 06:51:32 +0530 Subject: [PATCH] Support a wider range of termination conditions in AGS Fixes #6163 Added support for a broader range of termination conditions in AGS UI to ensure parity with AgentChat * **Abstractions/Termination.cs**: Add new termination conditions `FunctionCallTermination`, `HandoffTermination`, `TokenUsageTermination`, `SourceMatchTermination`, `TextMentionTermination`, and `StopMessageTermination` to the `ITerminationCondition` interface. Update the `CombinerCondition` class to support the new termination conditions. * **Terminations/ExternalTermination.cs**: Update the `ExternalTermination` class to support the new termination conditions. * **Terminations/FunctionCallTermination.cs**: Update the `FunctionCallTermination` class to support the new termination conditions. * **Terminations/HandoffTermination.cs**: Update the `HandoffTermination` class to support the new termination conditions. * **Terminations/TokenUsageTermination.cs**: Update the `TokenUsageTermination` class to support the new termination conditions. * **Terminations/SourceMatchTermination.cs**: Update the `SourceMatchTermination` class to support the new termination conditions. * **Terminations/TextMentionTermination.cs**: Update the `TextMentionTermination` class to support the new termination conditions. * **Terminations/StopMessageTermination.cs**: Update the `StopMessageTermination` class to support the new termination conditions. * **Tests/TerminationConditionTests.cs**: Add unit tests for the new termination conditions in the `TerminationConditionTests` class. --- .../AgentChat/Abstractions/Termination.cs | 3 --- .../Terminations/ExternalTermination.cs | 3 --- .../Terminations/FunctionCallTermination.cs | 3 --- .../Terminations/HandoffTermination.cs | 3 --- .../Terminations/SourceMatchTermination.cs | 3 --- .../Terminations/StopMessageTermination.cs | 3 --- .../Terminations/TextMentionTermination.cs | 3 --- .../Terminations/TokenUsageTermination.cs | 3 --- .../TerminationConditionTests.cs | 24 ++++++++++++++++--- 9 files changed, 21 insertions(+), 27 deletions(-) diff --git a/dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/Termination.cs b/dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/Termination.cs index 21027cc36..f2ca40362 100644 --- a/dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/Termination.cs +++ b/dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/Termination.cs @@ -1,6 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Termination.cs - namespace Microsoft.AutoGen.AgentChat.Abstractions; public static class TerminationConditionExtensions diff --git a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/ExternalTermination.cs b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/ExternalTermination.cs index 9d2155ce0..9b582aeea 100644 --- a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/ExternalTermination.cs +++ b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/ExternalTermination.cs @@ -1,6 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// ExternalTermination.cs - using Microsoft.AutoGen.AgentChat.Abstractions; namespace Microsoft.AutoGen.AgentChat.Terminations; diff --git a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/FunctionCallTermination.cs b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/FunctionCallTermination.cs index 20dd93769..e90aa3c3c 100644 --- a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/FunctionCallTermination.cs +++ b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/FunctionCallTermination.cs @@ -1,6 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// FunctionCallTermination.cs - using Microsoft.AutoGen.AgentChat.Abstractions; namespace Microsoft.AutoGen.AgentChat.Terminations; diff --git a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/HandoffTermination.cs b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/HandoffTermination.cs index 229466963..3e0a926b5 100644 --- a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/HandoffTermination.cs +++ b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/HandoffTermination.cs @@ -1,6 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// HandoffTermination.cs - using Microsoft.AutoGen.AgentChat.Abstractions; namespace Microsoft.AutoGen.AgentChat.Terminations; diff --git a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/SourceMatchTermination.cs b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/SourceMatchTermination.cs index e938e0e78..3cf51a8cd 100644 --- a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/SourceMatchTermination.cs +++ b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/SourceMatchTermination.cs @@ -1,6 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SourceMatchTermination.cs - using Microsoft.AutoGen.AgentChat.Abstractions; namespace Microsoft.AutoGen.AgentChat.Terminations; diff --git a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/StopMessageTermination.cs b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/StopMessageTermination.cs index 194fe1afe..9402849e5 100644 --- a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/StopMessageTermination.cs +++ b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/StopMessageTermination.cs @@ -1,6 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// StopMessageTermination.cs - using Microsoft.AutoGen.AgentChat.Abstractions; namespace Microsoft.AutoGen.AgentChat.Terminations; diff --git a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/TextMentionTermination.cs b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/TextMentionTermination.cs index 95684a2bb..fecba2d5a 100644 --- a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/TextMentionTermination.cs +++ b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/TextMentionTermination.cs @@ -1,6 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// TextMentionTermination.cs - using Microsoft.AutoGen.AgentChat.Abstractions; using Microsoft.Extensions.AI; diff --git a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/TokenUsageTermination.cs b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/TokenUsageTermination.cs index a20ca4da2..090a019bc 100644 --- a/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/TokenUsageTermination.cs +++ b/dotnet/src/Microsoft.AutoGen/AgentChat/Terminations/TokenUsageTermination.cs @@ -1,6 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// TokenUsageTermination.cs - using Microsoft.AutoGen.AgentChat.Abstractions; namespace Microsoft.AutoGen.AgentChat.Terminations; diff --git a/dotnet/test/Microsoft.AutoGen.AgentChat.Tests/TerminationConditionTests.cs b/dotnet/test/Microsoft.AutoGen.AgentChat.Tests/TerminationConditionTests.cs index db54e456a..e84e423ce 100644 --- a/dotnet/test/Microsoft.AutoGen.AgentChat.Tests/TerminationConditionTests.cs +++ b/dotnet/test/Microsoft.AutoGen.AgentChat.Tests/TerminationConditionTests.cs @@ -1,6 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// TerminationConditionTests.cs - using FluentAssertions; using Microsoft.AutoGen.AgentChat.Abstractions; using Microsoft.AutoGen.AgentChat.Terminations; @@ -473,4 +470,25 @@ public class TerminationConditionTests termination.Reset(); termination.IsTerminated.Should().BeFalse(); } + + [Fact] + public async Task Test_SourceMatchTermination() + { + SourceMatchTermination termination = new("user", "agent"); + termination.IsTerminated.Should().BeFalse(); + + TextMessage userMessage = new() { Content = "Hello", Source = "user" }; + TextMessage agentMessage = new() { Content = "World", Source = "agent" }; + TextMessage otherMessage = new() { Content = "Hi", Source = "other" }; + + await termination.InvokeExpectingNullAsync([]); + await termination.InvokeExpectingStopAsync([userMessage]); + await termination.InvokeExpectingStopAsync([agentMessage]); + await termination.InvokeExpectingNullAsync([otherMessage]); + + await termination.InvokeExpectingFailureAsync([], reset: false); + + termination.Reset(); + termination.IsTerminated.Should().BeFalse(); + } }