google / google/adk-python-community
feat(memory): add DatabaseMemoryService with SQL backend and agent scratchpad
- 主要言語
- Python
- スター
- 182
- フォーク
- 75
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
## 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
コントリビューションガイド
調査の方向性
まず、既存の BaseMemoryService と、コア ADK における DatabaseSessionService のパターンを読んでください。PR #98 と、SQL バックのメモリ、 pluggable search、冪等な取り込み、および 4 つの scratchpad ツールに関する要件を確認してください。提案されたサービスとツールが、指定された SQLAlchemy async バックエンド全体で、永続的なメモリ動作を伴って機能すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python, sqlalchemy
- 領域
- backend, database
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100