Hardening branch: see runtime setup and audit coverage. Automatic extraction now requires an explicitly configured tool-free chat-completions endpoint. It no longer launches an unrestricted AGY agent. Failed extraction retains pending turns. Schema upgrades run on first engine access; restart all clients together for rollout.
Lightweight SQLite FTS5 dynamic memory layer & MCP server for Google Antigravity (AGY)
Звёзды
35
Инструменты
—
Аптайм
—
Lightweight, high-performance, standalone dynamic cognitive memory layer for Google Antigravity (agy) and autonomous agent frameworks.
Inspired by Hermes Agent's multi-pillar memory architecture, using SQLite FTS5 for ultra-fast local retrieval (<2ms), multilingual compound sub-token decomposition & morphological stemming (DE, EN, FR, IT, ES, NL, SV), relational entity linking, and autonomous background queue workers with calm-memory session debouncing.
🔍 Evolution: From Pure Tokenizer to In-Process Hybrid Search
In version 2.0/2.1, agy-memory-engine deliberately avoided external, resource-heavy vector databases (such as Chroma, Milvus, or Qdrant) and PyTorch bloat (~500MB RAM, 150ms latency) to stay ultra-lightweight.
The limitation of pure keyword / FTS5 search:
Pure FTS5 struggles with vocabulary mismatch: If a user asks in everyday conversational language about "preventing data loss during disk cleanup", while the database stores the heuristic "Deletions of any kind require explicit approval (deletion protection)", pure FTS5 keyword matching returns exactly 0 results.
The solution starting in v2.2.0: In-Process Hybrid Search (sqlite-vec + FastEmbed)
Instead of introducing a heavy server backend, v2.2.0 combines the best of both worlds:
Ultra-fast CLI Prefetch (< 2ms): The synchronous pre-invocation hook remains unchanged on pure FTS5 + trigram decomposition for compound words — zero perceptible latency in chat.
In-Process Vector Extension (sqlite-vec): Runs natively in C directly inside the SQLite process (SIMD-accelerated, zero daemon, zero network hop).
Lightweight Local Embeddings (fastembed): Powered by ONNX Runtime with sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 (384 dimensions, ~9ms inference time, outstanding multilingual semantics).
Reciprocal Rank Fusion (RRF): Mathematically blends BM25 results (100% precision for IPs, IDs, exact names) and vector distance (understanding vague concepts and synonyms).
Automatic Synchronization: Background workers (memory_worker.py) and MCP storage tools index vectors transparently in the background; SQLite cascade triggers handle deletions automatically.
⚡ 5-Minute Quickstart Guide for Newbies
Get up and running from zero to autonomous memory in 5 minutes.
1. Prerequisites & Installation
Clone the repository and install the lightweight Python dependencies (no PyTorch, no heavyweight vector DBs needed):
git clone https://github.com/HydStAn/agy-memory-engine.git
cd agy-memory-engine
# Optional: set up your environment configuration
cp .env.example .env
The database (~/.gemini/memory.db) will be automatically initialized with all FTS5 virtual tables on first run!
2. See Instant Results in the Web Dashboard
The easiest way to see what's happening and test queries is the built-in live dashboard:
# Start the web UI on port 8085
python3 agy_memory.py ui --port 8085
Open http://localhost:8085 in your browser. You can:
Test hybrid multilingual searches in real-time with sub-millisecond metrics.
Visually browse Facts, Episodes, Learnings, and Graph Links.
Monitor pending debounced background tasks.
3. Add Your First Memories via CLI
You can seed your agent's memory directly from the terminal:
# 1. Add an atomic fact (Layer 1)
python3 agy_memory.py add --id "infra.server.ip" --category "infra" --fact "Home server IP is 192.168.1.100" --keywords "home server ip host"
# 2. Add a personal learning / heuristic (Layer 3)
python3 agy_memory.py add-learning --id "workflow.email.style" --category "communication" --insight "Keep email replies strictly under 3 bullet points." --keywords "email communication reply rule"
# 3. Test sub-millisecond prefetch (< 2ms)
python3 agy_memory.py prefetch "server"
4. Hook it up to your Agent (AGY / Claude Code)
Option A: Native MCP Integration (Works with Claude Code, Cursor, AGY)
Add the memory engine as an MCP tool server so your agent can actively search and store knowledge:
# For Claude Code:
claude mcp add memory python3 $(pwd)/agy_memory_mcp.py
# Or in your MCP config JSON (~/.gemini/antigravity-cli/mcp_config.json or Claude Desktop):
{
"mcpServers": {
"memory": {
"command": "python3",
"args": ["/path/to/agy-memory-engine/agy_memory_mcp.py"]
}
}
}
Option B: Configure Agent Prompt / Instructions (GEMINI.md or CLAUDE.md)
Add a simple memory rule to your global agent instructions (e.g. ~/.gemini/config/GEMINI.md, CLAUDE.md, or your project's system prompt) so your agent knows when to query memory:
## Long-Term Memory
- Before answering questions regarding personal preferences, server IPs, hardware, or past projects, call `search_memory` or run `agy_memory.py prefetch "<topic>"`.
- When the user states a new permanent fact or personal rule, persist it using `store_memory` or `record_learning`.
Add the debounced background worker to your crontab (*/5 * * * * python3 /path/to/agy-memory-engine/memory_worker.py).
🚀 CLI Reference & Quick Commands
# Multi-Layer Prefetch (< 2ms)
python3 agy_memory.py prefetch "Hundeversicherung"
# Add Layer 1 Fact
python3 agy_memory.py add --id "infra.server.ip" --category "infra" --fact "Home server IP is 192.168.1.50" --keywords "server host ip home"
# Add Layer 2 Episode
python3 agy_memory.py add-episode --id "travel.iceland2027" --topic "travel" --title "Laugavegur Trekking" --narrative "Hut booking watchdog active for July 2027." --status "active" --keywords "island laugavegur"
# Add Layer 3 Learning
python3 agy_memory.py add-learning --id "travel.flights.cdp" --category "travel" --insight "Use CDP browser for Google Flights to avoid bot-blocking." --keywords "google flights bot cdp"
# Link Entities in Graph
python3 agy_memory.py link --source "service.immich" --target "infra.server.ip" --relation "hosted_on"
# Optimize & Decay Maintenance
python3 agy_memory.py optimize --apply
# Migrate Database from v2.0 to v2.1 (Taxonomies, Relations, Graph Pruning)
python3 agy_memory.py migrate --dry-run
python3 agy_memory.py migrate
🔌 Model Context Protocol (MCP) Server
The engine includes a native FastMCP server (agy_memory_mcp.py) that equips autonomous AI agents (Antigravity, Claude, Cursor, OpenCode) with explicit memory reading and writing capabilities:
Available MCP Tools
Tool
Description
Key Parameters
search_memory
Hybrid multilingual search across Facts, Episodes, Learnings & Graph relations
query(str), limit(int, default: 5)
store_memory
Store or update an atomic configuration parameter or fact (Layer 1)
id, fact, category, keywords
record_episode
Record a rich narrative chronicle, ongoing topic, or history (Layer 2)
id, topic, title, narrative, status, stance
record_learning
Record a practical heuristic, tested rule of thumb, or stance (Layer 3)
id, category, insight, context, keywords
link_entities_mcp
Create directional knowledge graph links between memory entities (Layer 4)
source_id, target_id, relation
list_memories
Full multi-layer inventory export of all stored memories
—
migrate_memory
Migrate database to canonical v2.1 taxonomies, map relations, prune orphans
📱 Mobile User in Telegram (Voice, Text, Photos, Topics)
│
▼
🤖 AGY Telegram Bot (/opt/agy-telegram-bot)
│ (Executes standard agy prompt with --add-dir)
▼
⚡ AGY Global Stop-Hook (~/.gemini/config/hooks.json -> scripts/auto_sync_hook.py)
│ (Enqueues turn in <1ms to turn_queue.db, resolves Telegram topic/chat ID)
▼
🧠 Calm Memory Worker (memory_worker.py)
│ (Debounces 5m idle / 15m timeout, batches conversation into 1 LLM pass)
▼
💾 SQLite FTS5 Memory Store (~/.gemini/memory.db)
│
▼
📲 Instant Status Notification back to Telegram Topic / Chat
"🧠 Autonomous memory updated (1 fact, 1 learning)
• ➕ Home server IP is 192.168.1.50
• ➕ Use CDP browser for Google Flights"
Key Synergy Highlights:
Zero Chat Latency: The global stop-hook returns in < 1ms, ensuring the Telegram Bot responds instantly without waiting for memory extraction.
Context-Aware Topic Routing: The worker automatically preserves the originating Telegram chat_id and message_thread_id, routing notifications directly back into the relevant topic thread.
Loop Prevention: Ingestion runs under AGY_INTERNAL_INVOCATION=1 with prompt marker guards to prevent recursive agent loops.
⚙️ Configuration (.env)
All engine parameters, database locations, LLM model choice, and debounce thresholds can be configured via .env (or environment variables). A ready-to-use template is provided in .env.example:
# Copy template to .env
cp .env.example .env
# ==============================================================================
# AGY Memory Engine - Configuration File
# ==============================================================================
# LLM model used for background memory extraction & consolidation
AGY_MEMORY_MODEL=gemini-3.8-flash-low
# SQLite Database Storage Paths
AGY_MEMORY_DB=~/.gemini/memory.db
AGY_TURN_QUEUE_DB=~/.gemini/turn_queue.db
# Calm-Memory Debounce Settings (in seconds)
AGY_MEMORY_INACTIVITY_SECONDS=300 # 5 minutes idle threshold
AGY_MEMORY_MAX_WAIT_SECONDS=900 # 15 minutes max timeout
# Telegram Notification Recipient (optional: your numeric Telegram user or group ID)
AGY_MEMORY_TELEGRAM_CHAT_ID=your_telegram_chat_id_here
# Path to Antigravity CLI binary
AGY_BIN=agy
# Real-Time Debug Dashboard (Web UI)
AGY_MEMORY_DEBUG_DASHBOARD=true
AGY_MEMORY_DASHBOARD_PORT=8085
AGY_MEMORY_DASHBOARD_HOST=127.0.0.1
# Dashboard Authentication: set custom token or let engine auto-generate in ~/.gemini/dashboard.token
AGY_MEMORY_DASHBOARD_TOKEN=your_secure_dashboard_token_here
# Remote access (VPN, Tailscale, LAN): specify allowed hostnames and private networks
AGY_MEMORY_DASHBOARD_ALLOWED_HOSTS=my-node.ts.net,*.ts.net
AGY_MEMORY_DASHBOARD_ALLOW_PRIVATE_NETWORKS=true
# Optional: trusted OpenAI-compatible chat-completions URL for tool-free HTTP extraction.
# If unset (default), the engine gracefully falls back to native Antigravity CLI (agy --print).
AGY_MEMORY_INFERENCE_URL=
AGY_MEMORY_INFERENCE_MODEL=
AGY_MEMORY_INFERENCE_KEY=
# Jev relevance gate: one evaluation-model call per retrieval drops memory
# candidates that do not serve the request. Fail-open: without a key or on any
# error every candidate is kept. Key falls back to ~/.config/agy/sage.env.
AGY_JEV_API_KEY=
AGY_MEMORY_JEV_GATE=true
AGY_MEMORY_JEV_GATE_FLOOR=0.75
AGY_MEMORY_JEV_GATE_TIMEOUT=6
# Skip the call only when the candidate set is tiny AND short.
AGY_MEMORY_JEV_GATE_MIN_ITEMS=3
AGY_MEMORY_JEV_GATE_MIN_CHARS=600
Jev relevance gate
Retrieval results pass through one evaluation-model call before they reach the agent. Each candidate is scored against the request in a single batched question set; candidates below AGY_MEMORY_JEV_GATE_FLOOR are dropped. This keeps unrelated facts, episodes, and learnings out of the agent context. The gate covers both search_memory and prefetch.
The call is skipped when the candidate set is smaller than AGY_MEMORY_JEV_GATE_MIN_ITEMS and shorter than AGY_MEMORY_JEV_GATE_MIN_CHARS. Many small candidates still get gated. Every failure mode fails open: a missing key, a timeout, or an unparseable answer keeps all candidates.
📊 Real-Time Debug Web Dashboard
A zero-dependency, standalone live web dashboard is included to inspect, search, and monitor memory state in real time:
Live FTS5 Search Sandbox: Test hybrid multilingual queries with sub-millisecond latency metrics.
High-Performance Architecture: Transparent Gzip compression (~67% payload reduction), locally bundled deferred assets (vis-network), and lazy tab rendering for instant mobile & desktop loads.
Interactive Knowledge Graph (vis.js): Real-time interactive network graph visualization of entity relations with cluster domain filtering, relation-type pruning, and node physics.
Turn Queue & Debounce Monitor: Visual countdown bar for active conversation debouncing (5m idle / 15m timeout) with an instant "Process batch now" trigger.
4-Layer Visualizer: Browse Facts (Layer 1), Thematic Episodes with status badges (Layer 2), Experiential Learnings (Layer 3), and Knowledge Graph Entity Links (Layer 4).
Consolidation Audit Log & Opt-In Control: Review automated background merges, deduplications, and semantic rationale, with optional LLM semantic consolidation checkbox in optimization modal.
Engine Status & Version Control: Live git commit SHA, message display, and one-click engine restart button in the header.
Multi-User Profile Switcher: Seamlessly switch between configured user profiles on the host via the header dropdown.
Authentication & Token Security
The dashboard is protected by authentication tokens for all viewing and mutation endpoints:
Auto-Generated Token (Default):
On first start, the dashboard generates a 256-bit secure token stored in ~/.gemini/dashboard.token (permissions 0600, user-only).
Explicit Token via .env:
You can specify your own token in .env via AGY_MEMORY_DASHBOARD_TOKEN=your-secret-token.
Browser Access:
Append ?token=<your_token> to the URL on your first visit:
http://localhost:8085/?token=your_secure_dashboard_token_here
# Or over Tailscale:
https://<your-tailscale-node>.ts.net:8085/?token=your_secure_dashboard_token_here
The token is saved in browser localStorage, so subsequent reloads and visits do not require re-entering it.
API Requests:
Pass the header Authorization: Bearer <your_token>.
Starting the Dashboard
# Via CLI command
python3 agy_memory.py ui --port 8085
# Or directly via standalone runner
python3 dashboard.py --port 8085
# Or via systemd background user service
systemctl --user start agy-memory-dashboard.service
Integrated consolidate_learnings() directly into optimize_db(), enabling seamless, automated consolidation during nightly maintenance (04:30 Uhr via cron) and autonomous worker cycles.
Automatically deduplicates overlapping heuristics and purges transient bugfix and single-PR notes alongside atomic facts.
Extended Ephemeral Fact Lifecycle & Pruning:
Upgraded prune_stale_calendar_facts() into a unified ephemeral fact lifecycle engine.
Detects transient transaction and travel facts (%.flug_%, %.hotel_%, %.hammam_%, %.rueckreise_%, shopping.%order_%) with past dates (>14 days grace window) and automatically purges them, preventing fact-store dilution while strictly preserving long-term dates (medical, contracts, future bookings).
Event-Triggered Learning Extraction Refinement:
Tightened turn extraction criteria in agy_memory.py to 3 core triggers (user corrections, explicit rules/heuristics, and stable personal preferences), eliminating routine technical debugging noise.
Self-Healing Quality Watchdog Architecture:
Refactored watchdog_memory_learnings.py to measure incoming learning noise dynamically against the latest consolidation_log timestamp.
Automated autonomous background consolidation triggering when threshold (>15 new items) is reached, replacing manual CLI intervention prompts.
Dashboard & Environment Security Hardening:
Ensured correct precedence for ~/.gemini/memory.env overrides over project defaults.
Hardened authenticated HTML responses and preserved security headers.
v2.5.0 (2026-09-29)
Domain Taxonomy Expansion & De-concentration:
Expanded CANONICAL_LEARNING_CATEGORIES with dedicated domains: ux, dev, infra, and media, relieving the catch-all architecture bucket.
Re-mapped generic related_to links across system configurations, user profiles, projects, and media pipelines (reducing related_to density by >43%).
Adaptive Batched Semantic Memory Consolidation:
Refactored consolidate_memories from monolithic single-prompt serialization (which previously exceeded CLI subprocess payload and timeout limits on large stores) into category-chunked batches (≤ 25 facts per inference call).
Maintained single-pass backward compatibility for small databases and mocked unit tests.
FTS5 & Trigram Index Integrity:
Automated continuous SQLite triggers (trg_memories_trigram_ai/au/ad) to keep the substring trigram virtual table synchronized with memories.
Added memories_trigram maintenance to the routine rebuild_fts workflow in optimize_db.
Retrieval & Ingestion Hardening:
Decoupled static persistent preferences and safety guardrails from graph expansion to guarantee deterministic zero-hop system prompt injection.
Hardened automated calendar fact pruning and point-in-time episode lifecycle resolution.
v2.4.0 (2026-09-21)
Vector Index Synchronization & Outbox Architecture:
Self-healing vector synchronization with vector_index_jobs, vector_index_state, and vector_index_config (schema version 212).
Decoupled embedding computation from SQLite write transactions; atomic revision tracking and job enqueueing via database triggers.
Generational fencing, revision fencing, and lease tracking preventing race conditions during background vector draining.
Atomic batch claims with durable batch receipts and recoverable expiring leases in turn_queue.db.
Concurrency hardening: serialized schema bootstrap, entity revision tracking, and generation fencing preventing stale overwrites across restores.
Native agy --print CLI fallback for tool-free background inference when AGY_MEMORY_INFERENCE_URL is unset, with automatic markdown extraction and slash-command retry.
Multi-user dashboard and permission resilience: shared maintenance lock (LOCK_SH) allowing seamless cross-user profile inspection between multiple Linux user profiles.
Tolerant entity graph linking: invalid or unresolvable relationship endpoints are skipped with warnings instead of rolling back the entire extraction transaction (AGY_MEMORY_STRICT_GRAPH=false).
First-turn Telegram routing: in-flight session resolution in scripts/auto_sync_hook.py ensuring immediate chat attribution from the very first message.
Bounded MCP maintenance offloading to a single background worker thread to keep the event loop responsive.
Strict litmust test and exclusion rules for experiential learnings (no transient bug fixes, UI tweaks or code-internal details; strictly reusable heuristics and behavioral insights).
Списка инструментов пока нет. У удалённых серверов он появляется после первой проверки состояния.
FAQ
Вопросы
Как установить Agy Memory Engine?
Скопируйте на этой странице конфигурацию stdio для Cursor, Claude Desktop, Claude Code или VS Code. Она использует установку издателя, а не прокси PlugMCP.
Нужен ли API-ключ для Agy Memory Engine?
В этой записи не указано обязательных переменных окружения.
Какой транспорт использует Agy Memory Engine?
Agy Memory Engine работает локально через stdio.
Когда Agy Memory Engine проверялся в последний раз?
Последняя проверка: 2026-10-28. Lightweight SQLite FTS5 dynamic memory layer & MCP server for Google Antigravity (AGY)