Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content
Cookbook

Agent Memory Skill — Direct Retrieval

A drop-in skill file that teaches any coding agent (Claude Code, Codex, Cursor, or a general-purpose agent) to use Mubit as persistent, cross-session memory — with the direct, non-LLM retrieval path as the default.

The core insight: your agent is already an LLM, so it rarely needs Mubit's server-side query LLM to interpret memory for it. Direct retrieval returns the same ranked evidence — including cross-session lessons — with zero LLM calls, typically in 30–250 ms instead of the 4–9 s an agent-routed query takes. Live-benchmarked on hosted instances, direct recall is 30×+ faster than agent-routed recall with the same hit rate.

Install the skill

Download the skill file: SKILL.md

mkdir -p .claude/skills/mubit-memory
curl -o .claude/skills/mubit-memory/SKILL.md \
  https://docs.mubit.ai/skills/mubit-memory/SKILL.md

The file's frontmatter (name + description) makes it a native Claude Code skill — Claude loads it automatically when a task involves remembering things across sessions.

The agent needs two values (from the console):

export MUBIT_ENDPOINT="https://<your-instance-endpoint>"
export MUBIT_API_KEY="mbt_..."

What the skill teaches

Choosing a read path

PathLLM callsEmbedding callsLesson overlayTypical use
lookup (keyed)00noexact reads by metadata match — fastest path (~1–60 ms)
core search01noraw semantic top-k, no extras
recall with mode="direct_bypass", evidence_only=True01–3yesdefault: ranked evidence + cross-session lessons, no LLM (~30–250 ms)
recall (default agent_routed)2severalyesonly when you want the server to write final_answer (~4–9 s)
context2severalyespre-formatted prompt block — convenient, but pays full LLM cost

Rules of thumb: structured reads → lookup; "what do I know about X?" → direct-bypass evidence-only recall; never call agent-routed recall inside a loop. If a direct recall misses, rephrase and retry — two direct recalls still cost far less than one agent-routed call.

The default recall

direct_recall.py
from mubit import Client
client = Client()  # reads MUBIT_ENDPOINT / MUBIT_API_KEY
 
r = client.memory.recall(
    "How should I search for an invoice in the billing tool?",
    mode="direct_bypass",     # skip the query-router LLM
    evidence_only=True,       # skip the answer-synthesis LLM
    limit=8,
    run_id="sprint-42",
)
for ev in r.get("evidence", []):
    print(ev["retrieval_mode"], round(ev["score"], 3), ev["content"][:80])

In this mode final_answer is empty by design — the ranked evidence array is the product, and cross-session lessons arrive as evidence items with retrieval_mode: "lesson_overlay". The agent does the reasoning itself.

ℹ️Note

direct_bypass, core search, and lookup are gated by the instance's direct-access policy dials (on by default on hosted instances). If an operator has disabled direct search, the fallback that always works is recall(evidence_only=True) without the mode flag — the router LLM runs, but synthesis is skipped and you still get the evidence array.

Two write paths

Write pathLatency to acceptVisible afterLookup-matchable metadata
remember()~30 ms (wait=False)~2–4 s/item, ordered queueno
batch_insert~0.2–1.5 s (synchronous)immediatelyyes

Use remember() for narrative memory retrieved semantically; use batch_insert for structured records fetched back by key with lookup — only batch_insert metadata becomes lookup match keys. After a burst of wait=False writes, ingestion is ordered per run, so waiting on the last job id is a complete write barrier.

Cross-session lessons

client.memory.remember(
    "Always search billing by invoice ID; full-name search times out.",
    item_id="lesson-invoice-id",
    kind="lesson",
    lesson_type="success",
    visibility="global",          # the cross-run switch: run < agent < project < global
    lesson_importance="high",
    run_id="sprint-42",
)

visibility="global" is the guaranteed way to make a memory reachable from a brand-new, unlinked run. Lessons distilled at run end (or by client.lessons.reflect()) start run-scoped and are promoted by the server over time — so when the agent learns something it needs in the next session, it should also write the lesson explicitly.

Cross-session matching rules

A memory written in session A surfaces in session B only if the read matches the write on all five: scope (same run, linked run, or lesson scope ≥ session), user_id (same value on both sides, or unset on both), entry_types (don't filter unless you know the stored type), lane, and identity (same API key — run ids are namespaced per user).

Validation

The skill was validated live against hosted instances (real embedding service, real LLMs, no mocks): three cold agents given only the skill file completed store → learn → cross-session-recall workflows on the first try, and direct-bypass recall matched agent-routed recall's hit rate (8/8 known-answer queries) at 30×+ lower latency. The full read-path latency ladder in the skill reflects those measurements.

Related