* break conversation when orchestartor return null

* enable test on different OS
This commit is contained in:
Xiaoyun Zhang 2024-08-06 14:59:44 -07:00 committed by GitHub
parent 2ab74dbfb9
commit cf2fe4aa78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 2 deletions

View File

@ -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

View File

@ -43,6 +43,13 @@ public static class GroupChatExtension
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;

View File

@ -85,4 +85,29 @@ public class GroupChatTests
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);
}
}