Skip to content

Commit aef2284

Browse files
.Net: Make the previously flaky integration test more resilient and enable it (#12392)
1 parent 811dde0 commit aef2284

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

dotnet/src/IntegrationTests/Plugins/ContextualFunctionProviderTests.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void OnModelInvokingAsync(ICollection<ChatMessage> newMessages, AIContext contex
8888
Assert.Contains(relevantFunctions, f => f.Name == "IdentifySentimentTrend");
8989
}
9090

91-
[Fact(Skip = "This test periodically fails. Disabling it for now until the root cause is identified.")]
91+
[Fact]
9292
private async Task ItShouldSelectFunctionsBasedOnPreviousAndCurrentInvocationContextAsync()
9393
{
9494
// Arrange
@@ -116,7 +116,31 @@ void OnModelInvokingAsync(ICollection<ChatMessage> newMessages, AIContext contex
116116
maxNumberOfFunctions: 1, // Instruct the provider to return only one relevant function
117117
options: new ContextualFunctionProviderOptions
118118
{
119-
NumberOfRecentMessagesInContext = 1 // Use only the last message from the previous agent invocation
119+
NumberOfRecentMessagesInContext = 1, // Use only the last message from the previous agent invocation
120+
ContextEmbeddingValueProvider = (recentMessages, newMessages, _) =>
121+
{
122+
string context;
123+
124+
// Provide a deterministic context for the VM deployment request instead of using the one assembled by the provider based on
125+
// the LLM's non-deterministic response for the VM provisioning request. This is done to ensure that the context is always
126+
// the same for the VM deployment request; otherwise, the non-deterministic context could lead to different function selection
127+
// results for the same VM deployment request, resulting in test flakiness.
128+
if (newMessages.Any(m => m.Text.Contains("Deploy it")))
129+
{
130+
context = "A VM has been successfully provisioned with the ID: 40a2d11e-233b-409e-8638-9d4508623b93.\r\nDeploy it";
131+
}
132+
else
133+
{
134+
context = string.Join(
135+
Environment.NewLine,
136+
recentMessages
137+
.TakeLast(1)
138+
.Where(m => !string.IsNullOrWhiteSpace(m?.Text))
139+
.Select(m => m.Text));
140+
}
141+
142+
return Task.FromResult(context);
143+
},
120144
}
121145
);
122146

0 commit comments

Comments
 (0)