@@ -324,10 +324,14 @@ public async Task GrokGrpcInvokesHostedSearchTool()
324324
325325 Assert . Contains ( "TSLA" , text ) ;
326326 Assert . NotNull ( response . ModelId ) ;
327+ Assert . Contains ( new Uri ( "https://finance.yahoo.com/quote/TSLA/news/" ) , response . Messages
328+ . SelectMany ( x => x . Contents )
329+ . SelectMany ( x => x . Annotations ? . OfType < CitationAnnotation > ( ) ?? [ ] )
330+ . Select ( x => x . Url ) ) ;
327331 }
328332
329333 [ SecretsFact ( "XAI_API_KEY" ) ]
330- public async Task GrokGrpcInvokesGrokSearchTool ( )
334+ public async Task GrokGrpcInvokesGrokSearchToolIncludesDomain ( )
331335 {
332336 var messages = new Chat ( )
333337 {
@@ -341,13 +345,66 @@ public async Task GrokGrpcInvokesGrokSearchTool()
341345 {
342346 Tools = [ new GrokSearchTool
343347 {
344- AllowedDomains = [ "microsoft.com" , "news.microsoft.com" ]
348+ AllowedDomains = [ "microsoft.com" , "news.microsoft.com" ] ,
345349 } ]
346350 } ;
347351
348352 var response = await grok . GetResponseAsync ( messages , options ) ;
349353
350354 Assert . NotNull ( response . Text ) ;
351355 Assert . Contains ( "Microsoft" , response . Text ) ;
356+
357+ var urls = response . Messages
358+ . SelectMany ( x => x . Contents )
359+ . SelectMany ( x => x . Annotations ? . OfType < CitationAnnotation > ( ) ?? [ ] )
360+ . Where ( x => x . Url is not null )
361+ . Select ( x => x . Url ! )
362+ . ToList ( ) ;
363+
364+ foreach ( var url in urls )
365+ {
366+ output . WriteLine ( url . ToString ( ) ) ;
367+ }
368+
369+ Assert . All ( urls , x => x . Host . EndsWith ( ".microsoft.com" ) ) ;
370+ }
371+
372+ [ SecretsFact ( "XAI_API_KEY" ) ]
373+ public async Task GrokGrpcInvokesGrokSearchToolExcludesDomain ( )
374+ {
375+ var messages = new Chat ( )
376+ {
377+ { "system" , "You are an AI assistant that knows how to search the web." } ,
378+ { "user" , "What is the latest news about Microsoft?" } ,
379+ } ;
380+
381+ var grok = new GrokClient ( Configuration [ "XAI_API_KEY" ] ! ) . AsIChatClient ( "grok-4-fast" ) ;
382+
383+ var options = new ChatOptions
384+ {
385+ Tools = [ new GrokSearchTool
386+ {
387+ ExcludedDomains = [ "blogs.microsoft.com" ]
388+ } ]
389+ } ;
390+
391+ var response = await grok . GetResponseAsync ( messages , options ) ;
392+
393+ Assert . NotNull ( response . Text ) ;
394+ Assert . Contains ( "Microsoft" , response . Text ) ;
395+
396+ var urls = response . Messages
397+ . SelectMany ( x => x . Contents )
398+ . SelectMany ( x => x . Annotations ? . OfType < CitationAnnotation > ( ) ?? [ ] )
399+ . Where ( x => x . Url is not null )
400+ . Select ( x => x . Url ! )
401+ . ToList ( ) ;
402+
403+ foreach ( var url in urls )
404+ {
405+ output . WriteLine ( url . ToString ( ) ) ;
406+ }
407+
408+ Assert . DoesNotContain ( urls , x => x . Host == "blogs.microsoft.com" ) ;
352409 }
353410}
0 commit comments