Open-source · Self-hosted · Optimized for Qwen Code

Memory for your AI agents.

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.

Memory Architecture — Retrieval Pipeline · Autonomous TODO Loop · SKILL.state · Declarative Attention
1. ROUTE Where to look? 2. RETRIEVE Get the right context 3. PRUNE Keep what matters 4. INJECT Smaller, sharper context AGENT QUERY 💬 Why was the discount_threshold added and who uses it? ROUTER (Scoring) WORK HISTORY 0.82 KNOWLEDGE BASE 0.61 GRAPH INDEX 0.74 MEMORY INDEXES DECISION CHAINS Causal history, superseded by, why WORK HISTORY Decisions, facts, session outcomes KNOWLEDGE BASE Docs, plans, designs, notes GRAPH INDEX Code structure, calls, deps PRUNE & SUMMARIZE PRUNE Remove noise, dedupe, rank SUMMARIZE Compress to core facts (SUMMARY_LLM) ✓ AGENT / MODEL (LOCAL OR CLOUD) WRITE BACK Outcomes, decisions, new facts AUTONOMOUS TODO PIPELINE PM2 · DAILY 06:00 SCHEDULER todoRunner.js no commit · push · deploy TODO FILE todos/{date}.md skips if none pending SPAWN AGENT qwen -p default instructions EXECUTE 1 item at a time [ ] → [~] → [x] + summary AUTO-INGEST autoIngest.js refresh memory indexes same retrieval pipeline DAILY LOOP · RESUMES 06:00 SKILL.STATE — SURVIVING CONTEXT COMPACTION GATED · FOCUSMEMORY_SKILLSTATE=ON PRECOMPACT HOOK trigger: auto · manual spawns detached worker Σ EXTRACT transcript tail → state_patch parallel w/ native summary Σ MERGE Σ⊕Δ · null-deletes-key per-session + work_memory SESSIONSTART source: compact Σ + prose re-injected AGENT RESUME explicit state, not reconstructed history OFF = native compaction only (hooks no-op, fail-open) DECLARATIVE ATTENTION · KV-OFFLOAD — LOSSLESS RECALL GATED · DA=ON · KVOFFLOAD=ON EVICT engine over threshold oldest messages → PUT KV STORE /v1/kv-offload/chunk verbatim · no embedding DA MARKERS [[da:N]] + layout sig search results wrapped FOCUS <focus magic_chunks="N"> model names the chunk RE-PREFILL GET original text KV restored at tail ~1–2 s lossless recall vs ~5.3 min lossy auto-compact · production-verified (qwen3.8-27B)
FocusMemory qwen-code Extension logo

Memory infrastructure — zero modifications.

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 →

Neither remembers the decision that made it true.

Grep finds the code. Vectors find the meaning. Neither remembers why it's still that way.

↻

Search is stateless

Every session re-discovers the same files, re-reasons about the same architecture, from scratch — round-trips accumulate, context gets re-injected, tokens burn.

⊘

Schema drifts silently

What the code assumes about your database and what's actually running diverge — and nothing catches it until something breaks.

◇

Decisions vanish

Why a column was added, why a threshold was chosen — buried in a chat log that's gone the moment the session ends.

One decides what leaves. The other remembers what was there.

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.

Concernfocus-llama · inference engineFocusMemory · 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
launch the engine against it — --fm-offload --kv-offload-holes --focus-memory-host http://<host>:3900

Everything the engine needs to remember.

Not "just a search RAG" — four pillars cover the full memory contract between the inference engine and the agent.

The model names the chunk. The engine brings it back.

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.

✦

Server side — FocusMemory

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.

⚙

Engine side — focus-llama

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 focus tool

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.

<focus magic_chunks="N"> — comma-separated single chunk numbers only · no hyphen/tilde ranges · double quotes · closed tag · no partial tags in chain-of-thought

Explicit state, not reconstructed history.

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.

⏹

Stop — every turn

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).

⧉

PreCompact — final pass

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.

⚓

PromptSubmit / SessionStart

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

gated by FOCUSMEMORY_SKILLSTATE=on · ~9.8k input tokens per extraction, detached, parallel with native compaction · any failure leaves native compaction exactly as-is

Durable project knowledge — independent of the context window.

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.

⌨

Source code structure

Function graph via tree-sitter AST + semantic search over code chunks. The agent recalls "who calls X" without re-reading the file tree.

↺

Work history

Decisions, bug fixes, and session outcomes persist as causal chains. Next session starts where the last left off — not from zero.

☰

Task memory

Daily TODO files with progress tracking. The agent reads the plan, executes sequentially, and updates its own progress markers.

Ingest → Route → Recall → Prune → Commit → Supersede → Trace

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).

measured: tool calls/query 3.5 → 1.8 · response 25 s → 8 s  |  Hard Gate: PreToolUse denies grep/glob until search_memory runs — fails open

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.

[ ] → [~] in progress → [x] done  |  [!] interrupted (resumable)

A dumb store behind a lossless engine.

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.

⇄

Evict over threshold

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.

⤓

Focus to recall

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.

⛨

Dumb store, fail-open

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.

PUT /v1/kv-offload/chunk · GET /v1/kv-offload/chunk · DELETE /v1/kv-offload/session  |  gated by FOCUSMEMORY_KVOFFLOAD=on
~1–2 s lossless recall vs ~5.3 min lossy auto-compact · production-verified (qwen3.8-27B)  |  client must send X-Session-Id
FocusMemory qwen-code Extension logo

qwen-code extension — zero modifications.

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.

MCP Tools
search_memory · search_work_memory
trace_decision_chain · remember_decision
search_project_facts · search_code
query_graph · focus · search_web
HTTP Hook
UserPromptSubmit auto-recall
Context injected before agent loop
SUMMARY_LLM prune & summarize inline
View on GitHub →

Removing the friction between what the model knows and what the agent can actually do.