Est. 2026 Agent Memory Primitive Ref. v0.1

The forward way to remember.

MemRails plugs into your agent and equips a future-proof knowledge socket that replaces context-stuffing with dense, auditable, and payable deliverables ad hoc.

$ npx @memrails/wizard
View on GitHub → Get a demo →
~/agent/knowledge — memrails
$ npm install @memrails/memory
$ memrails init knowledge/
  → wrote knowledge/.memrails/config.yaml
  → indexed 0 keys · 0 claims · evidence layer ready

$ memrails query "what does this agent know with evidence?"
  ◐ literal scan        2.1ms   141 candidates
  ◐ key lookup          0.4ms     8 topics
  ◐ semantic rank       18ms      3 survivors
  ◐ evidence filter     1.2ms     3 claims ≥ 0.75 confidence
  ◇ packet              612 tokens  ← compressed
Markdown-canonical Git-versioned Evidence-aware
Context Bloat

Every token you stuff is a token you pay for twice.

Agents burn 80% of every context window on stale history, summaries-of-summaries, and irrelevant turns. The cost compounds — once in tokens, once in degraded reasoning.

Today

More tokens ≠ better thinking.

Endless embeddings, opaque graphs, vendor lock-in. Recall without trust. Tokens without signal.

MemRails

Better structure = cheaper cognition.

Files, keys, claims, evidence, diffs. Compression at retrieval. Audit before action.

What You Get

Memory that sharpens instead of bloating.

For agents
01

Drop-in retrieval API. memory.query() returns a ranked packet — fitted to your token budget — before any model call.

For tools
02

Every tool call leaves a paper trail. Memory packets cite the file, source, and confidence — auditable through MCP.

For frameworks
03

Improve memory. Get paid. Refactor agents propose cleaner claims, stronger evidence, better compression, and contradiction handling.

Architecture

Cheap filters first. Expensive reasoning only when needed.

L1Literal Filter
Purpose
Fast scan
Behavior
Most queries should not need a model.
L2Key Lookup
Purpose
Route to topic files
Behavior
Every concept has a durable key.
L3Semantic Rank
Purpose
Resolve meaning
Behavior
Embeddings run after scope is narrowed.
L4Evidence Filter
Purpose
Check trust
Behavior
Retrieve claims by confidence, not vibes.
L5Compression Packet
Purpose
Minimize context
Behavior
Give the model the smallest useful truth.
The Packet

Memory as a typed primitive, not a vendor graph.

Every topic is a key. Every key resolves to a Markdown file with typed frontmatter: claims, evidence, confidence, contradictions, refactor history. Embeddings, summaries, and caches are derived artifacts — regeneratable, swappable, never the source of truth.

knowledge/kv-cache.md
● evidence 0.79
---
key: kv-cache
aliases: [attention cache, transformer cache]
confidence: 0.86
evidence_score: 0.79
related: [attention, inference-optimization]
last_refactored: 2026-05-13
format_version: 0.1
---

# KV Cache

Short-term model memory that avoids recomputing
attention over prior tokens.

## Claims

- Claim: KV cache reduces repeated attention
  computation during autoregressive inference.
  confidence: high
  evidence: source-a, source-b

## Contradictions

None currently known.

## Refactor Notes

Compressed explanation split from
transformer-inference.md.
key
Stable, queryable identifier.
aliases
Synonyms agents collapse on retrieval.
confidence
Demoted automatically as evidence weakens.
evidence_score
Source quality × validator weight.
refactor_notes
Why this file looks like it does.
Self-Healing Memory

Memory improves.

MemRails treats memory maintenance like software maintenance.

refactor/kv-cache · diff
+ stake 12 · validator ✓
- confidence: 0.72
+ confidence: 0.86
- evidence: source-a
+ evidence: source-a, source-b
  contradictions: []
+ refactor_notes: |
+   Added second independent source.
+   Promoted confidence after validator review.
review · 2 validators · 1 dissent resolved See a refactor diff →
Trigger
Refactor Action
New trusted evidence arrives
Upgrade claim, link source
Sources disagree
Add contradiction, demote confidence
Repeated query exposes ambiguity
Sharpen definition
Topic gets too large
Split file, preserve links
Superior evidence appears
Downgrade stale claim
Concepts converge
Merge with aliases retained
Performance

Benchmark density, not just recall.

Current memory benchmarks ask: Did the system remember? MemRails asks the harder question: Did the system remember the smallest defensible version of the truth?

M01
Context Reduction

Tokens avoided per task

M02
Evidence Precision

Whether returned claims are source-backed

M03
Contradiction Survival

Whether nuance survives compression

M04
Refactor Velocity

How quickly memory improves after new evidence

M05
Cost per Useful Answer

Retrieval + model spend per successful output

M06
Drift Detection

Whether stale claims are visibly demoted

Developer Experience

Install it as a library. Keep it as a protocol.

No mandatory hosted service. No graph dependency. No SDK to deprecate around. MemRails runs inside your harness, writes to plain Markdown, and ships with first-class bindings for the runtimes you already use.

agent/memory.ts
@memrails/memory
import { Memory } from "@memrails/memory";

const memory = new Memory({
  root: "./knowledge",
  retrieval: ["grep", "key", "semantic", "evidence", "compress"]
});

const packet = await memory.query({
  q: "What do we know about KV cache optimization?",
  minConfidence: 0.75,
  maxTokens: 1200
});

console.log(packet.context);
console.log(packet.evidence);
Harness-native integrations
Claude Code OpenCode OpenClaw Cursor Codex LangGraph CrewAI n8n MCP
The Refactor Network

Memory becomes a market when quality becomes measurable.

When memory is file-based, evidence-scored, and diffable, improvement can be measured. When improvement can be measured, refactoring becomes payable work. When refactoring becomes payable work, memory becomes an economic network.

Users / Operators
Gives
Corrections, usage trails, memory data
Gets
Better memory, possible compensation
Refactor Agents
Gives
Cleaner claims, better evidence, compression
Gets
Payouts, reputation, lower fees
Buyers / Agents
Gives
Demand for trusted knowledge packets
Gets
Cheaper context, faster execution, better signal
Refactor Market — flow
Refactor Agent
↳ submits sourced diff
Validator
↳ checks evidence + rules
Accepted
↳ payout + reputation
Rejected
↳ stake loss + reputation penalty
Confidence formula
confidence =
  evidence_weight
+ source_quality
+ validator_score
+ contributor_reputation
+ stake_weight

Memory quality should not depend on one opaque agent. It should emerge from competition, evidence, and review.

One memory format · three monetization rails
Data Asset Rail
Curated memory becomes high-signal agent intent.
Refactor Rail
Agents earn for improving shared knowledge.
Agent Payment Rail
Agents pay for knowledge they did not generate.
vs. RAG

Not another memory API.

APIs make memory accessible. Protocols make memory durable.

Feature
Memory API
Vector DB
MemRails
Searchable memory
Human-readable source of truth
?
Git-versioned memory
Evidence-aware claims
?
Confidence demotion trails
?
Compression at retrieval
?
Refactor market
Protocol-first exit
14 / Ship it

Plug it in. Ship.

Models will change. Frameworks will fork. SDKs will deprecate. Compound your knowledge layer throughout.

$ npx @memrails/wizard
View on GitHub → Get a demo →

The future of agent memory is in your hands.