Skip to content

Commit cf2fe4a

Browse files
[.Net] Fix #3306 (#3310)
* break conversation when orchestartor return null * enable test on different OS
1 parent 2ab74db commit cf2fe4a

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

.github/workflows/dotnet-build.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ jobs:
4343
if: steps.filter.outputs.workflows == 'true'
4444
build:
4545
name: Dotnet Build
46-
runs-on: ubuntu-latest
4746
needs: paths-filter
4847
if: needs.paths-filter.outputs.hasChanges == 'true'
4948
defaults:
5049
run:
5150
working-directory: dotnet
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
os: [ ubuntu-latest, macos-latest, windows-latest ]
55+
runs-on: ${{ matrix.os }}
5256
steps:
5357
- uses: actions/checkout@v4
5458
with:
@@ -92,7 +96,7 @@ jobs:
9296
- name: Setup dotnet
9397
uses: actions/setup-dotnet@v4
9498
with:
95-
global-json-file: dotnet/global.json
99+
dotnet-version: '8.0.x'
96100

97101
- name: publish AOT testApp, assert static analysis warning count, and run the app
98102
shell: pwsh
@@ -181,12 +185,14 @@ jobs:
181185
env:
182186
AZURE_ARTIFACTS_FEED_URL: https://devdiv.pkgs.visualstudio.com/DevDiv/_packaging/AutoGen/nuget/v3/index.json
183187
NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_TOKEN }}
188+
continue-on-error: true
184189
- name: Publish nightly package to github package
185190
run: |
186191
echo "Publish nightly package to github package"
187192
echo "ls output directory"
188193
ls -R ./output/nightly
189194
dotnet nuget push --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/microsoft/index.json" ./output/nightly/*.nupkg --skip-duplicate
195+
continue-on-error: true
190196
- name: Publish nightly package to agentchat myget feed
191197
run: |
192198
echo "Publish nightly package to agentchat myget feed"
@@ -195,3 +201,5 @@ jobs:
195201
dotnet nuget push --api-key ${{ secrets.MYGET_TOKEN }} --source "https://www.myget.org/F/agentchat/api/v3/index.json" ./output/nightly/*.nupkg --skip-duplicate
196202
env:
197203
MYGET_TOKEN: ${{ secrets.MYGET_TOKEN }}
204+
continue-on-error: true
205+

dotnet/src/AutoGen.Core/Extension/GroupChatExtension.cs

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public static async IAsyncEnumerable<IMessage> SendAsync(
4343
while (maxRound-- > 0)
4444
{
4545
var messages = await groupChat.CallAsync(chatHistory, maxRound: 1, cancellationToken);
46+
47+
// if no new messages, break the loop
48+
if (messages.Count() == chatHistory.Count())
49+
{
50+
yield break;
51+
}
52+
4653
var lastMessage = messages.Last();
4754

4855
yield return lastMessage;

dotnet/test/AutoGen.Tests/GroupChat/GroupChatTests.cs

+25
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,29 @@ public async Task ItSendAsyncDoesntAddDuplicateInitializeMessagesTest()
8585

8686
chatHistory.Count().Should().Be(2);
8787
}
88+
89+
[Fact]
90+
public async Task ItTerminateConversationWhenNoSpeakerAvailable()
91+
{
92+
// fix #3306
93+
var alice = new DefaultReplyAgent("Alice", "I am alice");
94+
var bob = new DefaultReplyAgent("Bob", "I am bob");
95+
var cathy = new DefaultReplyAgent("Cathy", $"I am cathy, {GroupChatExtension.TERMINATE}");
96+
97+
var orchestrator = Mock.Of<IOrchestrator>();
98+
Mock.Get(orchestrator).Setup(x => x.GetNextSpeakerAsync(It.IsAny<OrchestrationContext>(), It.IsAny<CancellationToken>()))
99+
.ReturnsAsync((IAgent?)null);
100+
101+
var groupChat = new GroupChat([alice, bob, cathy], orchestrator);
102+
103+
var chatHistory = new List<IMessage>();
104+
105+
var maxRound = 10;
106+
await foreach (var message in groupChat.SendAsync(chatHistory, maxRound))
107+
{
108+
chatHistory.Add(message);
109+
}
110+
111+
chatHistory.Count().Should().Be(0);
112+
}
88113
}

0 commit comments

Comments
 (0)