agy-memory
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
agy-memory is a lightweight, local-first compaction guard and lossless session memory layer for Google Antigravity (Antigravity 2.0 / agy CLI).
It runs on 100% Python standard library + local SQLite WAL/FTS5 (including its built-in stdio JSON-RPC 2.0 MCP server) — zero third-party runtime dependencies, zero external LLM API keys, zero cloud accounts, zero background worker daemons.
Why agy-memory?
Auditing 19 automatic compactions across 4 long-horizon production sessions (13 main compactions + 6 subagent compactions) in Antigravity revealed four structural failure modes in native CHECKPOINT compaction:
Observed Failure Mode (19 Native Auto-Compactions) | Measured Baseline | Root Cause in Native | How |
1. Hard 10-turn user-request eviction | 100% of sessions > 10 turns dropped earlier verbatim requests |
| Incremental byte-offset SQLite ledger preserves all turns and prioritizes evicted declarative constraints |
2. Complete loss of assistant replies |
| Native | Captures final user-facing replies ( |
3. Sudden 500k compaction without | Main compactions fired at median | Antigravity hooks ( |
|
4. Post-compaction path hallucinations & re-read storms | Up to | Summarizer flattens directory trees and drops verified file paths | Tracks every |
5. Dead cross-session recall | Native | No built-in MCP search tool over local transcripts or structured decisions | Exposes 8 stdio MCP tools querying both |
Related MCP server: KusiScribe Core
Architecture
flowchart LR
subgraph AGY["Google Antigravity Runtime"]
T["transcript.jsonl / transcript_full.jsonl"]
H["hooks.json (PreInvocation, Stop)"]
S["conversation_summaries.db (Native FTS5)"]
end
subgraph GUARD["agy-memory Hook (stdlib only)"]
P["Incremental O(delta) Parser"]
D["Subagent Detector (step 0 != USER_INPUT)"]
R["Bounded Recovery Builder (<= 3.7k chars)"]
end
subgraph DB["Local SQLite WAL + FTS5 (agy_memory.db)"]
L1["Thread-Private Layer: sessions, session_directives, session_files, session:<cid>"]
L2["Shared Layer: workspace/global decisions (7-14d TTL + conflict check)"]
end
subgraph MCP["agy-memory Stdio MCP Server (8 Tools)"]
M1["pin_decision / list_decisions / retire_decision"]
M2["search_sessions / get_session_brief"]
M3["search_transcript / get_transcript_steps / memory_status"]
end
T -->|"byte-offset seek"| P
H --> P
P --> D
P --> L1
D -->|"main session only"| R
L1 --> R
L2 --> R
R -->|"injectSteps.systemMessage (deduped 1x)"| H
L1 <--> M1
L2 <--> M1
S -->|"read-only JOIN"| M2
T -->|"verbatim lookup"| M3Anti-Dilution & Anti-Staleness Design
Memory systems frequently hurt agent quality when they blindly dump text into the prompt. agy-memory enforces five explicit guardrails:
Strict Scope Separation (
session:<cid>vs. Workspace vs. Global)Thread-private (
scope="session", requiresconversation_id): restored only when that specific thread compacts. Never leaks into parallel threads working in the same repository.Workspace shared (
scope="/path/to/repo"): holds only incremental architecture locks or vetoes not already written inGEMINI.md/AGENTS.md.
Zero Subagent Pollution
Detects subagents deterministically from
step 0(type != USER_INPUT). Subagents receive{}(0bytes) on startup and only verified touched file paths (plus their own private pins, if any) if they compact.
Automatic TTL Decay & Conflict Detection
Decisions expire from automatic injection after 14 days (
veto/architecture/preference) or 7 days (decision/lesson), remaining searchable on demand viasearch_sessions.Every injected item carries an explicit age tag (
[2026-11-25·today]) and a top priority guardrail (later user instructions always override earlier memory).pin_decisionscans active same-scope entries and returnspotential_conflictsso superseded rules can be retired immediately viaretire_decision.
Question Filtering on Auto-Extraction
Interrogative user turns (
?,Why...,能不能...,...吗) are excluded from declarative constraint extraction.
Hard Byte Budgets & One-Time Deduplication
Normal non-compaction turns return
{}(0 bytes injected, prompt cache untouched).Post-compaction recovery fires at most once per
CHECKPOINTstep and replaces verbose full-file handoff dumps with a compact<= 3.7kcharacter packet.
Benchmarks
All numbers below are freshly measured with the included anonymized, self-contained benchmark fixture (625 steps, 24 user turns reaching 508k tokens, 1 main compaction + parallel thread + subagent). Run it yourself:
python benchmarks/run_benchmark.pyMetric | Measured Result | Notes |
Steady-state | 1.67 ms | Median over 10 runs ( |
Steady-state | 107.68 ms | Includes OS process + Python startup; returns |
Main session cold-start injection | 537 chars ( | Incremental workspace decisions only; no |
Subagent cold-start injection | 0 chars ( | Deterministic |
430k silent pre-compaction checkpoint | 504 chars ( | Silently saves unsaved specs before ~500k; never prompts user to |
Post-compaction recovery packet | 3,700 chars ( | Bounded size; fired once per |
Recent Q&A assistant reply recall | 3 / 3 (100%) | Recovers options & conclusions wiped by native |
Evicted early veto recall (> 10 turns ago) | 2 / 2 (100%) | Prioritizes declarative constraints over routine turns |
Thread-private pin recovered on own compaction | Yes ( |
|
Cross-thread leakage to parallel Thread B | 0 ( | Thread B in same workspace sees 0 bytes of Thread A's private pin |
Live production observation (anonymized): In real daily Antigravity 2.0 usage on Windows,
Stopsync events complete in4.2–41 ms, subagent startup skips complete in~5.0 ms, and pre-compaction checkpoint hooks trigger cleanly in~41.8 ms.
Quick Start
1. Install
Requires Python 3.11+ (SQLite FTS5 is bundled with standard Python).
git clone https://github.com/JieX133/agy-memory.git
cd agy-memory
pip install -e .2. Wire Hooks and MCP Server
# Registers PreInvocation/Stop hooks in ~/.gemini/config/hooks.json (with automatic backup)
# and registers agy-memory in ~/.agent-runtime/mcp/mcp.json (if present) or ~/.gemini/config/mcp_config.json
agy-memory installOptions:
--hooks-only— register lifecycle hooks only (if you manage MCP configs manually)--mcp-config /path/to/mcp.json— target a specific MCP config file--lang zh— emit Chinese headers in injected recovery packets (default:en)agy-memory doctor— verify Python, SQLite FTS5,mcpSDK, hook wiring, and recent hook timingsagy-memory uninstall— cleanly remove entries (keeping backups)
3. Optional Global Rule Snippet (~/.gemini/GEMINI.md)
Add these 4 lines so your agent uses the MCP tools proactively:
## Session Memory & Compaction Discipline
- Pin thread-local specs with `pin_decision(scope="session", conversation_id="<cid>")`; pin durable cross-thread workspace decisions (not already in `GEMINI.md`/`AGENTS.md`) with workspace `scope`. Retire superseded IDs via `retire_decision`.
- On `[Memory Guard | Pre-Compaction Checkpoint]`, do NOT ask the user to compact early; silently pin any unsaved specs/decisions before native ~500k compaction occurs.
- On `[Memory Guard | Post-Compaction Recovery]`, obey verified file paths and call `search_transcript` / `get_transcript_steps` whenever exact pre-compaction text is needed.
- To recall prior conversations without pasting UUIDs, call `search_sessions` / `get_session_brief`.Environment Variables
Variable | Default | Description |
|
| Directory storing |
|
| Explicit SQLite DB path override |
|
| Antigravity transcripts root |
|
| Native Antigravity FTS5 summaries DB |
|
| Token threshold for silent pre-compaction checkpoint reminder (never nudges early |
|
| Injected packet header language ( |
MCP Tools
Tool | Purpose |
| Save/update a |
| Inspect active decisions (workspace queries never expose |
| Deactivate an outdated or superseded decision |
| Full-text search across Antigravity's native |
| Structured brief of any session: all user requests (uncapped), compaction steps, modified files, and tail turns |
| Lossless verbatim grep over |
| Bounded verbatim step expansion (pair with |
| Store counters, expired decision count, and last 15 hook execution latencies |
Trade-offs & Limitations
Cannot prevent native prompt-cache resets on compaction:
agy-memoryoperates through Antigravity's public hook API; when Antigravity runs native compaction at ~500k tokens, prompt cache invalidation is internal to the host runtime. Pairingagy-memorywith a tool-output sandbox (such ascontext-modeMCP) helps delay hitting 500k in the first place.Python subprocess overhead:
PreInvocationruns synchronously in Antigravity. While SQLite incremental parsing takes~1.7 ms, spawning Python adds~90–110 msper turn on Windows (negligible relative to multi-second model turns, but worth noting).Deterministic reply distillation: Assistant replies longer than 320 characters are distilled heuristically (lead line + headings + bold/numbered options) without calling an external LLM. Large tables or full code snippets require one on-demand
get_transcript_steps(cid, step, step)call.No automatic semantic contradiction resolution: If you verbally reverse a pinned decision during its 7–14 day TTL and the agent forgets to call
retire_decision, the old entry stays in the prefix until expiry (mitigated by age tags and the top override rule, not eliminated 100%).
Development & Testing
pip install -e ".[dev]"
pytest -v
python benchmarks/run_benchmark.pyLicense
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Cross-tool persistent memory and context for AI assistants over MCP.
Persistent personal memory for AI assistants — save, search, and recall across every MCP client.
Persistent, verbatim, searchable memory for AI assistants — one memory across every MCP client.
Persistent AI memory shared across Claude, ChatGPT, coding agents, and compatible MCP clients.
Related MCP Servers
AlicenseNot gradedqualityCmaintenanceEnables AI agents to capture, search, and manage structured memory from agent sessions with append-only events and provenance tracking, providing eight local MCP stdio tools.1Apache 2.0- AlicenseNot gradedqualityCmaintenanceEnables autonomous multi-agent workflows to capture, preserve, and retrieve immutable transcripts and atomic memory cards through a local MCP server, providing tools for forensic search, topic mapping, and structured fact access without losing context fidelity.1MIT
- AlicenseNot gradedqualityBmaintenanceGives Google Antigravity persistent memory by automatically recalling profile and project context before model calls and saving new conversation turns at turn boundaries. Exposes MCP tools to add, search, list, profile, and forget memories, with privacy filtering and per-repository scoping.1MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to maintain local-first continuity memory by starting sessions with prior context, capturing durable preferences and decisions, recalling and correcting memories, and leaving handoffs for future sessions. It provides eleven MCP tools backed by local SQLite, with optional maintenance and reflection workflows that keep memory scoped to the agent’s relationship with the user.169 PyPI191Apache 2.0