From d593e0c455cdcc519bb389c9a3138d9deca0f34c Mon Sep 17 00:00:00 2001 From: XiaoYun Zhang Date: Tue, 6 Aug 2024 12:32:14 -0700 Subject: [PATCH 1/2] break conversation when orchestartor return null --- .../Extension/GroupChatExtension.cs | 7 ++++++ .../AutoGen.Tests/GroupChat/GroupChatTests.cs | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/dotnet/src/AutoGen.Core/Extension/GroupChatExtension.cs b/dotnet/src/AutoGen.Core/Extension/GroupChatExtension.cs index 6b17a2b93fd6..89da7708797c 100644 --- a/dotnet/src/AutoGen.Core/Extension/GroupChatExtension.cs +++ b/dotnet/src/AutoGen.Core/Extension/GroupChatExtension.cs @@ -43,6 +43,13 @@ public static async IAsyncEnumerable SendAsync( while (maxRound-- > 0) { var messages = await groupChat.CallAsync(chatHistory, maxRound: 1, cancellationToken); + + // if no new messages, break the loop + if (messages.Count() == chatHistory.Count()) + { + yield break; + } + var lastMessage = messages.Last(); yield return lastMessage; diff --git a/dotnet/test/AutoGen.Tests/GroupChat/GroupChatTests.cs b/dotnet/test/AutoGen.Tests/GroupChat/GroupChatTests.cs index 19ca02ae92fa..9c2d2ce8197a 100644 --- a/dotnet/test/AutoGen.Tests/GroupChat/GroupChatTests.cs +++ b/dotnet/test/AutoGen.Tests/GroupChat/GroupChatTests.cs @@ -85,4 +85,29 @@ public async Task ItSendAsyncDoesntAddDuplicateInitializeMessagesTest() chatHistory.Count().Should().Be(2); } + + [Fact] + public async Task ItTerminateConversationWhenNoSpeakerAvailable() + { + // fix #3306 + var alice = new DefaultReplyAgent("Alice", "I am alice"); + var bob = new DefaultReplyAgent("Bob", "I am bob"); + var cathy = new DefaultReplyAgent("Cathy", $"I am cathy, {GroupChatExtension.TERMINATE}"); + + var orchestrator = Mock.Of(); + Mock.Get(orchestrator).Setup(x => x.GetNextSpeakerAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync((IAgent?)null); + + var groupChat = new GroupChat([alice, bob, cathy], orchestrator); + + var chatHistory = new List(); + + var maxRound = 10; + await foreach (var message in groupChat.SendAsync(chatHistory, maxRound)) + { + chatHistory.Add(message); + } + + chatHistory.Count().Should().Be(0); + } } From 97b713e37ca7a5c79a4c60b4ddd479a0ef0ec4df Mon Sep 17 00:00:00 2001 From: XiaoYun Zhang Date: Tue, 6 Aug 2024 12:37:51 -0700 Subject: [PATCH 2/2] enable test on different OS --- .github/workflows/dotnet-build.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet-build.yml b/.github/workflows/dotnet-build.yml index 7e50025917de..6b7056cce6dc 100644 --- a/.github/workflows/dotnet-build.yml +++ b/.github/workflows/dotnet-build.yml @@ -43,12 +43,16 @@ jobs: if: steps.filter.outputs.workflows == 'true' build: name: Dotnet Build - runs-on: ubuntu-latest needs: paths-filter if: needs.paths-filter.outputs.hasChanges == 'true' defaults: run: working-directory: dotnet + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 with: @@ -92,7 +96,7 @@ jobs: - name: Setup dotnet uses: actions/setup-dotnet@v4 with: - global-json-file: dotnet/global.json + dotnet-version: '8.0.x' - name: publish AOT testApp, assert static analysis warning count, and run the app shell: pwsh @@ -181,12 +185,14 @@ jobs: env: AZURE_ARTIFACTS_FEED_URL: https://devdiv.pkgs.visualstudio.com/DevDiv/_packaging/AutoGen/nuget/v3/index.json NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_TOKEN }} + continue-on-error: true - name: Publish nightly package to github package run: | echo "Publish nightly package to github package" echo "ls output directory" ls -R ./output/nightly dotnet nuget push --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/microsoft/index.json" ./output/nightly/*.nupkg --skip-duplicate + continue-on-error: true - name: Publish nightly package to agentchat myget feed run: | echo "Publish nightly package to agentchat myget feed" @@ -195,3 +201,5 @@ jobs: dotnet nuget push --api-key ${{ secrets.MYGET_TOKEN }} --source "https://www.myget.org/F/agentchat/api/v3/index.json" ./output/nightly/*.nupkg --skip-duplicate env: MYGET_TOKEN: ${{ secrets.MYGET_TOKEN }} + continue-on-error: true +