Dev.to · 3 min read

How to Give Your AI Coding Agent Infinite Memory

How to Give Your AI Coding Agent Infinite Memory

Stop blowing context windows on historical chat logs. Index your agent's local session tapes with FastMCP and SQLite FTS5 for sub-10ms recall. The Problem AI coding agents are stateless. Once a session closes, the context window resets, and the agent forgets every architectural trade-off, rejected alternative, and subtle debugging edge case you worked through. Cramming 100k-token transcripts into prompt context causes latency spikes, attention dilution, and cost bloat. Naive automated summaries strip away the exact chronological rationale and specific trade-offs you actually need. The Fix Don't stuff context. Index your past trajectories locally and let the agent query them on demand. Think of it as giving your agent an active retrieval reflex instead of asking it to carry its entire life history in working memory. By connecting a lightweight FastMCP server to an embedded SQLite FTS5 database, the agent can search its own historical conversations in sub-10ms and pull exact past decisions using fewer than 120 tokens. The Architecture ~/.gemini/antigravity/brain/ │ [/transcript.jsonl] │ ▼ ┌───────────────────────────────────────┐ │ Incremental MTime Parser │ │ (Filters noise, diffs & shell stdout) │ └───────────────────┬───────────────────┘ │ ▼ ┌───────────────────────────────────────┐ │ SQLite + FTS5 BM25 Engine │ │ (conversations.db — local keyword FTS)│ └───────────────────┬───────────────────┘ │ ▼ ┌───────────────────────────────────────┐ │ FastMCP Server (stdio transport) │ │ (Exposes search tools to the agent) │ └───────────────────┬───────────────────┘ │ ▼ [ Antigravity Agent ] How to Build It 1. Configure at the Global MCP Tier In Google Antigravity, place the server in your global configuration (~/.gemini/config/mcp_config.json), rather than the scoped workspace config (.agents/mcp_config.json). Why: The agent gains cross-project memory across all branches, repositories, and writing workspaces without dragging unrelated source code or context into the active project tree. 2. Filter the Noise Before Indexing Raw agent transcripts (transcript.jsonl) contain megabytes of raw terminal output, file overwrite diffs, and status pings. Blindly indexing this breaks BM25 search relevance. The ingestion parser applies three strict filters: Index only discourse: Captures USER_INPUT (steering/prompts) and PLANNER_RESPONSE (reasoning/decisions). Discards binary payloads, file scrapes, and transient tool poll steps. Truncate tool bloat: Strips multi-thousand-line stdout outputs. Indexes only the tool name and target file reference (e.g., write_to_file: target.py). Clamp content length: Enforces a hard ceiling (MAX_CONTENT_CHARS = 10_000) on individual messages to prevent catastrophic index bloat. 3. Index with SQLite FTS5 Store records in a local SQLite virtual table using FTS5, Porter stemming, and Unicode-61 tokenization. An mtime cache tracks file modification timestamps so incremental re-indexing across dozens of sessions takes less than 20 milliseconds. 4. Expose the Search Tools The FastMCP server exposes two primary tools over stdio: search_antigravity_conversations(query="..."): Returns BM25-ranked matches with conversation IDs, timestamps, and highlighted snippets. get_antigravity_step(conversation_id, step_index): Pulls the surrounding dialogue window for full contextual fidelity. The Result in Practice When the agent hits friction, needs historical context, or conducts a post-mortem on earlier decisions, it calls the MCP tool directly: search_antigravity_conversations(query="Observer Stance negative assertions") Instead of guessing or re-reading giant raw files, SQLite returns the exact turn where the decision was made: [Match 1 | Session: 8f2a-e1... | Date: 2026-09-02 14:18] Role: PLANNER_RESPONSE Snippet: "...decided to cut redundant negative assertions from Chapter 1. The observer stance works best when physical actions imply boundaries rather than explicitly stating what didn't happen..." Query Latency: 99.8% reduction vs. reading raw transcripts) Grab the Code The complete implementation is open source on GitHub: 👉 Memory Server: github.com/kingjulian24/search-antigravity Stop starting from scratch every time you open a terminal. Let your agent inspect the tape.

This is a summary aggregated from Dev.to. Read the complete article on the original site:

Read full article at Dev.to

More AI & Machine Learning News