| name | google-adk-memory |
| description | ADK long-term memory with MemoryService. Use when implementing cross-session recall — InMemoryMemoryService for dev, Vertex AI RAG for production. Covers memory tools (load_memory, preload_memory) and custom memory services. |
Google ADK — Memory (Long-Term Recall)
Core Concept
Memory = knowledge that persists across sessions. Unlike state (per-session), memory lets agents recall information from previous conversations.
Memory Services
| Service | Storage | Use Case |
|---|
InMemoryMemoryService | RAM | Development/testing |
VertexAiRagMemoryService | Vertex AI RAG | Production (managed) |
Import
from google.adk.memory import InMemoryMemoryService
from google.adk.tools import load_memory, preload_memory
Basic Setup with Runner
from google.adk.agents import Agent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.adk.memory import InMemoryMemoryService
agent = Agent(
name="memory_agent",
model="gemini-2.5-flash",
instruction="You remember things users tell you across conversations.",
tools=[load_memory],
)
runner = Runner(
agent=agent,
session_service=InMemorySessionService(),
memory_service=InMemoryMemoryService(),
app_name="my_app",
)
Memory Tools
load_memory
Agent can search memory during conversation:
from google.adk.tools import load_memory
agent = Agent(
name="recall_agent",
model="gemini-2.5-flash",
instruction="Search your memory when users ask about past conversations.",
tools=[load_memory],
)
preload_memory
Automatically loads relevant memories at the start of each invocation:
from google.adk.tools import preload_memory
agent = Agent(
name="aware_agent",
model="gemini-2.5-flash",
instruction="You have context from past conversations preloaded.",
tools=[preload_memory],
)
Vertex AI RAG Memory Service
from google.adk.memory import VertexAiRagMemoryService
memory_service = VertexAiRagMemoryService(
project="my-gcp-project",
location="us-central1",
rag_corpus_name="projects/my-project/locations/us-central1/ragCorpora/my-corpus",
)
runner = Runner(
agent=agent,
session_service=session_service,
memory_service=memory_service,
app_name="my_app",
)
How Memory Works
- Storage: After a session ends, the runner stores the conversation in the memory service
- Retrieval: When
load_memory is called, the memory service searches for relevant past conversations
- Context: Retrieved memories are injected into the agent's context
Custom Memory Service
from google.adk.memory.base_memory_service import BaseMemoryService, SearchMemoryResponse
from google.adk.memory.memory_entry import MemoryEntry
from google.adk.sessions.session import Session
from google.genai import types
class MyMemoryService(BaseMemoryService):
async def add_session_to_memory(self, session: Session) -> None:
"""Store session content in your backend."""
pass
async def search_memory(
self,
*,
app_name: str,
user_id: str,
query: str,
) -> SearchMemoryResponse:
"""Search stored memories by query."""
return SearchMemoryResponse(
memories=[
MemoryEntry(
content=types.Content(
role="model",
parts=[types.Part(text="relevant memory text")],
),
),
]
)
Memory vs State
| Feature | State | Memory |
|---|
| Scope | Within one session | Across all sessions |
| Access | Direct key-value | Semantic search |
| Storage | Session service | Memory service |
| Use case | Current conversation context | Historical knowledge |
Key Rules
- Memory requires both a
SessionService and a MemoryService on the Runner
load_memory lets the agent decide WHEN to recall (on-demand)
preload_memory automatically loads relevant context (always-on)
- Memory is stored after session completion by the Runner
- For production, use
VertexAiRagMemoryService with a RAG corpus
InMemoryMemoryService loses all data on restart
Related Skills
google-adk-session — Session state (short-term, within a session)
google-adk-eval — Testing memory recall in evaluations