google / google/adk-python-community
feat(memory): add DatabaseMemoryService with SQL backend and agent scratchpad
- Langage dominant
- Python
- Étoiles
- 182
- Forks
- 75
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
## Feature Request
Add a durable, SQL-backed `DatabaseMemoryService` to `google-adk-community` as a self-hosted alternative to the volatile `InMemoryMemoryService`.
## Problem
The existing `InMemoryMemoryService` is explicitly test-only and loses all data on process restart. Developers not using Vertex AI RAG or Memory Bank have no persistent, self-hosted memory option out of the box.
Related: #46 (Add self-hosted option to manage working memory)
## Proposed Solution
A `DatabaseMemoryService` backed by SQLAlchemy async — the same ORM pattern already used by `DatabaseSessionService` in the core ADK. This enables any SQLAlchemy-compatible async database (SQLite, PostgreSQL, MySQL, MariaDB) as a memory backend.
### Components
- **`DatabaseMemoryService`** — implements `BaseMemoryService` with lazy table creation, idempotent session ingest (`add_session_to_memory`), and delta event ingestion (`add_events_to_memory`)
- **`MemorySearchBackend` ABC + `KeywordSearchBackend`** — pluggable search with LIKE/ILIKE and AND-first → OR-fallback tokenisation
- **Scratchpad subsystem** — KV store + append-only log exposed as four `BaseTool` subclasses (`ScratchpadGetTool`, `ScratchpadSetTool`, `ScratchpadAppendLogTool`, `ScratchpadGetLogTool`) for agent intermediate working memory
### Usage
```python
from google.adk_community.memory import DatabaseMemoryService
from google.adk_community.tools import scratchpad_get_tool, scratchpad_set_tool
# SQLite (zero config)
memory_service = DatabaseMemoryService("sqlite+aiosqlite:///agent_memory.db")
# PostgreSQL
memory_service = DatabaseMemoryService(
"postgresql+asyncpg://user:pass@host/dbname"
)
```
## Origin
This was originally submitted to `google/adk-python` ([#4736](https://github.com/google/adk-python/pull/4736)) and redirected here by maintainer [@rohityan](https://github.com/google/adk-python/pull/4736#issuecomment-2701940819).
## Implementation
PR: #98
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par lire le BaseMemoryService existant et le modèle DatabaseSessionService dans le cœur d’ADK. Examinez la PR #98 ainsi que les exigences relatives à une mémoire basée sur SQL, à une recherche enfichable, à une ingestion idempotente et aux quatre outils de scratchpad. Le travail est considéré comme terminé lorsque les services et outils proposés fonctionnent sur les backends SQLAlchemy asynchrones indiqués avec un comportement de mémoire durable.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python, sqlalchemy
- Domaine
- backend, database
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100