@@ -88,7 +88,7 @@ void OnModelInvokingAsync(ICollection<ChatMessage> newMessages, AIContext contex
88
88
Assert . Contains ( relevantFunctions , f => f . Name == "IdentifySentimentTrend" ) ;
89
89
}
90
90
91
- [ Fact ( Skip = "This test periodically fails. Disabling it for now until the root cause is identified." ) ]
91
+ [ Fact ]
92
92
private async Task ItShouldSelectFunctionsBasedOnPreviousAndCurrentInvocationContextAsync ( )
93
93
{
94
94
// Arrange
@@ -116,7 +116,31 @@ void OnModelInvokingAsync(ICollection<ChatMessage> newMessages, AIContext contex
116
116
maxNumberOfFunctions : 1 , // Instruct the provider to return only one relevant function
117
117
options : new ContextualFunctionProviderOptions
118
118
{
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 \n Deploy 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
+ } ,
120
144
}
121
145
) ;
122
146
0 commit comments