Skip to content

Commit 5c69b8f

Browse files
Raman369AIclaude
andcommitted
feat(memory): add DatabaseMemoryService with SQL backend and scratchpad
Adds a durable, RDBMS-backed memory service that works with any SQLAlchemy-supported database (SQLite, PostgreSQL, MySQL, MariaDB) as an alternative to the volatile InMemoryMemoryService. Key additions: - DatabaseMemoryService: implements BaseMemoryService with lazy table creation, idempotent session ingest, and delta event ingestion - MemorySearchBackend ABC + KeywordSearchBackend: LIKE/ILIKE search with AND-first → OR-fallback tokenization strategy - Scratchpad KV store and append-only log for intermediate agent state - Four agent-callable BaseTool subclasses: scratchpad_get_tool, scratchpad_set_tool, scratchpad_append_log_tool, scratchpad_get_log_tool - 38 unit tests covering all methods, tool happy-paths, wrong-service errors, multi-user isolation, and session scoping Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6edcb97 commit 5c69b8f

8 files changed

Lines changed: 1855 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ Thumbs.db
9999
*.tmp
100100
*.temp
101101

102+
# Agent handoff / session notes (not for version control)
103+
AGENT_HANDOFF.md
104+
102105
# AI Coding Tools - Project-specific configs
103106
# Developers should symlink or copy AGENTS.md and add their own overrides locally
104107
.adk/

src/google/adk/memory/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,20 @@
3535
' VertexAiRagMemoryService please install it. If not, you can ignore this'
3636
' warning.'
3737
)
38+
39+
try:
40+
from .database_memory_service import DatabaseMemoryService
41+
from .memory_search_backend import KeywordSearchBackend
42+
from .memory_search_backend import MemorySearchBackend
43+
44+
__all__ += [
45+
'DatabaseMemoryService',
46+
'KeywordSearchBackend',
47+
'MemorySearchBackend',
48+
]
49+
except ImportError:
50+
logger.debug(
51+
'SQLAlchemy or an async DB driver is not installed. If you want to use'
52+
' DatabaseMemoryService please install sqlalchemy and an async driver'
53+
' (e.g. aiosqlite for SQLite). If not, you can ignore this warning.'
54+
)

0 commit comments

Comments
 (0)