Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
<svg xmlns="http://www.w3.org/2000/svg" width="1400" height="920" viewBox="0 0 1400 920" role="img" aria-labelledby="title desc">
<title id="title">ai-memory architecture overview</title>
<desc id="desc">A diagram showing agent clients sending lifecycle hooks and MCP calls into ai-memory serve, which routes through hook, MCP, web, admin, scope, auth, writer, read pool, markdown wiki, SQLite index, scheduled auto-improvement and maintenance jobs, and optional LLM and embedding providers.</desc>
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#334155" />
</marker>
<marker id="arrow-blue" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#2563eb" />
</marker>
<marker id="arrow-green" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#15803d" />
</marker>
<style>
.canvas { fill: #f8fafc; }
.title { font: 700 30px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #0f172a; }
.subtitle { font: 500 15px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #475569; }
.group-label { font: 700 16px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #334155; letter-spacing: .02em; }
.box-title { font: 700 17px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #0f172a; }
.box-text { font: 500 13px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #334155; }
.small { font: 500 12px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #475569; }
.client { fill: #ffffff; stroke: #cbd5e1; stroke-width: 1.5; rx: 16; }
.server { fill: #eef2ff; stroke: #818cf8; stroke-width: 2; rx: 22; }
.route { fill: #ffffff; stroke: #a5b4fc; stroke-width: 1.5; rx: 14; }
.boundary { fill: #fef3c7; stroke: #f59e0b; stroke-width: 1.5; rx: 14; }
.writer { fill: #dcfce7; stroke: #22c55e; stroke-width: 1.5; rx: 14; }
.reader { fill: #dbeafe; stroke: #3b82f6; stroke-width: 1.5; rx: 14; }
.job { fill: #f5f3ff; stroke: #8b5cf6; stroke-width: 1.5; rx: 14; }
.store { fill: #ffffff; stroke: #64748b; stroke-width: 1.5; rx: 16; }
.external { fill: #fff7ed; stroke: #fb923c; stroke-width: 1.5; rx: 16; }
.arrow { fill: none; stroke: #334155; stroke-width: 2.2; marker-end: url(#arrow); }
.arrow-blue { fill: none; stroke: #2563eb; stroke-width: 2.2; marker-end: url(#arrow-blue); }
.arrow-green { fill: none; stroke: #15803d; stroke-width: 2.2; marker-end: url(#arrow-green); }
.arrow-dashed { fill: none; stroke: #64748b; stroke-width: 2; stroke-dasharray: 7 6; marker-end: url(#arrow); }
</style>
</defs>
<rect class="canvas" x="0" y="0" width="1400" height="920" />
<text class="title" x="700" y="48" text-anchor="middle">ai-memory architecture overview</text>
<text class="subtitle" x="700" y="76" text-anchor="middle">Hooks capture automatically; markdown is the source of truth; SQLite is the derived search/index layer.</text>
<text class="group-label" x="70" y="112">CLIENTS</text>
<rect class="client" x="60" y="130" width="290" height="118" />
<text class="box-title" x="85" y="164">Agent CLIs</text>
<text class="box-text" x="85" y="190">Claude Code, Codex, OpenCode</text>
<text class="box-text" x="85" y="211">Cursor, Gemini, Antigravity</text>
<text class="box-text" x="85" y="232">Grok, OpenClaw, OMP</text>
<rect class="client" x="390" y="130" width="290" height="118" />
<text class="box-title" x="415" y="164">Terminal and automation</text>
<text class="box-text" x="415" y="190">ai-memory CLI thin clients</text>
<text class="box-text" x="415" y="211">bootstrap, search, backup</text>
<text class="box-text" x="415" y="232">lint, embed, forget-sweep</text>
<rect class="client" x="720" y="130" width="290" height="118" />
<text class="box-title" x="745" y="164">Browser and API clients</text>
<text class="box-text" x="745" y="190">/web wiki browser</text>
<text class="box-text" x="745" y="211">/admin operator routes</text>
<text class="box-text" x="745" y="232">/api/v1 integration surface</text>
<rect class="external" x="1050" y="130" width="290" height="118" />
<text class="box-title" x="1075" y="164">Optional providers</text>
<text class="box-text" x="1075" y="190">LLM consolidation and lint</text>
<text class="box-text" x="1075" y="211">scheduled review + approval</text>
<text class="box-text" x="1075" y="232">embedding vector backfill</text>
<rect class="server" x="60" y="300" width="1280" height="390" />
<text class="group-label" x="90" y="335">ai-memory serve - one Rust binary</text>
<rect class="route" x="100" y="365" width="235" height="100" />
<text class="box-title" x="125" y="397">/hook router</text>
<text class="box-text" x="125" y="423">fire-and-forget capture</text>
<text class="box-text" x="125" y="444">sanitizes hook payloads</text>
<rect class="route" x="375" y="365" width="235" height="100" />
<text class="box-title" x="400" y="397">MCP server</text>
<text class="box-text" x="400" y="423">stdio and HTTP /mcp</text>
<text class="box-text" x="400" y="444">memory_query, handoff, etc.</text>
<rect class="route" x="650" y="365" width="235" height="100" />
<text class="box-title" x="675" y="397">Web, admin, API</text>
<text class="box-text" x="675" y="423">wiki UI and operator routes</text>
<text class="box-text" x="675" y="444">HTTP API integrations</text>
<rect class="boundary" x="925" y="365" width="360" height="100" />
<text class="box-title" x="950" y="397">Scope, auth, admission</text>
<text class="box-text" x="950" y="423">workspace/project resolution</text>
<text class="box-text" x="950" y="444">capability gates + webhooks</text>
<rect class="writer" x="150" y="535" width="345" height="110" />
<text class="box-title" x="175" y="568">Writer actor</text>
<text class="box-text" x="175" y="594">single mpsc queue, one rusqlite writer</text>
<text class="box-text" x="175" y="615">WAL mode, batch transactions</text>
<rect class="reader" x="555" y="535" width="345" height="110" />
<text class="box-title" x="580" y="568">Read pool and retrieval</text>
<text class="box-text" x="580" y="594">FTS5 + entity + graph RRF</text>
<text class="box-text" x="580" y="615">optional vector + authority + raw fallback</text>
<rect class="job" x="960" y="535" width="300" height="110" />
<text class="box-title" x="985" y="568">Lifecycle and scheduled jobs</text>
<text class="box-text" x="985" y="594">session summary + handoff</text>
<text class="box-text" x="985" y="615">auto-improve scheduler</text>
<text class="box-text" x="985" y="636">consolidate, lint, embed, sweep</text>
<text class="group-label" x="70" y="735">DURABLE STATE</text>
<rect class="store" x="105" y="755" width="350" height="120" />
<text class="box-title" x="130" y="789">Markdown wiki</text>
<text class="box-text" x="130" y="815">source of truth on disk</text>
<text class="box-text" x="130" y="836">git commits, restore-page</text>
<text class="box-text" x="130" y="857">editable by humans/tools</text>
<rect class="store" x="525" y="755" width="350" height="120" />
<text class="box-title" x="550" y="789">SQLite memory.sqlite</text>
<text class="box-text" x="550" y="815">derived index and audit store</text>
<text class="box-text" x="550" y="836">pages, sessions, observations</text>
<text class="box-text" x="550" y="857">FTS5, handoffs, embeddings</text>
<rect class="store" x="945" y="755" width="350" height="120" />
<text class="box-title" x="970" y="789">Backups and checkpoints</text>
<text class="box-text" x="970" y="815">SQLite online backup</text>
<text class="box-text" x="970" y="836">wiki git checkpoints</text>
<text class="box-text" x="970" y="857">rsync or tarball restore</text>
<path class="arrow-blue" d="M 205 248 C 205 280 205 320 205 365" />
<text class="small" x="105" y="287">lifecycle hooks POST /hook</text>
<path class="arrow-blue" d="M 260 248 C 320 290 410 320 492 365" />
<text class="small" x="370" y="308">MCP stdio or HTTP</text>
<path class="arrow-blue" d="M 535 248 C 590 292 660 320 735 365" />
<text class="small" x="553" y="286">CLI HTTP calls</text>
<path class="arrow-blue" d="M 865 248 C 865 295 800 320 768 365" />
<text class="small" x="805" y="287">browser/API HTTP</text>
<path class="arrow" d="M 335 415 L 375 415" />
<path class="arrow" d="M 610 415 L 650 415" />
<path class="arrow" d="M 885 415 L 925 415" />
<text class="small" x="936" y="488">authorized write/read requests</text>
<path class="arrow-green" d="M 1040 465 C 910 515 610 500 495 560" />
<path class="arrow-blue" d="M 1110 465 C 1040 520 940 520 900 570" />
<path class="arrow-green" d="M 323 645 C 300 690 285 720 280 755" />
<path class="arrow-green" d="M 405 645 C 500 700 615 710 700 755" />
<path class="arrow-blue" d="M 700 755 C 705 715 715 680 728 645" />
<path class="arrow-blue" d="M 600 645 C 505 700 380 714 285 755" />
<path class="arrow-dashed" d="M 455 810 C 490 775 500 775 525 810" />
<text class="small" x="458" y="747">watcher reconciliation</text>
<path class="arrow" d="M 1100 645 C 1090 700 1110 720 1120 755" />
<path class="arrow" d="M 455 835 C 620 895 780 895 945 835" />
<path class="arrow" d="M 875 835 C 900 835 920 835 945 835" />
<path class="arrow-dashed" d="M 1195 535 C 1240 445 1240 330 1195 248" />
<text class="small" x="1212" y="388">LLM and embedding calls</text>
<text class="small" x="70" y="900">Solid arrows show request, read, and write paths. Dashed arrows show background reconciliation or provider-backed maintenance.</text>
</svg>