google / google/adk-python-community
feat(memory): add DatabaseMemoryService with SQL backend and agent scratchpad
- Ngôn ngữ chính
- Python
- Star
- 182
- Fork
- 75
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
## 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
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách đọc BaseMemoryService hiện có và pattern của DatabaseSessionService trong ADK core. Xem lại PR #98 và các yêu cầu đối với bộ nhớ được hỗ trợ bởi SQL, khả năng tìm kiếm có thể cắm, việc nạp dữ liệu idempotent và bốn công cụ scratchpad. Được xem là hoàn thành khi các service và công cụ được đề xuất hoạt động trên các backend SQLAlchemy async đã nêu với hành vi bộ nhớ bền vững.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python, sqlalchemy
- Lĩnh vực
- backend, database
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100