@@ -217,25 +217,28 @@ public async Task<RealtimeSession> CreateSession(Agent agent, List<RoleDialogMod
217217 systemInstruction : request . SystemInstruction ? . Parts . FirstOrDefault ( ) ? . Text ) ;
218218 _client . UseGoogleSearch = _settings . Gemini . UseGoogleSearch ;
219219
220- if ( request . Tools != null && request . Tools . Count > 0 )
220+ if ( _settings . Gemini . UseGoogleSearch )
221221 {
222- var lst = ( request . Tools . Select ( s => ( IFunctionTool ) new TemporaryFunctionTool ( s ) ) . ToList ( ) ) ;
223-
224- _client . AddFunctionTools ( lst , new ToolConfig ( )
222+ if ( request . Tools == null )
223+ request . Tools = new List < Tool > ( ) ;
224+ request . Tools . Add ( new Tool ( )
225225 {
226- FunctionCallingConfig = new FunctionCallingConfig ( )
227- {
228- Mode = FunctionCallingMode . AUTO
229- }
226+ GoogleSearch = new GoogleSearchTool ( )
230227 } ) ;
231228 }
232229
233230 await AttachEvents ( ) ;
234231
235232 await _client . ConnectAsync ( ) ;
236233
237- _client . FunctionTools ? . Clear ( ) ;
238-
234+ await _client . SendSetupAsync ( new BidiGenerateContentSetup ( )
235+ {
236+ GenerationConfig = config ,
237+ Model = Model ,
238+ SystemInstruction = request . SystemInstruction ,
239+ Tools = request . Tools ? . ToArray ( ) ,
240+ } ) ;
241+
239242 return new RealtimeSession ( )
240243 {
241244 Id = _client . ConnectionId . ToString ( ) ,
@@ -271,13 +274,14 @@ public async Task<string> UpdateSession(RealtimeHubConnection conn, bool interru
271274 config . Temperature = Math . Max ( realtimeModelSettings . Temperature , 0.6f ) ;
272275 config . MaxOutputTokens = realtimeModelSettings . MaxResponseOutputTokens ;
273276 }
277+
274278
275279 var functions = request . Tools ? . SelectMany ( s => s . FunctionDeclarations ) . Select ( x =>
276280 {
277281 var fn = new FunctionDef
278282 {
279283 Name = x . Name ?? string . Empty ,
280- Description = x . Description ?? string . Empty ,
284+ Description = x . Description ?? string . Empty ,
281285 } ;
282286 fn . Parameters = x . Parameters != null
283287 ? JsonSerializer . Deserialize < FunctionParametersDef > ( JsonSerializer . Serialize ( x . Parameters ) )
@@ -287,6 +291,16 @@ public async Task<string> UpdateSession(RealtimeHubConnection conn, bool interru
287291
288292 await HookEmitter . Emit < IContentGeneratingHook > ( _services ,
289293 async hook => { await hook . OnSessionUpdated ( agent , prompt , functions ) ; } ) ;
294+
295+ if ( _settings . Gemini . UseGoogleSearch )
296+ {
297+ if ( request . Tools == null )
298+ request . Tools = new List < Tool > ( ) ;
299+ request . Tools . Add ( new Tool ( )
300+ {
301+ GoogleSearch = new GoogleSearchTool ( )
302+ } ) ;
303+ }
290304
291305 //ToDo: Not sure what's the purpose of UpdateSession, Google Realtime conversion works right away after sending the message!
292306
@@ -309,7 +323,7 @@ public async Task InsertConversationItem(RoleDialogModel message)
309323 {
310324 var function = new FunctionResponse ( )
311325 {
312- Name = message . FunctionName ?? string . Empty ,
326+ Name = message . FunctionName ?? string . Empty ,
313327 Response = JsonNode . Parse ( message . Content ?? "{}" )
314328 } ;
315329
@@ -323,11 +337,7 @@ await _client.SendToolResponseAsync(new BidiGenerateContentToolResponse()
323337 }
324338 else if ( message . Role == AgentRole . User )
325339 {
326- await _client . SendClientContentAsync ( new BidiGenerateContentClientContent ( )
327- {
328- TurnComplete = true ,
329- Turns = [ new Content ( message . Content , AgentRole . User ) ]
330- } ) ;
340+ await _client . SentTextAsync ( message . Content ) ;
331341 }
332342 else
333343 {
@@ -428,7 +438,7 @@ public Task<RoleDialogModel> OnConversationItemCreated(RealtimeHubConnection con
428438 {
429439 FunctionResponse = new FunctionResponse
430440 {
431- Name = message . FunctionName ?? string . Empty ,
441+ Name = message . FunctionName ?? string . Empty ,
432442 Response = new JsonObject ( )
433443 {
434444 [ "result" ] = message . Content ?? string . Empty
0 commit comments