google / google/adk-python-community

feat(memory): add DatabaseMemoryService with SQL backend and agent scratchpad

Abierto
#99 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
182
Forks
75
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

## 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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza leyendo el BaseMemoryService existente y el patrón de DatabaseSessionService en el ADK principal. Revisa el PR #98 y los requisitos para memoria respaldada por SQL, búsqueda conectable, ingestión idempotente y las cuatro herramientas de scratchpad. Se considera terminado cuando los servicios y herramientas propuestos funcionan en los backends asíncronos de SQLAlchemy indicados y ofrecen un comportamiento de memoria duradero.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python, sqlalchemy
Área
backend, database
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.