@@ -113,7 +113,6 @@ private async Task ReceiveMessage(
113113 continue ;
114114 }
115115
116- Console . WriteLine ( $ "Received text: { receivedText } ") ;
117116 try
118117 {
119118 var response = JsonSerializer . Deserialize < RealtimeServerResponse > ( receivedText , _jsonOptions ) ;
@@ -126,10 +125,15 @@ private async Task ReceiveMessage(
126125 {
127126 _logger . LogInformation ( $ "Session setup completed.") ;
128127 }
128+ else if ( response . SessionResumptionUpdate != null )
129+ {
130+ _logger . LogInformation ( $ "Session resumption update => New handle: { response . SessionResumptionUpdate . NewHandle } , Resumable: { response . SessionResumptionUpdate . Resumable } ") ;
131+ }
129132 else if ( response . ToolCall != null && ! response . ToolCall . FunctionCalls . IsNullOrEmpty ( ) )
130133 {
131- var functionCall = response . ToolCall . FunctionCalls . First ( ) ;
132- _logger . LogInformation ( $ "Tool call received { functionCall . Name } ({ functionCall . Args ? . ToJsonString ( _jsonOptions ) ?? string . Empty } ).") ;
134+ var functionCall = response . ToolCall . FunctionCalls ! . First ( ) ;
135+
136+ _logger . LogInformation ( $ "Tool call received: { functionCall . Name } ({ functionCall . Args ? . ToJsonString ( _jsonOptions ) ?? string . Empty } ).") ;
133137
134138 if ( functionCall != null )
135139 {
@@ -154,7 +158,7 @@ private async Task ReceiveMessage(
154158 _logger . LogInformation ( $ "Model audio delta received.") ;
155159
156160 // Handle input transcription
157- var inputTranscription = inputStream . GetString ( ) ;
161+ var inputTranscription = inputStream . GetText ( ) ;
158162 if ( ! string . IsNullOrEmpty ( inputTranscription ) )
159163 {
160164 var message = OnUserAudioTranscriptionCompleted ( conn , inputTranscription ) ;
@@ -182,7 +186,8 @@ private async Task ReceiveMessage(
182186 {
183187 _logger . LogInformation ( $ "Model turn completed.") ;
184188
185- var outputTranscription = outputStream . GetString ( ) ;
189+ // Handle output transcription
190+ var outputTranscription = outputStream . GetText ( ) ;
186191 if ( ! string . IsNullOrEmpty ( outputTranscription ) )
187192 {
188193 var messages = await OnResponseDone ( conn , outputTranscription , response . UsageMetaData ) ;
@@ -237,13 +242,13 @@ await SendEventToModel(new BidiClientPayload
237242
238243 public async Task TriggerModelInference ( string ? instructions = null )
239244 {
240- var content = new Content ( "Please respond to me ." , AgentRole . User ) ;
245+ var content = new Content ( instructions ?? "Please respond to user ." , AgentRole . User ) ;
241246
242247 await SendEventToModel ( new BidiClientPayload
243248 {
244249 ClientContent = new ( )
245250 {
246- Turns = null ,
251+ Turns = [ content ] ,
247252 TurnComplete = true
248253 }
249254 } ) ;
@@ -269,9 +274,10 @@ public async Task SendEventToModel(object message)
269274 public async Task < string > UpdateSession ( RealtimeHubConnection conn , bool isInit = false )
270275 {
271276 var convService = _services . GetRequiredService < IConversationService > ( ) ;
272- var conv = await convService . GetConversation ( conn . ConversationId ) ;
273-
274277 var agentService = _services . GetRequiredService < IAgentService > ( ) ;
278+ var realtimeSetting = _services . GetRequiredService < RealtimeModelSettings > ( ) ;
279+
280+ var conv = await convService . GetConversation ( conn . ConversationId ) ;
275281 var agent = await agentService . LoadAgent ( conn . CurrentAgentId ) ;
276282
277283 var ( prompt , request ) = PrepareOptions ( agent , [ ] ) ;
@@ -285,10 +291,8 @@ public async Task<string> UpdateSession(RealtimeHubConnection conn, bool isInit
285291 var words = new List < string > ( ) ;
286292 HookEmitter . Emit < IRealtimeHook > ( _services , hook => words . AddRange ( hook . OnModelTranscriptPrompt ( agent ) ) ) ;
287293
288- var realtimeModelSettings = _services . GetRequiredService < RealtimeModelSettings > ( ) ;
289-
290- config . Temperature = Math . Max ( realtimeModelSettings . Temperature , 0.6f ) ;
291- config . MaxOutputTokens = realtimeModelSettings . MaxResponseOutputTokens ;
294+ config . Temperature = Math . Max ( realtimeSetting . Temperature , 0.6f ) ;
295+ config . MaxOutputTokens = realtimeSetting . MaxResponseOutputTokens ;
292296 }
293297
294298 var functions = request . Tools ? . SelectMany ( s => s . FunctionDeclarations ) . Select ( x =>
@@ -316,7 +320,6 @@ await HookEmitter.Emit<IContentGeneratingHook>(_services,
316320 } ) ;
317321 }
318322
319- var realtimeSetting = _services . GetRequiredService < RealtimeModelSettings > ( ) ;
320323 await SendEventToModel ( new RealtimeClientPayload
321324 {
322325 Setup = new RealtimeGenerateContentSetup ( )
@@ -326,7 +329,8 @@ await SendEventToModel(new RealtimeClientPayload
326329 SystemInstruction = request . SystemInstruction ,
327330 Tools = request . Tools ? . ToArray ( ) ,
328331 InputAudioTranscription = realtimeSetting . InputAudioTranscribe ? new ( ) : null ,
329- OutputAudioTranscription = realtimeSetting . InputAudioTranscribe ? new ( ) : null
332+ OutputAudioTranscription = realtimeSetting . InputAudioTranscribe ? new ( ) : null ,
333+ SessionResumption = new ( )
330334 }
331335 } ) ;
332336
@@ -339,6 +343,7 @@ public async Task InsertConversationItem(RoleDialogModel message)
339343 {
340344 var function = new FunctionResponse ( )
341345 {
346+ Id = message . ToolCallId ,
342347 Name = message . FunctionName ?? string . Empty ,
343348 Response = new JsonObject ( )
344349 {
0 commit comments