1- using System . Text . Json . Serialization ;
1+ using System . ComponentModel ;
2+ using System . Text . Json . Serialization ;
23using Microsoft . Extensions . AI ;
34
45namespace Devlooped . Extensions . AI . Grok ;
56
67/// <summary>
7- /// Enables or disables Grok's live search capabilities .
8- /// See https://docs.x.ai/docs/guides/live- search#enabling-search
8+ /// Enables or disables Grok's search tool .
9+ /// See https://docs.x.ai/docs/guides/tools/ search-tools
910/// </summary>
11+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
12+ [ Obsolete ( "No longer supported in agent search too. Use either GrokSearchTool or GrokXSearchTool" ) ]
1013public enum GrokSearch
1114{
1215 /// <summary>
13- /// (default): Live search is available to the model, but the model automatically decides whether to perform live search.
16+ /// (default): Search tool is available to the model, but the model automatically decides whether to perform search.
1417 /// </summary>
1518 Auto ,
1619 /// <summary>
17- /// Enables live search.
20+ /// Enables search tool .
1821 /// </summary>
1922 On ,
2023 /// <summary>
21- /// Disables search and uses the model without accessing additional information from data sources.
24+ /// Disables search tool and uses the model without accessing additional information from data sources.
2225 /// </summary>
2326 Off
2427}
2528
26- /// <summary>Configures Grok's live search capabilities. See https://docs.x.ai/docs/guides/live-search.</summary>
27- public class GrokSearchTool ( GrokSearch mode ) : HostedWebSearchTool
29+ /// <summary>
30+ /// Configures Grok's agentic search tool.
31+ /// See https://docs.x.ai/docs/guides/tools/search-tools.
32+ /// </summary>
33+ public class GrokSearchTool : HostedWebSearchTool
2834{
29- /// <summary>Sets the search mode for Grok's live search capabilities.</summary>
30- public GrokSearch Mode { get ; } = mode ;
35+ public GrokSearchTool ( ) { }
36+
3137 /// <inheritdoc/>
32- public override string Name => "Live Search" ;
38+ public override string Name => "Search" ;
3339 /// <inheritdoc/>
34- public override string Description => "Performs live search using X.AI" ;
40+ public override string Description => "Performs search using X.AI" ;
41+
42+ /// <summary>Use to make the web search only perform the search and web browsing on web pages that fall within the specified domains. Can include a maximum of five domains.</summary>
43+ public IList < string > ? AllowedDomains { get ; set ; }
44+ /// <summary>Use to prevent the model from including the specified domains in any web search tool invocations and from browsing any pages on those domains. Can include a maximum of five domains.</summary>
45+ public IList < string > ? ExcludedDomains { get ; set ; }
46+ /// <summary>See https://docs.x.ai/docs/guides/tools/search-tools#enable-image-understanding</summary>
47+ public bool EnableImageUnderstanding { get ; set ; }
48+
49+ #region Legacy Live Search
50+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
51+ [ Obsolete ( "Legacy live search mode is not available in new agentic search tool." ) ]
52+ public GrokSearchTool ( GrokSearch mode ) => Mode = mode ;
53+ /// <summary>Sets the search mode for Grok's live search capabilities.</summary>
54+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
55+ [ Obsolete ( "Legacy live search mode is not available in new agentic search tool." ) ]
56+ public GrokSearch Mode { get ; set ; }
3557 /// <summary>See https://docs.x.ai/docs/guides/live-search#set-date-range-of-the-search-data</summary>
58+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
59+ [ Obsolete ( "Date range can only be applied to X source." ) ]
3660 public DateOnly ? FromDate { get ; set ; }
3761 /// <summary>See https://docs.x.ai/docs/guides/live-search#set-date-range-of-the-search-data</summary>
62+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
63+ [ Obsolete ( "Date range can only be applied to X search tool." ) ]
3864 public DateOnly ? ToDate { get ; set ; }
3965 /// <summary>See https://docs.x.ai/docs/guides/live-search#limit-the-maximum-amount-of-data-sources</summary>
66+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
67+ [ Obsolete ( "No longer supported in search tool." ) ]
4068 public int ? MaxSearchResults { get ; set ; }
4169 /// <summary>See https://docs.x.ai/docs/guides/live-search#data-sources-and-parameters</summary>
70+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
71+ [ Obsolete ( "No longer supported in search tool." ) ]
4272 public IList < GrokSource > ? Sources { get ; set ; }
4373 /// <summary>See https://docs.x.ai/docs/guides/live-search#returning-citations</summary>
74+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
75+ [ Obsolete ( "No longer supported in search tool." ) ]
4476 public bool ? ReturnCitations { get ; set ; }
77+ #endregion
78+ }
79+
80+ /// <summary>
81+ /// Configures Grok's agentic search tool for X.
82+ /// See https://docs.x.ai/docs/guides/tools/search-tools.
83+ /// </summary>
84+ public class GrokXSearchTool : HostedWebSearchTool
85+ {
86+ /// <summary>See https://docs.x.ai/docs/guides/tools/search-tools#only-consider-x-posts-from-specific-handles</summary>
87+ [ JsonPropertyName ( "allowed_x_handles" ) ]
88+ public IList < string > ? AllowedHandles { get ; set ; }
89+ /// <summary>See https://docs.x.ai/docs/guides/tools/search-tools#exclude-x-posts-from-specific-handles</summary>
90+ [ JsonPropertyName ( "excluded_x_handles" ) ]
91+ public IList < string > ? ExcludedHandles { get ; set ; }
92+ /// <summary>See https://docs.x.ai/docs/guides/tools/search-tools#date-range</summary>
93+ public DateOnly ? FromDate { get ; set ; }
94+ /// <summary>See https://docs.x.ai/docs/guides/tools/search-tools#date-range</summary>
95+ public DateOnly ? ToDate { get ; set ; }
96+ /// <summary>See https://docs.x.ai/docs/guides/tools/search-tools#enable-image-understanding-1</summary>
97+ public bool EnableImageUnderstanding { get ; set ; }
98+ /// <summary>See https://docs.x.ai/docs/guides/tools/search-tools#enable-video-understanding</summary>
99+ public bool EnableVideoUnderstanding { get ; set ; }
45100}
46101
47102/// <summary>Grok Live Search data source base type.</summary>
@@ -50,9 +105,13 @@ public class GrokSearchTool(GrokSearch mode) : HostedWebSearchTool
50105[ JsonDerivedType ( typeof ( GrokNewsSource ) , "news" ) ]
51106[ JsonDerivedType ( typeof ( GrokRssSource ) , "rss" ) ]
52107[ JsonDerivedType ( typeof ( GrokXSource ) , "x" ) ]
108+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
109+ [ Obsolete ( "No longer supported in agent search too. Use either GrokSearchTool or GrokXSearchTool" ) ]
53110public abstract class GrokSource { }
54111
55112/// <summary>Search-based data source base class providing common properties for `web` and `news` sources.</summary>
113+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
114+ [ Obsolete ( "No longer supported in agent search too. Use either GrokSearchTool or GrokXSearchTool" ) ]
56115public abstract class GrokSearchSource : GrokSource
57116{
58117 /// <summary>Include data from a specific country/region by specifying the ISO alpha-2 code of the country.</summary>
@@ -64,24 +123,32 @@ public abstract class GrokSearchSource : GrokSource
64123}
65124
66125/// <summary>Web live search source.</summary>
126+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
127+ [ Obsolete ( "No longer supported in agent search too. Use either GrokSearchTool or GrokXSearchTool" ) ]
67128public class GrokWebSource : GrokSearchSource
68129{
69130 /// <summary>See https://docs.x.ai/docs/guides/live-search#parameter-allowed_websites-supported-by-web</summary>
70131 public IList < string > ? AllowedWebsites { get ; set ; }
71132}
72133
73134/// <summary>News live search source.</summary>
135+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
136+ [ Obsolete ( "No longer supported in agent search too. Use either GrokSearchTool or GrokXSearchTool" ) ]
74137public class GrokNewsSource : GrokSearchSource { }
75138
76139/// <summary>RSS live search source.</summary>
77140/// <param name="rss">The RSS feed to search.</param>
141+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
142+ [ Obsolete ( "No longer supported in agent search too. Use either GrokSearchTool or GrokXSearchTool" ) ]
78143public class GrokRssSource ( string rss ) : GrokSource
79144{
80145 /// <summary>See https://docs.x.ai/docs/guides/live-search#parameter-link-supported-by-rss</summary>
81146 public IList < string > ? Links { get ; set ; } = [ rss ] ;
82147}
83148
84149/// <summary>X live search source./summary>
150+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
151+ [ Obsolete ( "No longer supported in agent search too. Use GrokXSearchTool" ) ]
85152public class GrokXSource : GrokSearchSource
86153{
87154 /// <summary>See https://docs.x.ai/docs/guides/live-search#parameter-excluded_x_handles-supported-by-x</summary>
@@ -96,4 +163,9 @@ public class GrokXSource : GrokSearchSource
96163 /// <summary>See https://docs.x.ai/docs/guides/live-search#parameters-post_favorite_count-and-post_view_count-supported-by-x</summary>
97164 [ JsonPropertyName ( "post_view_count" ) ]
98165 public int ? ViewCount { get ; set ; }
166+ [ JsonPropertyName ( "from_date" ) ]
167+ public DateOnly ? FromDate { get ; set ; }
168+ /// <summary>See https://docs.x.ai/docs/guides/live-search#set-date-range-of-the-search-data</summary>
169+ [ JsonPropertyName ( "to_date" ) ]
170+ public DateOnly ? ToDate { get ; set ; }
99171}
0 commit comments