# Useful but Little-Known Features of ADK 2.0
🌍 What if your agent could remember conversations from last week and use that context to give better answers today?
ADK 2.0's Memory feature provides agents with long-term knowledge that persists across sessions. It stores past conversations and learned information, retrieving them when needed.
📌 Title: Memory
🔗 URL:
🧩 Overview
Unlike State, Memory manages long-term knowledge that spans across sessions. Three memory service implementations are available: InMemoryMemoryService for development and testing, VertexAiMemoryBankService for production with semantic search, and VertexAiRagMemoryService for vector-based RAG. Two built-in tools handle retrieval: PreloadMemory (auto-loads at session start) and LoadMemory (loads on demand). For programmatic access, use tool_context.search_memory(). You can also combine multiple memory services through custom tools.
🛠 How to use it
Set up a memory service and add memory tools to your agent.
```python
from google.adk.memory import InMemoryMemoryService
from import PreloadMemory, LoadMemory
# Development: in-memory implementation
memory_service = InMemoryMemoryService()
# Add memory tools to the agent
agent = Agent(
name="assistant",
tools=[PreloadMemory(), LoadMemory()],
...
)
# Configure the runner with the memory service
runner = Runner(
agent=agent,
memory_service=memory_service,
...
)
```
To search memory programmatically from within a tool:
```python
def my_tool(query: str, tool_context: ToolContext) -> str:
results = tool_context.search_memory(query="past conversations")
return str(results)
```
For multiple memory sources, create custom tools that integrate them together.
🏗 Building it into production
・Prototype quickly with InMemoryMemoryService, then switch to VertexAI services for production
・Use PreloadMemory to auto-load frequently needed context and improve response quality
・Design appropriate boundaries for what gets stored in memory to prevent data bloat
・Build custom tools to integrate multiple memory sources into a comprehensive knowledge base
💡 Use cases
🧠 Generate personalized responses based on past conversation history
📚 Retain long-term memory of project discussions and decisions
🔍 Automatically retrieve relevant past interactions via semantic search
🤝 Share a knowledge base across multiple agents using memory as a common layer
⚠️ Watch out
InMemoryMemoryService loses all data when the process terminates — do not use it in production. VertexAI-based services require GCP setup and configuration. As stored data grows, search latency can be affected, so plan a data management strategy for your memory stores.
✨ Memory gives your agents the ability to carry context across sessions. It's a game-changer for building agents that deliver consistently better long-term user experiences.
#
ADK# #
AIAgent#