For instance, our Python Tutor agent might want to store quiz scores over time: how has the student improved? Long-term memories could also help the agent develop a personalized learning plan for the student: what topics has the student consistently struggled with?
ADK offers two ways to store these long-term memories. The default way is in memory, by using an InMemoryMemoryService. Here, all sessions are stored raw (with the full conversation thread), and can be retrieved by the agent in further sessions using a basic keyword search. This method is good for local development, but it has the same pitfall as the InMemorySessionService: if ADK restarts or crashes, all memories are lost forever. Another downside to this method is if you have a lot of past user sessions, and you’re retrieving the session’s event history in its raw form, you could overwhelm your agent’s model with too much context.
Luckily, ADK provides a way to store long-term memories persistently outside the ADK runtime, and that’s with a VertexAIMemoryBankService. This memory service uses Vertex AI Memory Bank (Preview) to intelligently store and retrieve memories from past user interactions.
Memory Bank uses the Gemini model to extract key information from session data, to store just the key memories for future use: