usingvarclient=newGeminiClient(apiKey);varmodelId=GetGenerateContentModelId();try{vargetWeatherTool=AIFunctionFactory.Create((stringlocation)=>$"The weather in {location} is 72°F and sunny.",name:"get_weather",description:"Gets the current weather for a given location.");IChatClientchatClient=client;varmessages=newList<ChatMessage>{new(ChatRole.User,"What is the weather in Paris?"),};// First turn: model requests tool callvarresponse=awaitchatClient.GetResponseAsync(messages,newChatOptions{ModelId=modelId,Tools=[getWeatherTool],});varfunctionCall=response.Messages.SelectMany(m=>m.Contents).OfType<FunctionCallContent>().FirstOrDefault();// Verify thought signature is preserved on function call content// (Gemini API requires it to be echoed back in subsequent turns)if(functionCall!.AdditionalProperties?.TryGetValue("gemini.thoughtSignature",outvarsig)==true){}// Add assistant message with function call and tool resultmessages.AddRange(response.Messages);vartoolResult=awaitgetWeatherTool.InvokeAsync(functionCall.Argumentsis{}args?newAIFunctionArguments(args):null);messages.Add(newChatMessage(ChatRole.Tool,[ new FunctionResultContent(functionCall.CallId, toolResult), ]));// Second turn: model should produce a final text response// (this verifies the thought signature round-trip works — the API// rejects requests with missing thought signatures)varfinalResponse=awaitchatClient.GetResponseAsync(messages,newChatOptions{ModelId=modelId,Tools=[getWeatherTool],});}catch(ApiExceptionex)when(IsTransientAvailabilityIssue(ex)){AssertTransientAvailability(ex);}