AI / Google Antigravity Gemini Fundamentals Interview Questions
How do you implement multi-turn conversations in the Gemini API?
Multi-turn conversations maintain context across several exchanges. The Gemini API supports two approaches: manually managing conversation history with generateContent, or using the Interactions API's previous_interaction_id for server-side state management.
from google import genai from google.genai import types client = genai.Client() # Approach 1: Manual history with generateContent (legacy) history = [] while True: user_input = input("You: ") history.append(types.Content(role="user", parts=[types.Part(text=user_input)])) response = client.models.generate_content( model="gemini-3.5-flash", contents=history, ) assistant_reply = response.candidates[0].content history.append(assistant_reply) # add model turn to history print(f"Gemini: {assistant_reply.parts[0].text}") # Approach 2: Interactions API with previous_interaction_id (recommended) # First turn: first = client.interactions.create( model="gemini-3.5-flash", input="I am building a task management app in Python.", ) # Second turn - model remembers the first: second = client.interactions.create( model="gemini-3.5-flash", input="What database would you recommend for my app?", previous_interaction_id=first.id, # server retrieves first turn context ) # Third turn: third = client.interactions.create( model="gemini-3.5-flash", input="Show me the schema for that database.", previous_interaction_id=second.id, ) print(third.output_text)
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
