Persistent Memory Plugin — Give Your Agent Long-Term Memory Across All Projects

# Persistent Memory Plugin — Give Your Agent Long-Term Memory Across All Projects

Hi Everyone,

## The Problem

Every time you start a new conversation in Antigravity, your agent starts from scratch — it has no memory of past bug fixes, architectural decisions, or project-specific context you’ve already worked through. You end up re-explaining the same things over and over.

## What I Built

A zero-configuration plugin that gives your agent **persistent, searchable memory** across every codebase on your machine. Once installed, your agent can recall past solutions, project conventions, and user preferences from any previous conversation — automatically.

## How It Works

The plugin uses a multi-layered approach:

**1. Proactive Memory (Subconscious)**

Hooked into `PreInvocation` — before your agent even starts generating, it automatically searches your memory database for relevant past context using BM25 ranking and injects it into the conversation. No manual step needed.

**2. Active Recall (Conscious)**

An MCP server exposing two tools your agent can call when it needs memory:

- `search_past_memory(query)` — Full-text search with smart context windowing (extracts surrounding 1000 chars for proper AI context)

- `get_user_profile()` — Consolidated rules/preferences extracted from all past conversations

**3. Memory Harness (ETL Pipeline)**

Runs on the `Stop` hook, scans Antigravity’s brain directory for transcript files, extracts user/assistant messages, and bulk-inserts them into an SQLite FTS5 database with automatic index synchronization via triggers.

**4. Rule Consolidation**

Automatically extracts explicit user instructions (e.g. “always use TypeScript strict mode”, “never use var”) from past conversations and stores them as a persistent user profile.

## Tech Stack

- **SQLite FTS5** — Full-text search with BM25 ranking for fast, relevant memory retrieval

- **FastMCP** — MCP server over stdio transport

- **Google Antigravity Customizations** — `PreInvocation` and `Stop` lifecycle hooks

- **Python 3.10+** — No external dependencies beyond `mcp`

## Installation

### Global Install (recommended — memory shared across all projects)

```bash

git clone GitHub - Shankarsan-Sahoo/persistent-memory-plugin: persistent-memory-plugin · GitHub

cp -r persistent-memory-plugin ~/.gemini/config/plugins/

```

Then add to `~/.gemini/config/plugins.json`:

```json

{

“plugins”: [“persistent-memory”]

}

```

### Workspace Install (memory scoped to one project)

```bash

mkdir -p YourProject/.agents/plugins/

cp -r persistent-memory-plugin YourProject/.agents/plugins/

```

Then add to `YourProject/.agents/plugins.json`:

```json

{

“plugins”: [“persistent-memory”]

}

```

## Example Usage

After installation, your agent automatically:

  1. **Before responding** — searches past conversations for relevant context and injects it into the prompt (proactive memory)

  2. **When asked** — can explicitly search for past solutions, bug fixes, or configurations using `search_past_memory`

  3. **Over time** — builds a consolidated user profile of your preferences and coding conventions

```

You: How do I fix the Docker caching issue in GitHub Actions?

Agent: I remember — we fixed this last time. Here’s the solution…

```

## What’s in the Database

- `conversations` — UUID, workspace path, timestamps

- `messages` — Full transcript data (role, content, timestamp) with FTS5 index

- `user_profile` — Extracted rules and preferences

## Repository

GitHub: GitHub - Shankarsan-Sahoo/persistent-memory-plugin: persistent-memory-plugin · GitHub

## Open Questions

- Has anyone else run into FTS5 column-filter syntax issues with hyphens in queries? I’ve addressed this by tokenizing and quoting terms, but curious if others have hit similar edge cases.

- Would love feedback on the hook-based approach vs. alternative memory architectures.

- Any suggestions for incremental sync optimization? Currently does a full rescan per conversation on each run.

Built by Shankarsan Sahoo. Happy to answer questions or help with setup!