Memory + execution-state layer for AI coding agents — and the KV store behind focus-llama. The engine decides what leaves and what comes back; FocusMemory remembers what was there.
Plug FocusMemory into qwen-code with a single manifest file. Nine MCP tools, an auto-recall HTTP hook, and Hard Gate search rules — all loaded automatically on startup. No fork, no patch.
Learn more →Grep finds the code. Vectors find the meaning. Neither remembers why it's still that way.
Every session re-discovers the same files, re-reasons about the same architecture, from scratch — round-trips accumulate, context gets re-injected, tokens burn.
What the code assumes about your database and what's actually running diverge — and nothing catches it until something breaks.
Why a column was added, why a threshold was chosen — buried in a chat log that's gone the moment the session ends.
focus-llama is a llama.cpp fork that owns the inference side — KV eviction, re-prefill, attention control. FocusMemory is its durable memory backend: project knowledge, structured execution state, and a verbatim store for evicted context.
| Concern | focus-llama · inference engine | FocusMemory · memory layer |
|---|---|---|
| KV cache | Decides which messages to evict, cuts their KV, re-prefills on focus | Dumb store — returns evicted text verbatim; no chunking, embedding, or search |
| Declarative attention | --da-prompt-scan recovers the layout; re-prefills the recalled chunks |
Emits [[da:N]] magic-chunk markers + the focus retrieval tool |
| Execution state (Σ) | — stays in the engine's context | Extracts a structured state patch pre-compaction, re-injects it post-compaction |
| Project knowledge | — | Qdrant + Meilisearch + tree-sitter AST graph — durable, context-window-independent |
Not "just a search RAG" — four pillars cover the full memory contract between the inference engine and the agent.
Numbered magic-chunk markers let the model name exactly which recalled chunks it wants in context — lossless recall by name, not re-derivation.
Structured execution state extracted pre-compaction, re-injected post-compaction — the agent resumes from explicit state, not a lossy prose summary.
Durable project knowledge — semantic search, causal decision chains, code graph, task memory. Independent of the context window.
A dumb per-session verbatim store for evicted context — the lossless-recall backend behind focus-llama's --fm-offload.
The bridge between the memory and KV-store pillars: a lossless-recall mechanism that lets the model pull back specific evicted chunks by name instead of re-deriving them.
Gated by FOCUSMEMORY_DA=on: search results wrapped in numbered [[da:N]] magic-chunk markers (per-session monotonic), a [[da:filler]] placeholder, a [[da:layout:N]] footer, and a versioned signature. Cap: 5 chunks × 300 chars.
Launched with --da-prompt-scan, which recovers the layout from the rendered prompt. The model then emits <focus magic_chunks="N"> to restrict attention to, or recall, specific chunks.
The retrieval-side DA primitive. Two-stage: a cheap index scan, then fetch the full original chunk by point_id UUID or file_path + entity_name.
Long sessions get compacted into a lossy prose summary. SKILL.state extracts a structured state patch (Σ) from the pre-compaction transcript and re-injects it after compaction — the agent resumes from explicit state.
Records context size and spawns a detached extraction worker on either trigger: a state change (a mutating tool call since the last extraction — mechanical, no LLM in the hook) or context growth (50k+ tokens past the last extraction, for prose-only drift).
Spawns the same worker as a final pass and exits in milliseconds — native compaction is never blocked. The worker calls the extraction LLM, merges (Σₜ₊₁ = Σₜ ⊕ Δ; null deletes a key), and dual-writes a work_memory checkpoint.
Injects a one-line state anchor (task | step | pending | files | failing checks) once context passes the threshold — no LLM call, millisecond-scale. After compaction, Σ is loaded as additionalContext.
task_summary · current_step · pending_checks — replace | files_touched · decisions — union (capped 50) | tests_status — merge
Qdrant collections + Meilisearch full-text + a tree-sitter AST graph. Source code structure, work history, and task memory as a single shared memory — eliminating grep/glob, cold boot, and re-derivation.
Function graph via tree-sitter AST + semantic search over code chunks. The agent recalls "who calls X" without re-reading the file tree.
Decisions, bug fixes, and session outcomes persist as causal chains. Next session starts where the last left off — not from zero.
Daily TODO files with progress tracking. The agent reads the plan, executes sequentially, and updates its own progress markers.
Each query is decomposed into signals and scored across all backends (0.5·similarity + 0.4·feature_fit + 0.1·recency); a local LLM compresses the raw hits into core facts before they reach the prompt. New decisions auto-supersede old ones on the same topic key (similarity ≥ 0.8).
todoRunner.js (PM2-managed) schedules the daily backlog run at 06:00. It reads the most recent todos/{date}.md with pending items (the next day's work plan), spawns the agent with operational instructions, and triggers index refresh on completion.
A long agent run normally hits its context window and loses detail to a lossy auto-compact summary. With
focus-llama's
--fm-offload
engine, the oldest conversation is evicted to FocusMemory verbatim and pulled back on demand — lossless. The engine owns all eviction/recall logic; FocusMemory just stores and returns the text.
Once the engine's prompt passes a threshold (set under the client's compact point), the oldest middle messages are PUT to FocusMemory and removed from the prompt. System and the last user message are never evicted.
Evicted segments become virtual chunks (M+1…M+K). When the model emits <focus magic_chunks="N"> for one, the engine GETs its original text back and re-prefills it at the tail.
FocusMemory only stores and returns the text — no chunking, embedding, or search. Any store error fails open: the segment stays in the prompt, so a downed store degrades to a normal session, never to data loss.
A recall re-prefills one evicted chunk and is lossless; an auto-compact replaces the conversation with a lossy summary. The engine decides which messages leave and how to bring one back; FocusMemory is just the external memory behind it.
Plug FocusMemory into qwen-code with a single manifest file. Nine MCP tools, an auto-recall HTTP hook, and Hard Gate search rules — all loaded automatically on startup. No fork, no patch.
Removing the friction between what the model knows and what the agent can actually do.