Multi-turn Conversation (Interactions)
Persist previous_interaction_id across turns with a database so GeminiInteractions keeps context server-side.
The Interactions API keeps conversation history server-side. After the first turn, the model sends only the new message and references the prior turn via previous_interaction_id. Multi-turn needs a database so the interaction ID from each response is persisted and read back on the next turn.
Code
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.google import GeminiInteractions
agent = Agent(
model=GeminiInteractions(id="gemini-3.5-flash"),
add_history_to_context=True,
db=SqliteDb(db_file="tmp/data.db"),
markdown=True,
)
if __name__ == "__main__":
# First turn - establishes the interaction
agent.print_response("My name is Alice and I love hiking in the mountains.")
# Second turn - references the previous interaction for context
agent.print_response("What did I just tell you about myself?")
# Third turn - continues the conversation chain
agent.print_response(
"Suggest a hiking destination based on what you know about me."
)Usage
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateSet your API key
export GOOGLE_API_KEY=xxxInstall dependencies
uv pip install -U "google-genai>=2.3" sqlalchemy agnoRun Agent
Save the code above as multi_turn.py, then run:
python multi_turn.py