Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[.Net] Fix #3306 #3310

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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

7 changes: 7 additions & 0 deletions dotnet/src/AutoGen.Core/Extension/GroupChatExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public static async IAsyncEnumerable<IMessage> 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;
Expand Down
25 changes: 25 additions & 0 deletions dotnet/test/AutoGen.Tests/GroupChat/GroupChatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IOrchestrator>();
Mock.Get(orchestrator).Setup(x => x.GetNextSpeakerAsync(It.IsAny<OrchestrationContext>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((IAgent?)null);

var groupChat = new GroupChat([alice, bob, cathy], orchestrator);

var chatHistory = new List<IMessage>();

var maxRound = 10;
await foreach (var message in groupChat.SendAsync(chatHistory, maxRound))
{
chatHistory.Add(message);
}

chatHistory.Count().Should().Be(0);
}
}
Loading