agent-recall-mcp 3.3.18 → 3.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +130 -1145
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,250 +1,34 @@
1
- <h1 align="center">AgentRecall</h1>
1
+ <h1 align="center">AgentRecall — MCP Server</h1>
2
2
 
3
3
  <p align="center"><strong>Your agent doesn't just remember. It learns how you think.</strong></p>
4
- <p align="center">Every correction saved is a mistake never repeated. Every insight compounded is tokens never wasted rebuilding context.</p>
5
- <p align="center">Persistent, compounding memory + automatic correction capture. MCP server + SDK + CLI.</p>
4
+ <p align="center">Persistent, compounding memory + automatic correction capture for Claude Code, Cursor, Windsurf, Codex, and any MCP-compatible agent.</p>
6
5
 
7
6
  <p align="center">
8
7
  <a href="https://www.npmjs.com/package/agent-recall-mcp"><img src="https://img.shields.io/npm/v/agent-recall-mcp?style=flat-square&label=MCP&color=5D34F2" alt="MCP npm"></a>
9
- <a href="https://www.npmjs.com/package/agent-recall-sdk"><img src="https://img.shields.io/npm/v/agent-recall-sdk?style=flat-square&label=SDK&color=0EA5E9" alt="SDK npm"></a>
10
- <a href="https://www.npmjs.com/package/agent-recall-cli"><img src="https://img.shields.io/npm/v/agent-recall-cli?style=flat-square&label=CLI&color=10B981" alt="CLI npm"></a>
11
8
  <a href="https://github.com/Goldentrii/AgentRecall/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen?style=flat-square" alt="License"></a>
12
- <img src="https://img.shields.io/badge/MCP-5_tools-orange?style=flat-square" alt="Tools">
9
+ <a href="https://lobehub.com/mcp/goldentrii-agentrecall"><img src="https://lobehub.com/badge/mcp/goldentrii-agentrecall" alt="MCP Badge"></a>
10
+ <img src="https://img.shields.io/badge/MCP-6_tools-orange?style=flat-square" alt="Tools">
13
11
  <img src="https://img.shields.io/badge/cloud-zero-blue?style=flat-square" alt="Zero Cloud">
14
- <img src="https://img.shields.io/badge/Obsidian-compatible-7C3AED?style=flat-square" alt="Obsidian">
15
- <img src="https://img.shields.io/badge/overhead-~876_tokens%2Fsession-22C55E?style=flat-square" alt="Token overhead">
16
12
  <img src="https://img.shields.io/badge/saves_up_to-57%25_tokens-FF6B6B?style=flat-square" alt="Token savings">
17
13
  <img src="https://img.shields.io/badge/break--even-3--4_sessions-22C55E?style=flat-square" alt="Break-even">
18
- <img src="https://img.shields.io/badge/scoring-RRF_(Cormack_2009)-7C3AED?style=flat-square" alt="RRF scoring">
19
- <img src="https://img.shields.io/badge/decay-Ebbinghaus_(1885)-3B82F6?style=flat-square" alt="Ebbinghaus decay">
20
- <img src="https://img.shields.io/badge/feedback-Bayesian_Beta-F59E0B?style=flat-square" alt="Beta distribution">
21
14
  </p>
22
15
 
23
16
  <p align="center">
24
- <b>EN:</b>&nbsp;
25
- <a href="#why-choose-agentrecall">Why</a> ·
26
- <a href="#three-ways-to-use-it">Use</a> ·
27
- <a href="#what-is-agentrecall">What</a> ·
28
- <a href="#quick-start">Install</a> ·
29
- <a href="#5-mcp-tools">Tools</a> ·
30
- <a href="#how-memory-compounds">Compounding</a> ·
31
- <a href="#sdk-api">SDK</a> ·
32
- <a href="#architecture">Architecture</a> ·
33
- <a href="#docs">Docs</a>
17
+ <a href="#quick-start"><b>Install</b></a> ·
18
+ <a href="#three-commands"><b>Commands</b></a> ·
19
+ <a href="#auto-hooks"><b>Hooks</b></a> ·
20
+ <a href="#6-mcp-tools"><b>Tools</b></a> ·
21
+ <a href="#benchmarked-savings"><b>Benchmarks</b></a> ·
22
+ <a href="#architecture"><b>Architecture</b></a>
34
23
  &nbsp;&nbsp;|&nbsp;&nbsp;
35
- <b>中文:</b>&nbsp;
36
- <a href="#agentrecall中文文档">简介</a> ·
37
- <a href="#快速开始">安装</a> ·
38
- <a href="#5-个-mcp-工具">工具</a> ·
39
- <a href="#记忆如何复合增长">复合</a> ·
40
- <a href="#sdk-api-1">SDK</a> ·
41
- <a href="#架构">架构</a>
24
+ <a href="#agentrecall-mcp中文文档">中文</a>
42
25
  </p>
43
26
 
44
27
  ---
45
28
 
46
- <p align="center">
47
- <a href="#arsave-and-arstart"><img src="https://img.shields.io/badge/%2Farsave-Save_Session-FF6B6B?style=for-the-badge" alt="/arsave"></a>
48
- <a href="#arsave-and-arstart"><img src="https://img.shields.io/badge/%2Farstart-Load_Context-4ECDC4?style=for-the-badge" alt="/arstart"></a>
49
- </p>
50
- <p align="center">
51
- <img src="https://img.shields.io/badge/AUTO-hook--start-8B5CF6?style=for-the-badge" alt="hook-start">
52
- <img src="https://img.shields.io/badge/AUTO-hook--correction-F97316?style=for-the-badge" alt="hook-correction">
53
- <img src="https://img.shields.io/badge/AUTO-hook--end-06B6D4?style=for-the-badge" alt="hook-end">
54
- </p>
55
- <p align="center">
56
- <a href="#how-memory-compounds"><img src="https://img.shields.io/badge/1-AUTO--NAMING-5D34F2?style=for-the-badge" alt="Auto-Naming"></a>
57
- <a href="#how-memory-compounds"><img src="https://img.shields.io/badge/2-INDEXES-0EA5E9?style=for-the-badge" alt="Indexes"></a>
58
- <a href="#how-memory-compounds"><img src="https://img.shields.io/badge/3-RELATIVITY-10B981?style=for-the-badge" alt="Relativity"></a>
59
- <a href="#how-memory-compounds"><img src="https://img.shields.io/badge/4-WEIGHT_%2B_DECAY-F59E0B?style=for-the-badge" alt="Weight + Decay"></a>
60
- <a href="#how-memory-compounds"><img src="https://img.shields.io/badge/5-FEEDBACK_LOOP-EF4444?style=for-the-badge" alt="Feedback Loop"></a>
61
- </p>
62
-
63
- ## `/arsave` and `/arstart`
64
-
65
- > **Two commands. That's all you need.**
66
-
67
- | Command | When | What it does |
68
- |---------|------|-------------|
69
- | **`/arsave`** | End of session | Write journal + consolidate to palace + update awareness + optional git push |
70
- | **`/arstart`** | Start of session | Recall cross-project insights + walk palace + load context |
71
-
72
- Type `/arsave` after a long project session. Everything gets saved. Type `/arstart` next time. Everything loads back.
73
-
74
- ```bash
75
- # Install commands (one-time, Claude Code only)
76
- mkdir -p ~/.claude/commands
77
- curl -o ~/.claude/commands/arsave.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arsave.md
78
- curl -o ~/.claude/commands/arstart.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arstart.md
79
- ```
80
-
81
- ### The Difference
82
-
83
- ```
84
- WITHOUT AgentRecall WITH AgentRecall
85
- ────────────────── ────────────────
86
-
87
- Day 1: Build monorepo Day 1: /arstart → /arsave
88
- Day 2: "What monorepo?" Day 2: /arstart
89
- → 20 min re-explaining → 2 sec: loads all decisions
90
- → Agent repeats same mistakes → Knows "no version inflation"
91
- → Forgets your priorities → Knows "arsave = hero section"
92
- → Misses half the tasks → Pushes to both repos
93
- ```
94
-
95
- ### Three Layers of Value
96
-
97
- **Layer 1 (5 seconds):** It makes your AI agent remember what happened last session.
98
-
99
- **Layer 2 (30 seconds):** Every time you correct your agent — "no, not that version", "ask me first" — that correction is stored permanently and recalled before the agent makes the same mistake again. After 10 sessions, your agent understands your priorities, your communication style, your non-negotiables.
100
-
101
- **Layer 3 (2 minutes):** The [Intelligent Distance Protocol](https://github.com/Goldentrii/AgentRecall/wiki/Intelligent-Distance). The structural gap between human thinking and AI action can't be closed — but it can be navigated better every session. Corrections are training data. The 200-line awareness cap forces quality over quantity. Cross-project insights mean lessons learned once apply everywhere.
102
-
103
- ### Real Session Flow
104
-
105
- This is from an actual multi-day project where a human gave scattered, non-linear instructions. The agent used AgentRecall throughout:
106
-
107
- ```
108
- Session 1 (Tuesday) Session 2 (Wednesday, different agent)
109
- ───────────────── ─────────────────────────────────────
110
-
111
- /arstart /arstart
112
- │ │
113
- ├─ session_start() ──→ identity, ├─ session_start() ──→ loads Tuesday's
114
- │ top insights, active rooms, │ decisions in ~400 tokens,
115
- │ cross-project matches, │ watch_for: "structurize input"
116
- │ watch_for warnings │
117
- │ ├─ recall("SDK CLI monorepo") ──→
118
- ├─ recall("SDK CLI versions") ──→ │ • "no version inflation"
119
- │ • "structurize scattered input" │ • "arsave/arstart = hero section"
120
- │ • "search before building" │
121
- │ • "ask when ambiguous" ├─ Continues exactly where
122
- │ │ Session 1 left off
123
- ▼ │
124
- Human: "we need SDK, CLI, ▼
125
- update README, fix versions" Human: "publish to npm,
126
- │ update both GitHub repos"
127
- ├─ check(goal="SDK+CLI+README", │
128
- │ confidence="medium") ├─ No re-explanation needed.
129
- │ → 4 tasks detected │ Agent already knows the
130
- │ → present plan → human confirms │ monorepo structure, package
131
- │ │ names, and version policy.
132
- ├─ Execute in order: │
133
- │ 1. Core extraction ✓ └─ Done in 2 minutes
134
- │ 2. Tool logic split ✓ (vs 20 min cold start
135
- │ 3. MCP wrappers ✓ without AgentRecall)
136
- │ 4. SDK + CLI ✓
137
-
138
- /arsave
139
-
140
- └─ session_end(summary, insights, trajectory)
141
- → journal + awareness + palace — one call
142
- ```
143
-
144
- ---
145
-
146
- ## Why Choose AgentRecall
147
-
148
- **AgentRecall is not a memory tool. It's a learning loop.**
149
-
150
- Memory is the mechanism. Understanding is the goal. Every time you correct your agent — "no, not that version", "put this section first", "ask me before you assume" — that correction is stored, weighted, and recalled next time. After 10 sessions, your agent doesn't just remember your project. It understands how you think: your priorities, your communication style, your non-negotiables.
151
-
152
- This is the **Intelligent Distance Protocol** — not closing the gap between human and AI (that gap is structural), but navigating it better every session.
153
-
154
- - **Your agent learns how you think.** Humans are inconsistent — we skip from A to E, forget what we said yesterday, change priorities mid-sentence. AgentRecall captures every correction and surfaces it before the next mistake. The gap between what you mean and what your agent does shrinks with every session.
155
-
156
- - **Compounding awareness, not infinite logs.** Memory is capped at 200 lines. New insights either merge with existing ones (strengthening them) or replace the weakest. After 100 sessions, your awareness file is still 200 lines — but each line carries the weight of cross-validated, confirmed observations.
157
-
158
- - **Cross-project recall.** Lessons learned in one project apply everywhere. Built a rate limiter last month? That lesson surfaces when you're building one today — in a different repo, through a different agent.
159
-
160
- - **Near-universal compatibility.** MCP server for any MCP-compatible agent (Claude Code, Cursor, Windsurf, VS Code, Codex). SDK for any JS/TS framework (LangChain, CrewAI, Vercel AI SDK, custom agents). CLI for terminal and CI workflows. One memory system, every surface.
161
-
162
- - **Zero cloud, zero telemetry, all local.** Everything is markdown on disk. Browse it in Obsidian, grep it in the terminal, version it in git. No accounts, no API keys, no lock-in.
163
-
164
- ### Use Case 1: The Scattered Human
165
-
166
- A real session where the human gave non-linear, scattered instructions across a 2-day project:
167
-
168
- > Human: "we need SDK, CLI, also update README, oh and the npm versions are wrong, fix those too"
169
-
170
- Without AgentRecall, the agent guesses priority and misses items. With AgentRecall:
171
-
172
- | What the agent already knew | How it knew |
173
- |---|---|
174
- | "This human communicates in scattered bursts — structurize into modules before executing" | `awareness_update` from 3 prior sessions |
175
- | "Ask when ambiguous, proceed when clear" | `alignment_check` correction stored last week |
176
- | "No version inflation — this human cares about semver discipline" | `nudge` captured mid-session, recalled immediately |
177
-
178
- Result: Agent presented a structured 4-step plan, human confirmed, zero rework. A fresh agent without AgentRecall would have guessed wrong on versions, buried the most important feature in the README, and published without testing.
179
-
180
- ### Use Case 2: The Cross-Project Lesson
181
-
182
- An engineer built a proxy server with rate limiting (Project A). Three weeks later, started an API gateway (Project B).
183
-
184
- ```
185
- /arstart on Project B:
186
- recall_insight: "Rate limiting prevents runaway costs"
187
- → source: Project A, confirmed 3x, severity: critical
188
- → applies_when: ["api", "proxy", "rate-limit", "cost"]
189
- → The lesson from Project A surfaces automatically in Project B
190
- ```
191
-
192
- The engineer never mentioned rate limiting. AgentRecall matched the project context against the global insights index and surfaced it proactively.
193
-
194
- ### Use Case 3: The Correction That Sticks
195
-
196
- Session 1: Agent uses version 4.0.0 for a patch release. Human corrects: "That's version inflation. Use 3.3.4."
197
-
198
- Session 2 (next day, different agent): Awareness already contains "no version inflation — this human cares about conservative versioning." The new agent gets it right the first time.
199
-
200
- Without AgentRecall, the same correction would be needed again. And again. And again. With AgentRecall, **every correction happens exactly once.**
201
-
202
- ---
203
-
204
- ## Three Ways to Use It
205
-
206
- **MCP** — for AI agents (Claude Code, Cursor, Windsurf, VS Code, Codex):
207
- ```bash
208
- claude mcp add --scope user agent-recall -- npx -y agent-recall-mcp
209
- ```
210
-
211
- **SDK** — for any JS/TS application (LangChain, CrewAI, Vercel AI SDK, custom):
212
- ```typescript
213
- import { AgentRecall } from "agent-recall-sdk";
214
- const memory = new AgentRecall({ project: "my-app" });
215
- await memory.capture("What stack?", "Next.js + Postgres");
216
- ```
217
-
218
- **CLI** — for terminal workflows and CI:
219
- ```bash
220
- npx agent-recall-cli capture "What stack?" "Next.js + Postgres"
221
- npx agent-recall-cli palace walk --depth active
222
- ```
223
-
224
- ---
225
-
226
- ## What Is AgentRecall?
227
-
228
- A **learning system** that bridges the gap between how humans think and how AI agents work. Not a log. Not a database. A compounding loop where every correction, decision, and insight makes the next session better than the last.
229
-
230
- **The problem:** AI agents don't truly forget — they lose focus. Priorities blur across sessions. Lessons go dormant. The same misunderstanding happens twice because no one stored the correction. The gap between what you mean and what your agent does stays constant, session after session.
231
-
232
- **The fix:** AgentRecall stores knowledge in a five-layer memory pyramid — from quick captures to cross-project insights — and forces compression so memory gets more valuable over time. But more importantly, it closes the **Intelligent Distance** gap: every human correction is captured, weighted, and recalled before the agent makes the same mistake again.
233
-
234
- | Without AgentRecall | With AgentRecall |
235
- |---------------------|------------------|
236
- | Agent forgets yesterday's decisions | Decisions live in palace rooms, loaded on cold start |
237
- | Same mistake repeated across sessions | `recall_insight` surfaces past lessons before work starts |
238
- | 5 min context recovery on each session start | 2 second cold start from palace (~200 tokens) |
239
- | Flat memory files that grow forever | 200-line awareness cap forces merge-or-replace |
240
- | Knowledge trapped in one project | Cross-project insights match by keyword |
241
- | Agent misunderstands, you correct, it forgets | `alignment_check` records corrections permanently |
242
-
243
- ---
244
-
245
29
  ## Quick Start
246
30
 
247
- ### MCP Server (for AI agents)
31
+ One command to wire AgentRecall into your agent:
248
32
 
249
33
  ```bash
250
34
  # Claude Code
@@ -263,77 +47,42 @@ claude mcp add --scope user agent-recall -- npx -y agent-recall-mcp
263
47
  codex mcp add agent-recall -- npx -y agent-recall-mcp
264
48
  ```
265
49
 
266
- **Skill (Claude Code only):**
50
+ **Claude Code skill (one-time, recommended):**
267
51
  ```bash
268
52
  mkdir -p ~/.claude/skills/agent-recall
269
53
  curl -o ~/.claude/skills/agent-recall/SKILL.md \
270
54
  https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/SKILL.md
271
55
  ```
272
56
 
273
- ### SDK (for JS/TS applications)
274
-
57
+ **Install slash commands (Claude Code only):**
275
58
  ```bash
276
- npm install agent-recall-sdk
277
- ```
278
-
279
- ```typescript
280
- import { AgentRecall } from "agent-recall-sdk";
281
-
282
- const memory = new AgentRecall({ project: "my-app" });
283
-
284
- // Capture knowledge
285
- await memory.capture("What ORM?", "Drizzle — type-safe, lightweight");
286
-
287
- // Write to memory palace
288
- await memory.palaceWrite("architecture", "Stack: Next.js 16 + Drizzle + Postgres");
289
-
290
- // Cold start — load project context in ~200 tokens
291
- const context = await memory.coldStart();
292
-
293
- // Recall cross-project insights
294
- const insights = await memory.recallInsight("rate limiting");
295
-
296
- // Walk the palace at different depths
297
- const walk = await memory.walk("active");
298
- ```
299
-
300
- ### CLI (for terminal and CI)
301
-
302
- ```bash
303
- npm install -g agent-recall-cli
304
- # or use npx: npx agent-recall-cli <command>
59
+ mkdir -p ~/.claude/commands
60
+ curl -o ~/.claude/commands/arsave.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arsave.md
61
+ curl -o ~/.claude/commands/arstart.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arstart.md
62
+ curl -o ~/.claude/commands/arsaveall.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arsaveall.md
305
63
  ```
306
64
 
307
- ```bash
308
- # Capture a Q&A pair
309
- ar capture "What ORM?" "Drizzle" --project my-app
310
-
311
- # Read today's journal
312
- ar read --date latest
65
+ ---
313
66
 
314
- # Walk the memory palace
315
- ar palace walk --depth active
67
+ ## Three Commands
316
68
 
317
- # Search across all memory
318
- ar search "rate limiting" --include-palace
69
+ > That's all you need.
319
70
 
320
- # Recall cross-project insights
321
- ar insight "building auth middleware"
71
+ | Command | When | What it does |
72
+ |---------|------|-------------|
73
+ | **`/arsave`** | End of session | Write journal + consolidate to palace + update awareness |
74
+ | **`/arstart`** | Start of session | Recall cross-project insights + walk palace + load context |
75
+ | **`/arsaveall`** | End of day (multi-session) | Batch save all parallel sessions at once — scan, merge, deduplicate |
322
76
 
323
- # Write to a palace room
324
- ar palace write architecture "Switched from REST to tRPC"
77
+ Type `/arsave` after a session. Type `/arstart` next time. Everything loads back.
325
78
 
326
- # Compact old journals into weekly summaries
327
- ar rollup --min-age-days 14
328
- ```
79
+ **Running 5 agents in parallel?** Don't `/arsave` five times. Type **`/arsaveall`** once — it scans all sessions across all projects, merges them into consolidated journals, deduplicates insights. Each session writes to its own file (session-ID scoped), so no conflicts, no data loss.
329
80
 
330
81
  ---
331
82
 
332
- ## How an Agent Uses AgentRecall
83
+ ## Auto Hooks
333
84
 
334
- ### Automatic (Zero DisciplineHooks)
335
-
336
- Wire once in `~/.claude/settings.json`. Every session is captured automatically, even without `/arsave`:
85
+ Wire once in `~/.claude/settings.json`. Every session is saved automatically even without typing `/arsave`:
337
86
 
338
87
  ```json
339
88
  {
@@ -343,6 +92,8 @@ Wire once in `~/.claude/settings.json`. Every session is captured automatically,
343
92
  }],
344
93
  "UserPromptSubmit": [{
345
94
  "command": "node ~/.local/share/npm/lib/node_modules/agent-recall-cli/dist/index.js hook-correction 2>/dev/null || true"
95
+ }, {
96
+ "command": "node ~/.local/share/npm/lib/node_modules/agent-recall-cli/dist/index.js hook-ambient 2>/dev/null || true"
346
97
  }],
347
98
  "Stop": [{
348
99
  "command": "node ~/.local/share/npm/lib/node_modules/agent-recall-cli/dist/index.js hook-end 2>/dev/null || true"
@@ -351,949 +102,183 @@ Wire once in `~/.claude/settings.json`. Every session is captured automatically,
351
102
  }
352
103
  ```
353
104
 
354
- - **hook-start** on every session open: prints identity + top insights + watch_for warnings
355
- - **hook-correction** — on every prompt: detects corrections (regex) and captures them silently
356
- - **hook-end** on every session close: appends a lightweight end-of-session log entry
105
+ | Hook | Trigger | What it does |
106
+ |------|---------|-------------|
107
+ | `hook-start` | SessionStart | Prints identity + top insights + `watch_for` warnings |
108
+ | `hook-correction` | Every user prompt | Detects corrections (regex) and captures them silently — no agent discretion |
109
+ | `hook-ambient` | Every user prompt | Extracts keywords → fires recall → injects top results before agent responds |
110
+ | `hook-end` | Session close | Appends lightweight end-of-session log entry |
357
111
 
358
- ### Session Start (`/arstart`)
359
- ```
360
- session_start() → identity, insights, active rooms, cross-project matches,
361
- recent journal briefs, watch_for warnings — all in one call
362
- recall(query) → surface task-specific past knowledge from all stores
363
- ```
364
-
365
- ### During Work
366
- ```
367
- remember("We decided to use GraphQL instead of REST") → auto-routes to the right store
368
- recall("authentication design") → searches all stores, ranked results
369
- check(goal="build auth", confidence="medium") → verify understanding, get warnings
370
- ```
371
-
372
- ### Session End (`/arsave`)
373
- ```
374
- session_end(summary="...", insights=[...], trajectory="...") → journal + awareness + consolidation
375
- ```
112
+ Hooks move the save burden from agent discretion → harness enforcement. The agent never has to remember to save.
376
113
 
377
114
  ---
378
115
 
379
- ## 5 MCP Tools
116
+ ## 6 MCP Tools
380
117
 
381
- AgentRecall exposes exactly 5 tools to agents. Each tool composes multiple subsystems internally — the agent doesn't need to know about the plumbing.
118
+ AgentRecall exposes 6 tools to your agent. Each tool composes multiple subsystems — the agent doesn't need to know about the plumbing.
382
119
 
383
120
  | Tool | What it does |
384
121
  |------|-------------|
385
- | `session_start` | Load project context for a new session. Returns identity, top insights, active rooms, cross-project matches, recent activity, and predictive `watch_for` warnings from past corrections. One call, ~400 tokens. |
386
- | `remember` | Save a memory. Auto-classifies content (bug fix, architecture decision, insight, session note) and routes to the right store (journal, palace, knowledge, or awareness). Auto-generates semantic names for future retrieval. |
387
- | `recall` | Search all memory stores at once using **Reciprocal Rank Fusion (RRF)** — each source ranks internally, then positions are merged so no source dominates by default. Returns ranked results with stable IDs. Accepts `feedback` to rate previous results: positive boosts future ranking, negative penalizes. Query-aware — feedback from one search doesn't bleed into unrelated queries. |
388
- | `session_end` | Save everything in one call. Writes journal, updates awareness with new insights, consolidates to palace rooms, archives demoted insights (not deleted — preserved with resurrection support). |
389
- | `check` | Record what you think the human wants. Returns `watch_for` patterns from past correction history ("You've been corrected on X 3 times — ask about it"). Accepts `human_correction` and `delta` after the human responds. Auto-promotes strong patterns (3+) to awareness. |
390
-
391
- ### Legacy tools
392
-
393
- The original 22 subsystem tools (palace_write, journal_capture, awareness_update, etc.) remain available via the SDK and CLI for backward compatibility and advanced use cases. They are not registered in the MCP server by default.
122
+ | `session_start` | Load project context. Returns identity, top insights, active rooms, cross-project matches, and `watch_for` warnings from past corrections. One call, ~400 tokens. |
123
+ | `remember` | Save a memory. Auto-classifies and routes to the right store (journal, palace, knowledge, or awareness). Auto-generates semantic names for retrieval. |
124
+ | `recall` | Search all memory stores with **Reciprocal Rank Fusion (RRF)**. Returns ranked results. Accepts `feedback` to rate previous results positive boosts future ranking, negative penalizes. |
125
+ | `session_end` | Save everything in one call: journal + awareness update + palace consolidation + archive demoted insights (preserved, not deleted). |
126
+ | `check` | Record what you think the human wants. Returns `watch_for` patterns from past corrections. Accepts `human_correction` and `delta` after the human responds. |
127
+ | `digest` | **Context cache** — store pre-computed analysis results and recall them instead of recomputing. Supports TTL, global store, and dedup. **83% token savings on repeated analysis.** |
394
128
 
395
129
  ---
396
130
 
397
131
  ## How Memory Compounds
398
132
 
399
- <p align="center">
400
- <a href="#1-auto-naming"><img src="https://img.shields.io/badge/1-AUTO--NAMING-5D34F2?style=for-the-badge" alt="Auto-Naming"></a>
401
- <a href="#2-indexes"><img src="https://img.shields.io/badge/2-INDEXES-0EA5E9?style=for-the-badge" alt="Indexes"></a>
402
- <a href="#3-relativity"><img src="https://img.shields.io/badge/3-RELATIVITY-10B981?style=for-the-badge" alt="Relativity"></a>
403
- <a href="#4-weight--decay"><img src="https://img.shields.io/badge/4-WEIGHT_%2B_DECAY-F59E0B?style=for-the-badge" alt="Weight + Decay"></a>
404
- <a href="#5-feedback-loop"><img src="https://img.shields.io/badge/5-FEEDBACK_LOOP-EF4444?style=for-the-badge" alt="Feedback Loop"></a>
405
- </p>
133
+ Memory is not a list. It's a compounding system — each layer feeds the next:
406
134
 
407
- > Memory is not a list. It's a compounding system where 1+1+1 > 3. Each subsystem feeds the next naming enables retrieval, retrieval enables feedback, feedback enables ranking, ranking surfaces the right memory at the right time. After 10 sessions, the system knows more than any individual memory contains.
135
+ 1. **Auto-Naming**Content is saved with semantic slugs. Good naming is the first layer of retrieval.
136
+ 2. **Indexes** — Every memory has an address in palace index, insights index, and the 200-line awareness document.
137
+ 3. **Relativity** — Memories that relate to each other are connected automatically via graph edges.
138
+ 4. **Weight + Decay** — Salience scoring: `recency(0.30) + access(0.25) + connections(0.20) + urgency(0.15) + importance(0.10)`. Architecture decisions persist; blocker noise fades.
139
+ 5. **Feedback Loop** — Bayesian Beta distribution learns which recalled memories are actually useful. Useful memories rise; noise sinks.
408
140
 
409
- ### 1. Auto-Naming
410
-
411
- The agent knows content best at the moment of saving. AgentRecall captures that understanding in a semantic slug — not `"mcp-verified"` but `"verified-agentrecall-mcp-22tools-functional"`.
412
-
413
- ```
414
- Content: "Fixed a critical bug where the payment processor crashed on refunds"
415
- → Type detected: bug-fix
416
- → Keywords extracted: payment, processor, crashed, refunds
417
- → Slug generated: bug-fix-payment-processor-crashed
418
141
  ```
419
-
420
- Good naming IS the first layer of retrieval. A well-named memory is 80% findable without any search algorithm.
421
-
422
- ### 2. Indexes
423
-
424
- Every memory has an address in three index systems:
425
-
426
- | Index | What it tracks | Token cost |
427
- |-------|---------------|------------|
428
- | **Palace index** | Room catalog + salience scores | ~50 tokens to scan |
429
- | **Insights index** | Cross-project lessons + keyword matching | ~30 tokens to query |
430
- | **Awareness** | 200-line compounding document (forced merge) | ~200 tokens, but each line carries cross-validated weight |
431
-
432
- Indexes are cheap pointers. The agent scans indexes first, then loads full content only when needed.
433
-
434
- ### 3. Relativity
435
-
436
- Memories that relate to each other are connected automatically — no wikilinks needed.
437
-
438
- ```
439
- Agent writes: "JWT refresh rotation prevents session fixation"
440
- → Keywords: jwt, refresh, rotation, session
441
- → Room "architecture" has tags: ["technical"]
442
- → Room "knowledge" has a lesson about "session management"
443
- → Auto-edge created: architecture ←→ knowledge (weight 0.3)
444
- ```
445
-
446
- When you `recall("session security")`, the system surfaces keyword-matched memories across connected rooms. Edges are stored in `graph.json` and are available for traversal — relativity turns isolated memories into a knowledge graph.
447
-
448
- ### 4. Weight + Decay
449
-
450
- Not all memories are equal. Salience scoring ensures the right memory surfaces first:
451
-
452
- ```
453
- salience = recency(0.30) + access(0.25) + connections(0.20) + urgency(0.15) + importance(0.10)
454
- ```
455
-
456
- - Architecture decisions decay at 0.98/day (persistent). Blockers decay at 0.90/day (ephemeral).
457
- - Memories you actually access get stronger. Memories you never revisit fade.
458
- - Demoted insights don't die — they go to the archive. If a future insight matches, they resurrect.
459
-
460
- `recall` applies the **Ebbinghaus forgetting curve** `R(t) = e^(−t/S)` with memory-type-specific strength values — matching the psychological reality of each type:
461
-
462
- | Memory type | S (days) | 1-day retention | 1-week retention |
463
- |-------------|----------|-----------------|------------------|
464
- | Journal (episodic) | 2 | 60% | ~7% |
465
- | Knowledge / bug fix (procedural) | 180 | 99% | 96% |
466
- | Palace / decisions (semantic) | 9999 | ≈100% | ≈100% |
467
-
468
- Old journal noise fades in days. Architecture decisions persist indefinitely. Same query, right results.
469
-
470
- ### 5. Feedback Loop
471
-
472
- The system learns what's useful and what's not, using a **Bayesian Beta distribution** — the mathematically optimal estimate of true usefulness from binary observations (`E[Beta(α,β)] = (pos+1)/(pos+neg+2)`):
473
-
474
- ```
475
- Session 1: recall("auth design") → returns 5 results
476
- Agent rates: result #1 useful, result #3 not useful
477
- → Stored in feedback-log.json with query context
478
-
479
- Session 2: recall("auth patterns") → similar query
480
- → Result #1: Beta(2,1) → E[U]=0.67 → ×1.33 score multiplier
481
- → Result #3: Beta(1,2) → E[U]=0.33 → ×0.67 score multiplier
482
- → Rankings shift: useful memories rise, noise sinks
483
- ```
484
-
485
- No-feedback items stay neutral (multiplier ×1.0). Feedback is query-aware — rating a result "useless" for "auth design" doesn't penalize it for "database schema". The system learns per-context, not globally.
486
-
487
- ### The Compounding Effect
488
-
489
- ```
490
- Session 1: Save 3 memories (auto-named, indexed, edges created)
491
- Session 5: Recall surfaces memories from sessions 1-4, feedback refines ranking
142
+ Session 1: Save 3 memories → auto-named, indexed, edges created
143
+ Session 5: Recall surfaces sessions 1-4; feedback refines ranking
492
144
  Session 10: watch_for warns agent about past mistakes before they repeat
493
- Session 20: Awareness contains 10 cross-validated insights (merged from 40+ raw observations)
494
- Session 50: The agent knows your priorities, blind spots, and communication style
495
- — not because it was told, but because every correction compounded
145
+ Session 20: Awareness has 10 cross-validated insights (merged from 40+ raw)
146
+ Session 50: The agent knows your priorities, blind spots, communication style
496
147
  ```
497
148
 
498
- Each layer multiplies the others. Auto-naming makes indexing useful. Indexing makes relativity possible. Relativity makes recall precise. Precise recall generates meaningful feedback. Feedback makes the next recall even better. The loop compounds.
499
-
500
149
  ---
501
150
 
502
- ## SDK API
151
+ ## Benchmarked Savings
503
152
 
504
- The `agent-recall-sdk` package exposes the `AgentRecall` classa programmatic interface to the full memory system. Use it to add persistent, compounding memory to any JS/TS agent framework: LangChain, CrewAI, Vercel AI SDK, AutoGen, or your own.
153
+ > **Honest caveat:** The "without AR" costs are modeled estimateswe estimated what a human would spend re-explaining context. These are not long-term production data. Real savings depend on project complexity and session count. [Let us know](mailto:tong.wu@novada.com) if your results differ.
505
154
 
506
- ```typescript
507
- import { AgentRecall } from "agent-recall-sdk";
155
+ | Scenario | Without AR | With AR | Saved |
156
+ |----------|:----------:|:-------:|:-----:|
157
+ | **A: Simple** (2 sessions, 0 corrections) | 567 | 1,131 | **+99% overhead** |
158
+ | **B: Medium** (5 sessions, 1 correction) | 6,220 | 4,382 | **-30%** |
159
+ | **C: Complex** (20 sessions, 5 corrections) | 40,910 | 17,520 | **-57%** |
160
+ | **D: Multi-agent** (3 agents × 5 sessions) | 20,781 | 13,140 | **-37%** |
161
+ | **E: Digest cache** (repeated analysis) | ~2,400 | ~400 | **-83%** |
508
162
 
509
- const ar = new AgentRecall({ project: "my-project" });
510
- ```
511
-
512
- ### Core Methods
513
-
514
- | Method | Returns | Description |
515
- |--------|---------|-------------|
516
- | `capture(question, answer, opts?)` | `JournalCaptureResult` | Quick Q&A capture (L1 memory) |
517
- | `journalWrite(content, opts?)` | `JournalWriteResult` | Write daily journal entry |
518
- | `journalRead(opts?)` | `JournalReadResult` | Read journal by date or "latest" |
519
- | `journalSearch(query, opts?)` | `JournalSearchResult` | Full-text search across journals |
520
- | `coldStart()` | `JournalColdStartResult` | Palace-first context loading (~200 tokens) |
521
-
522
- ### Palace Methods
523
-
524
- | Method | Returns | Description |
525
- |--------|---------|-------------|
526
- | `palaceWrite(room, content, opts?)` | `PalaceWriteResult` | Write to a room with fan-out cross-refs |
527
- | `palaceRead(room?, topic?)` | `PalaceReadResult` | Read room content or list all rooms |
528
- | `walk(depth?, focus?)` | `PalaceWalkResult` | Progressive walk: identity → active → relevant → full |
529
- | `palaceSearch(query, room?)` | `PalaceSearchResult` | Search rooms by content |
530
- | `lint(fix?)` | `PalaceLintResult` | Health check and auto-archive |
531
-
532
- ### Awareness & Insight Methods
533
-
534
- | Method | Returns | Description |
535
- |--------|---------|-------------|
536
- | `awarenessUpdate(insights, opts?)` | `AwarenessUpdateResult` | Compound new insights into awareness |
537
- | `readAwareness()` | `string` | Read the 200-line awareness document |
538
- | `recallInsight(context, opts?)` | `RecallInsightResult` | Cross-project insight recall |
539
-
540
- ### Alignment Methods
541
-
542
- | Method | Returns | Description |
543
- |--------|---------|-------------|
544
- | `alignmentCheck(input)` | `AlignmentCheckResult` | Record confidence + assumptions |
545
- | `nudge(input)` | `NudgeResult` | Detect contradictions with past decisions |
546
- | `synthesize(opts?)` | `ContextSynthesizeResult` | L3 synthesis, optional palace consolidation |
547
-
548
- ### LangChain / CrewAI Integration Example
549
-
550
- ```typescript
551
- import { AgentRecall } from "agent-recall-sdk";
552
-
553
- const memory = new AgentRecall({ project: "langchain-app" });
554
-
555
- // Before agent runs — load context
556
- const context = await memory.coldStart();
557
- const insights = await memory.recallInsight("current task description");
558
-
559
- // Inject into system prompt
560
- const systemPrompt = `You have persistent memory:\n${context.summary}\n\nRelevant insights:\n${insights.matches.map(m => m.insight).join("\n")}`;
561
-
562
- // After agent runs — save what was learned
563
- await memory.capture("What did the agent decide?", agentOutput);
564
- await memory.awarenessUpdate([{
565
- insight: "Rate limiting needs token bucket, not fixed window",
566
- evidence: "Fixed window caused burst failures in load test",
567
- applies_when: ["rate-limiting", "api-design", "load-testing"]
568
- }]);
569
- ```
570
-
571
- ---
572
-
573
- ## CLI Commands
574
-
575
- The `agent-recall-cli` package provides the `ar` command for terminal workflows, CI pipelines, and quick access to your agent's memory outside of an editor.
576
-
577
- ```
578
- ar v3.3.14 — AgentRecall CLI
579
-
580
- JOURNAL:
581
- ar read [--date YYYY-MM-DD] [--section <name>]
582
- ar write <content> [--section <name>]
583
- ar capture <question> <answer> [--tags tag1,tag2]
584
- ar list [--limit N]
585
- ar search <query> [--include-palace]
586
- ar state read|write [data]
587
- ar cold-start
588
- ar archive [--older-than-days N]
589
- ar rollup [--min-age-days N] [--dry-run]
590
-
591
- PALACE:
592
- ar palace read [<room>] [--topic <name>]
593
- ar palace write <room> <content> [--importance high|medium|low]
594
- ar palace walk [--depth identity|active|relevant|full]
595
- ar palace search <query>
596
- ar palace lint [--fix]
597
-
598
- AWARENESS:
599
- ar awareness read
600
- ar awareness update --insight "title" --evidence "ev" --applies-when kw1,kw2
601
-
602
- INSIGHT:
603
- ar insight <context> [--limit N]
604
-
605
- META:
606
- ar projects
607
- ar synthesize [--entries N]
608
- ar knowledge write --category <cat> --title "t" --what "w" --cause "c" --fix "f"
609
- ar knowledge read [--category <cat>]
610
-
611
- HOOKS (auto-wired via settings.json — zero discipline required):
612
- ar hook-start # SessionStart: prints identity + insights + watch_for
613
- ar hook-correction # UserPromptSubmit: silently captures corrections from prompt
614
- ar hook-end # Stop: appends end-of-session log entry
615
-
616
- GLOBAL FLAGS:
617
- --root <path> Storage root (default: ~/.agent-recall)
618
- --project <slug> Project override
619
- ```
163
+ **Break-even: ~3-4 sessions.** For simple throwaway tasks, AR is overhead. For anything with 3+ sessions, corrections, or multiple agents, it pays for itself.
620
164
 
621
165
  ---
622
166
 
623
167
  ## Architecture
624
168
 
625
- ### Five-Layer Memory Pyramid
626
-
627
- ```
628
- L1: Working Memory journal_capture "what happened"
629
- L2: Episodic Memory journal_write "what it means"
630
- L3: Memory Palace palace_write / walk "knowledge across sessions"
631
- L4: Awareness awareness_update "compounding insights"
632
- L5: Insight Index recall_insight "cross-project experience"
633
- ```
634
-
635
- ### Key Mechanisms
636
-
637
- **Fan-out writes** — Write to one room, cross-references auto-update in related rooms via `[[wikilinks]]`. Mechanical, zero LLM cost.
638
-
639
- **Salience scoring** — Every room has a salience score: `recency(0.30) + access(0.25) + connections(0.20) + urgency(0.15) + importance(0.10)`. High-salience rooms surface first. Below threshold → auto-archive.
640
-
641
- **Compounding awareness** — `awareness.md` is capped at 200 lines. When new insights are added, similar existing ones merge (strengthen), dissimilar ones compete (lowest-confirmation gets replaced). The constraint creates compression. Compression creates compounding.
642
-
643
- **Cross-project insight recall** — `insights-index.json` maps insights to situations via keywords. `recall_insight("building quality gates")` returns relevant lessons from any project, ranked by severity x confirmation count.
644
-
645
- **Obsidian-compatible** — Every palace file has YAML frontmatter + `[[wikilinks]]`. Open `palace/` as an Obsidian vault → graph view shows room connections. Zero Obsidian dependency.
646
-
647
- ### Storage Layout
648
-
649
169
  ```
650
- ~/.agent-recall/
651
- awareness.md # 200-line compounding document (global)
652
- awareness-state.json # Structured awareness data
653
- awareness-archive.json # Demoted insights (preserved, not deleted)
654
- insights-index.json # Cross-project insight matching
655
- projects/
656
- <project>/
657
- journal/
658
- YYYY-MM-DD.md # Daily journal
659
- YYYY-MM-DD-log.md # L1 captures (hook-start/hook-end entries)
660
- YYYY-MM-DD.state.json # JSON state
661
- index.jsonl # Fast machine-scannable index of all entries
662
- palace/
663
- identity.md # ~50 token project identity card
664
- palace-index.json # Room catalog + salience scores
665
- graph.json # Cross-reference edges (relativity)
666
- feedback-log.json # Per-query feedback scores (recall learning)
667
- alignment-log.json # Past corrections for watch_for patterns
668
- rooms/
669
- goals/ # Active goals, evolution
670
- architecture/ # Technical decisions, patterns
671
- blockers/ # Current and resolved
672
- alignment/ # Human corrections
673
- knowledge/ # Learned lessons by category
674
- <custom>/ # Agents create rooms on demand
170
+ Agent (Claude Code / Cursor / Windsurf / Codex)
171
+
172
+ └─ MCP tools: session_start, remember, recall, session_end, check, digest
173
+
174
+ └─ agent-recall-core (local, no cloud)
175
+
176
+ ├─ ~/.agent-recall/awareness.md (200-line global document)
177
+ ├─ ~/.agent-recall/insights-index.json (cross-project recall)
178
+ └─ ~/.agent-recall/projects/<project>/
179
+ ├─ journal/ (daily logs)
180
+ └─ palace/rooms/ (persistent decisions, Obsidian-compatible)
675
181
  ```
676
182
 
677
- ---
678
-
679
- ## Platform Compatibility
680
-
681
- | Platform | MCP | SDK | CLI | Notes |
682
- |----------|:---:|:---:|:---:|-------|
683
- | Claude Code | ✅ | ✅ | ✅ | Full support — MCP + SKILL.md + commands |
684
- | Cursor | ✅ | ✅ | ✅ | MCP via .cursor/mcp.json |
685
- | VS Code (Copilot) | ✅ | ✅ | ✅ | MCP via .vscode/mcp.json |
686
- | Windsurf | ✅ | ✅ | ✅ | MCP via mcp_config.json |
687
- | OpenAI Codex | ✅ | ✅ | ✅ | `codex mcp add` — config.toml |
688
- | Claude Desktop | ✅ | — | — | MCP server |
689
- | LangChain / LangGraph | — | ✅ | — | `new AgentRecall()` in your chain |
690
- | CrewAI | — | ✅ | — | SDK in tool definitions |
691
- | Vercel AI SDK | — | ✅ | — | SDK in server actions |
692
- | Custom JS/TS agents | — | ✅ | ✅ | SDK + CLI for any agent framework |
693
- | CI / GitHub Actions | — | — | ✅ | `npx agent-recall-cli` in workflows |
694
- | Any MCP agent | ✅ | — | — | Standard MCP protocol |
695
-
696
- ---
697
-
698
- ## Real Results
699
-
700
- Validated over 42+ sessions across 5 production projects:
701
- - Cold-start: **5 min → 2 seconds** (palace-first loading, ~400 tokens)
702
- - Decision retention: **0% → 100%** across sessions
703
- - Misunderstanding caught before wrong work: **6+ instances** via `check` before publish/deploy
704
- - Repeated mistakes prevented: **3 instances** via cross-project insight recall
705
-
706
- ### Measured Token Cost (v3.3.14, 5 rounds)
707
-
708
- | Surface | What it returns | Measured tokens |
709
- |---------|----------------|-----------------|
710
- | `hook-start` (stdout) | identity + watch_for + 3 insights + recent + cross-project hint | ~215 |
711
- | `session_start` (MCP) | full session context — all fields | ~601 |
712
- | `check` (MCP) | watch_for patterns + past deltas | ~80 |
713
- | **Total session overhead** | | **~896 tokens** |
714
-
715
- Each prevented correction ≈ **1,500 tokens saved** (re-explanation + wrong work + retry).
716
- Breakeven: **less than 1 correction prevented per session** covers the overhead.
717
- At 42 sessions with avg 1.5 corrections prevented: **~94,000 tokens saved** vs ~37,600 overhead.
718
-
719
- ### What the 5 Test Rounds Verified
720
-
721
- **Round 1 — hook-start:**
722
- Fires on session open (with per-session lock to avoid double-fire). Output: project identity, past correction warnings (watch_for), top 3 awareness insights, today's journal brief, cross-project hint. All in 9 lines.
723
-
724
- **Round 2 — capture / palace write / search / walk:**
725
- - `capture "bug fix"` → routes to journal log with auto-tags
726
- - `palace write architecture "..."` → writes to room with fan-out
727
- - `search "journal crash fix"` → keyword match finds the entry from 2 minutes ago
728
- - `palace walk --depth active` → loads 5 rooms, top 10 insights, architecture decisions in one JSON
729
-
730
- **Round 3 — hook-correction / hook-end / MCP tools:**
731
- - `hook-correction` with no-correction prompt → silent exit (correct)
732
- - `hook-correction` with correction ("no use patch not minor") → silent capture, exit 0
733
- - `hook-end` → exit 0, auto-log entry
734
- - MCP `session_start` → 601 tokens, all 7 fields populated
735
- - MCP `check(goal="publish v3.3.14", confidence="high")` → 80 tokens, 1 watch_for pattern surfaced
736
-
737
- **Round 4 — cross-source recall competition (v3.3.14):**
738
- - `recall("edge functions cold start")` → palace + journal + insight all queried; RRF merged by rank position — no source dominated by raw score inflation
739
- - Old journal entries (>3 days) correctly faded via Ebbinghaus S=2; palace decisions surfaced regardless of age
740
-
741
- **Round 5 — feedback loop (v3.3.14):**
742
- - `recall("auth design")` + feedback `{useful: true}` → Beta(2,1) → ×1.33 on next query
743
- - `recall("auth design")` + feedback `{useful: false}` → Beta(1,2) → ×0.67 penalty
744
- - Zero-feedback items unchanged (Beta(1,1) → ×1.0 neutral)
745
-
746
- 172 tests (129 core + 4 smoke + 28 SDK + 11 CLI), 0 failures. Build clean.
183
+ Everything is markdown on disk. Browse in Obsidian, grep in terminal, version in git. Zero cloud, zero telemetry.
747
184
 
748
185
  ---
749
186
 
750
- ## Docs
187
+ ## Links
751
188
 
752
- | Document | Description |
753
- |----------|-------------|
754
- | [Intelligent Distance Protocol](docs/intelligent-distance-protocol.md) | The foundational theory — why the gap between human and AI is structural, and how to navigate it |
755
- | [Scoring Design Rationale](docs/SCORING.md) | Why the scoring system works this way — RRF, Ebbinghaus, Beta distribution, and the bugs they fix |
756
- | [MCP Adapter Spec](docs/mcp-adapter-spec.md) | Technical spec for building adapters on top of AgentRecall |
757
- | [SDK Design](docs/sdk-design.md) | Design doc for the SDK architecture |
758
- | [Upgrade v3.4](UPGRADE-v3.4.md) | Changelog: weekly roll-up, palace-first cold start, promotion verification |
189
+ - **Full documentation:** [Main README](../../README.md)
190
+ - **SDK API reference:** [agent-recall-core](../core/README.md)
191
+ - **GitHub:** [Goldentrii/AgentRecall](https://github.com/Goldentrii/AgentRecall)
192
+ - **Issues:** [GitHub Issues](https://github.com/Goldentrii/AgentRecall/issues)
193
+ - **Email:** [tong.wu@novada.com](mailto:tong.wu@novada.com)
759
194
 
760
195
  ---
761
196
 
762
- ## Contributing
763
-
764
- Built by [tongwu](https://github.com/Goldentrii) at [Novada](https://www.novada.com).
765
-
766
- - Issues & feedback: [GitHub Issues](https://github.com/Goldentrii/AgentRecall/issues)
767
- - Email: [tong.wu@novada.com](mailto:tong.wu@novada.com)
768
- - Website: [novada.com](https://www.novada.com)
769
-
770
- MIT License.
771
-
772
197
  ---
773
198
 
774
- ---
775
-
776
- # AgentRecall(中文文档)
199
+ # AgentRecall MCP(中文文档)
777
200
 
778
- > **你的智能体记不清楚?听不懂你说话?每次项目都做得非常乱?**
779
- >
780
- > **AgentRecall 让它学会理解你的思维方式。**
201
+ > **你的智能体记不清楚?AgentRecall 让它学会理解你的思维方式。**
781
202
  >
782
- > 赋能agent长期记忆,并从错误中学习和纠正,随时间和项目难度进化,越来越擅长和了解用户和agent的思维。
783
- >
784
- > 持久复合记忆 + 智能距离协议。MCP 服务器 + SDK + CLI。
785
-
786
- ---
787
-
788
- <p align="center">
789
- <a href="#arsave-and-arstart"><img src="https://img.shields.io/badge/%2Farsave-保存会话-FF6B6B?style=for-the-badge" alt="/arsave"></a>
790
- <a href="#arsave-and-arstart"><img src="https://img.shields.io/badge/%2Farstart-加载上下文-4ECDC4?style=for-the-badge" alt="/arstart"></a>
791
- </p>
792
- <p align="center">
793
- <img src="https://img.shields.io/badge/自动-hook--start-8B5CF6?style=for-the-badge" alt="hook-start">
794
- <img src="https://img.shields.io/badge/自动-hook--correction-F97316?style=for-the-badge" alt="hook-correction">
795
- <img src="https://img.shields.io/badge/自动-hook--end-06B6D4?style=for-the-badge" alt="hook-end">
796
- </p>
797
- <p align="center">
798
- <a href="#记忆如何复合增长"><img src="https://img.shields.io/badge/1-自动命名-5D34F2?style=for-the-badge" alt="自动命名"></a>
799
- <a href="#记忆如何复合增长"><img src="https://img.shields.io/badge/2-索引-0EA5E9?style=for-the-badge" alt="索引"></a>
800
- <a href="#记忆如何复合增长"><img src="https://img.shields.io/badge/3-关联性-10B981?style=for-the-badge" alt="关联性"></a>
801
- <a href="#记忆如何复合增长"><img src="https://img.shields.io/badge/4-权重与衰减-F59E0B?style=for-the-badge" alt="权重与衰减"></a>
802
- <a href="#记忆如何复合增长"><img src="https://img.shields.io/badge/5-反馈回路-EF4444?style=for-the-badge" alt="反馈回路"></a>
803
- </p>
804
-
805
- ## `/arsave` 和 `/arstart`
806
-
807
- > **两个命令,ezpz。**
808
-
809
- | 命令 | 时机 | 功能 |
810
- |------|------|------|
811
- | **`/arsave`** | 会话结束时 | 写入日志 + 整合到记忆宫殿 + 更新感知 + 可选 git 推送 |
812
- | **`/arstart`** | 会话开始时 | 召回跨项目洞察 + 遍历宫殿 + 加载上下文 |
813
-
814
- 会话结束时输入 `/arsave`,所有内容自动保存。下次开始时输入 `/arstart`,所有上下文自动恢复。
815
-
816
- ```bash
817
- # 安装命令(一次性,仅 Claude Code)
818
- mkdir -p ~/.claude/commands
819
- curl -o ~/.claude/commands/arsave.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arsave.md
820
- curl -o ~/.claude/commands/arstart.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arstart.md
821
- ```
822
-
823
- ### 效果对比
824
-
825
- ```
826
- 没有 AgentRecall 有 AgentRecall
827
- ────────────── ────────────
828
-
829
- 第 1 天:构建单仓 第 1 天:/arstart → /arsave
830
- 第 2 天:"什么单仓?" 第 2 天:/arstart
831
- → 20 分钟重新解释 → 2 秒:加载所有决策
832
- → 智能体重复同样的错误 → 知道"不要版本膨胀"
833
- → 忘记你的优先级 → 知道"arsave 要放首位"
834
- → 遗漏一半的任务 → 自动推送两个仓库
835
- ```
836
-
837
- ### 三层价值
838
-
839
- **第一层(5 秒):** 让你的 AI agent 记住上次会话发生了什么。
840
-
841
- **第二层(30 秒):** 每次你纠正 agent——"不,不是那个版本"、"先问我"——这个纠正被永久存储,并在 agent 再犯同样错误之前被召回。10 次会话后,你的 agent 理解你的优先级、你的沟通风格、你的不可妥协项。
842
-
843
- **第三层(2 分钟):** [智能距离协议](https://github.com/Goldentrii/AgentRecall/wiki/Intelligent-Distance)。人类思维和 AI 行动之间的结构性鸿沟无法消除——但可以在每次会话中更好地穿越。纠正就是训练数据。200 行感知上限强制质量优于数量。跨项目洞察意味着学到一次的经验到处适用。
844
-
845
- ### 真实会话流程
846
-
847
- 以下来自一个真实的多日项目,人类给出了分散、非线性的指令。智能体全程使用 AgentRecall:
848
-
849
- ```
850
- 会话 1(周二) 会话 2(周三,不同的智能体)
851
- ────────── ────────────────────────
852
-
853
- /arstart /arstart
854
- │ │
855
- ├─ session_start() ──→ 身份 + 洞察 ├─ session_start() ──→ 加载周二
856
- │ 活跃房间 + 跨项目匹配 │ 架构决策(约 400 token),
857
- │ watch_for 警告 │ watch_for: "结构化输入"
858
- │ │
859
- ├─ recall("SDK CLI 版本") ──→ ├─ recall("SDK CLI 单仓") ──→
860
- │ • "结构化分散的输入" │ • "不要版本膨胀"
861
- │ • "先搜索再构建" │ • "arsave 放在最显眼的位置"
862
- │ • "模糊时询问,明确时执行" │
863
- │ ├─ 从会话 1 离开的地方
864
- ▼ │ 无缝继续
865
- 人类:"我们需要 SDK、CLI, │
866
- 更新 README,修复版本号" ▼
867
- │ 人类:"发布到 npm,
868
- ├─ check(goal="SDK+CLI+README", 更新两个 GitHub 仓库"
869
- │ confidence="medium") │
870
- │ 检测到 4 个任务项 ├─ 无需重新解释。
871
- │ → 呈现方案 → 人类确认 │ 智能体已经知道单仓结构、
872
- │ │ 包名和版本策略。
873
- ├─ 按顺序执行: │
874
- │ 1. 核心提取 ✓ └─ 2 分钟完成
875
- │ 2. 工具逻辑拆分 ✓ (没有 AgentRecall
876
- │ 3. MCP 封装 ✓ 需要 2-8 分钟冷启动)
877
- │ 4. SDK + CLI ✓
878
-
879
- /arsave
880
-
881
- └─ session_end(summary, insights, trajectory)
882
- → 日志 + 感知 + 宫殿 — 一次调用全部完成
883
- ```
884
-
885
- ---
886
-
887
- ## 为什么选择 AgentRecall
888
-
889
- **AgentRecall 不是记忆工具,而是学习循环。**
890
-
891
- 你的智能体在会话之间不是真的遗忘——它们是记不清楚、分不清主次,甚至听不懂你在说什么。AgentRecall 像人类记忆一样运作:把不重要的东西冬眠起来,但随时可以唤醒。更重要的是,它让智能体越用越懂你。
892
-
893
- 记忆是机制,理解才是目标。每次你纠正智能体 —— "不要那个版本"、"把这个部分放在最前面"、"做之前先问我" —— 这个纠正会被存储、加权、并在下次自动召回。10 个会话后,你的智能体不只是记住了你的项目,它理解了你的思维方式:你的优先级、你的沟通风格、你的底线。
894
-
895
- 这就是**智能距离协议** —— 不是消除人类与 AI 之间的差距(这个差距是结构性的),而是每次会话都导航得更好。
896
-
897
- - **你的智能体学会理解你的思维。** 人类本身就是不一致的 —— 我们会从 A 直接跳到 E,跳过 B、C、D。我们会忘记昨天说的话,会在句子中间改变优先级。AgentRecall 捕获每一次纠正,在下一个错误发生之前浮现。你的意图和智能体行为之间的差距,每次会话都在缩小。
898
-
899
- - **复合感知,而非无限日志。** 记忆上限 200 行。新洞察要么与已有的合并(增强),要么替换最弱的。100 个会话后,感知文件仍然是 200 行 —— 但每一行都承载着经过交叉验证的确认观察。
900
-
901
- - **跨项目召回。** 在一个项目中学到的教训适用于所有项目。上个月做了限流器?今天在另一个项目构建时,那个教训会自动浮现。
902
-
903
- - **近乎通用的兼容性。** MCP 服务器支持所有 MCP 兼容智能体(Claude Code、Cursor、Windsurf、VS Code、Codex)。SDK 支持任何 JS/TS 框架(LangChain、CrewAI、Vercel AI SDK、自定义智能体)。CLI 支持终端和 CI 工作流。一套记忆系统,覆盖所有场景。
904
-
905
- - **零云端,零遥测,全部本地。** 一切都是磁盘上的 markdown。在 Obsidian 中浏览,在终端中 grep,在 git 中版本管理。无需账户、API 密钥或锁定。
906
-
907
- ### 用例一:跳跃式思维的人类
908
-
909
- 一个真实会话,人类在两天项目中给出了非线性、分散的指令:
910
-
911
- > 人类:"我们需要 SDK、CLI,还有更新 README,哦对了 npm 版本号也错了,一起修"
912
-
913
- 没有 AgentRecall,智能体猜测优先级,遗漏项目。有 AgentRecall:
914
-
915
- | 智能体已经知道的 | 怎么知道的 |
916
- |---|---|
917
- | "这个人沟通是分散的 —— 先结构化成模块再执行" | 3 个先前会话的 `awareness_update` |
918
- | "模糊时询问,明确时执行" | 上周 `alignment_check` 存储的纠正 |
919
- | "不要版本膨胀 —— 这个人很在意语义化版本" | 会话中 `nudge` 捕获,立即召回 |
920
-
921
- 结果:智能体呈现结构化的 4 步方案,人类确认,零返工。没有 AgentRecall 的新智能体会猜错版本号、把最重要的功能埋在 README 深处、并且不测试就发布。
922
-
923
- ### 用例二:跨项目经验传递
924
-
925
- 一个工程师构建了带限流的代理服务器(项目 A)。三周后,开始构建 API 网关(项目 B)。
926
-
927
- ```
928
- 在项目 B 运行 /arstart:
929
- recall_insight:"限流防止成本失控"
930
- → 来源:项目 A,确认 3 次,严重性:critical
931
- → 适用场景:["api", "proxy", "rate-limit", "cost"]
932
- → 项目 A 的教训在项目 B 中自动浮现
933
- ```
934
-
935
- 工程师从未提到限流。AgentRecall 自动匹配项目上下文与全局洞察索引。
936
-
937
- ### 用例三:纠正只发生一次
938
-
939
- 会话 1:智能体把补丁版本设为 4.0.0。人类纠正:"这是版本膨胀,用 3.3.4。"
940
-
941
- 会话 2(第二天,不同的智能体):感知系统已包含"不要版本膨胀 —— 这个人在意保守的版本策略"。新智能体第一次就做对了。
942
-
943
- 没有 AgentRecall,同样的纠正需要一次又一次。有 AgentRecall,**每个纠正只发生一次。**
944
-
945
- ---
946
-
947
- ## 三种使用方式
948
-
949
- **MCP** — 面向 AI 智能体(Claude Code、Cursor、Windsurf、VS Code、Codex):
950
- ```bash
951
- claude mcp add --scope user agent-recall -- npx -y agent-recall-mcp
952
- ```
953
-
954
- **SDK** — 面向任何 JS/TS 应用(LangChain、CrewAI、Vercel AI SDK、自定义):
955
- ```typescript
956
- import { AgentRecall } from "agent-recall-sdk";
957
- const memory = new AgentRecall({ project: "my-app" });
958
- await memory.capture("用什么技术栈?", "Next.js + Postgres");
959
- ```
960
-
961
- **CLI** — 面向终端工作流和 CI:
962
- ```bash
963
- npx agent-recall-cli capture "用什么技术栈?" "Next.js + Postgres"
964
- npx agent-recall-cli palace walk --depth active
965
- ```
966
-
967
- ---
968
-
969
- ## AgentRecall 是什么?
970
-
971
- 一个**学习系统**,弥合人类思维方式与 AI 智能体工作方式之间的差距。不是日志,不是数据库——是一个复合循环,每一次纠正、决策和洞察都让下一次会话比上一次更好。
972
-
973
- **问题:** AI 智能体不是真的遗忘——它们主要是无法抓住人类以为的重点。记不清楚优先级,分不清主次,教训进入休眠状态,同样的误解重复发生因为没人存储那次纠正行为。你的意图、目标和智能体行为之间的差距和割裂导致最终项目效果不佳。
974
-
975
- **解决方案:** AgentRecall 将知识存储在五层记忆金字塔中——从快速捕获到跨项目洞察——并通过强制压缩让记忆随时间增值。但更重要的是,它缩小了**智能距离**差距:每一次人类的纠正都被捕获、加权、并在智能体犯同样错误之前被召回。
976
-
977
- | 没有 AgentRecall | 有 AgentRecall |
978
- |-----------------|---------------|
979
- | 智能体忘记昨天的决策 | 决策存在宫殿房间,冷启动时加载 |
980
- | 跨会话重复同样的错误 | `recall_insight` 工作前自动呈现过去教训 |
981
- | 每次开始需要 5 分钟恢复上下文 | 2 秒冷启动,从宫殿加载(~200 token) |
982
- | 平面记忆文件无限增长 | 200 行感知上限,强制合并或替换 |
983
- | 知识锁在单个项目 | 跨项目洞察按关键词匹配 |
203
+ > 持久复合记忆 + 自动纠正捕获。适用于 Claude Code、Cursor、Windsurf、Codex 等 MCP 兼容智能体。
984
204
 
985
205
  ---
986
206
 
987
207
  ## 快速开始
988
208
 
989
- ### MCP 服务器(面向 AI 智能体)
990
-
991
209
  ```bash
992
210
  # Claude Code
993
211
  claude mcp add --scope user agent-recall -- npx -y agent-recall-mcp
994
212
 
995
213
  # Cursor — .cursor/mcp.json
996
214
  { "mcpServers": { "agent-recall": { "command": "npx", "args": ["-y", "agent-recall-mcp"] } } }
997
-
998
- # VS Code — .vscode/mcp.json
999
- { "servers": { "agent-recall": { "command": "npx", "args": ["-y", "agent-recall-mcp"] } } }
1000
-
1001
- # Codex — ~/.codex/config.toml
1002
- codex mcp add agent-recall -- npx -y agent-recall-mcp
1003
215
  ```
1004
216
 
1005
- **Claude Code 技能安装:**
217
+ **安装斜杠命令(Claude Code):**
1006
218
  ```bash
1007
- mkdir -p ~/.claude/skills/agent-recall
1008
- curl -o ~/.claude/skills/agent-recall/SKILL.md \
1009
- https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/SKILL.md
1010
- ```
1011
-
1012
- ### SDK(面向 JS/TS 应用)
1013
-
1014
- ```bash
1015
- npm install agent-recall-sdk
1016
- ```
1017
-
1018
- ```typescript
1019
- import { AgentRecall } from "agent-recall-sdk";
1020
-
1021
- const memory = new AgentRecall({ project: "my-app" });
1022
- await memory.capture("用什么 ORM?", "Drizzle — 类型安全、轻量");
1023
- await memory.palaceWrite("architecture", "技术栈:Next.js 16 + Drizzle + Postgres");
1024
- const context = await memory.coldStart();
1025
- ```
1026
-
1027
- ### CLI(面向终端和 CI)
1028
-
1029
- ```bash
1030
- npm install -g agent-recall-cli
1031
-
1032
- ar capture "用什么 ORM?" "Drizzle" --project my-app
1033
- ar palace walk --depth active
1034
- ar insight "构建认证中间件"
219
+ mkdir -p ~/.claude/commands
220
+ curl -o ~/.claude/commands/arsave.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arsave.md
221
+ curl -o ~/.claude/commands/arstart.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arstart.md
222
+ curl -o ~/.claude/commands/arsaveall.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arsaveall.md
1035
223
  ```
1036
224
 
1037
225
  ---
1038
226
 
1039
- ## 智能体使用流程
1040
-
1041
- ### 会话开始 (`/arstart`)
1042
- ```
1043
- session_start() → 身份、洞察、活跃房间、跨项目匹配、最近活动、watch_for 预警 — 一次调用
1044
- ```
1045
-
1046
- ### 工作中
1047
- ```
1048
- remember("我们决定用 GraphQL 替代 REST") → 自动分类并路由到正确的存储
1049
- recall("认证设计") → 搜索所有存储,排名结果
1050
- check(goal="构建认证", confidence="medium") → 验证理解,获取预警
1051
- ```
227
+ ## 三个命令
1052
228
 
1053
- ### 会话结束 (`/arsave`)
1054
- ```
1055
- session_end(summary="...", insights=[...], trajectory="...") → 日志 + 感知 + 整合
1056
- ```
229
+ | 命令 | 时机 | 功能 |
230
+ |------|------|------|
231
+ | **`/arsave`** | 会话结束时 | 写入日志 + 整合到记忆宫殿 + 更新感知 |
232
+ | **`/arstart`** | 会话开始时 | 召回跨项目洞察 + 遍历宫殿 + 加载上下文 |
233
+ | **`/arsaveall`** | 一天结束时(多会话) | 一次性批量保存所有并行会话 |
1057
234
 
1058
235
  ---
1059
236
 
1060
- ## 5 个 MCP 工具
237
+ ## 自动 Hooks
1061
238
 
1062
- AgentRecall 目前只向 agent 提供 5 个工具。每个工具内部组合多个子系统 — agent 不需要了解内部管道。
239
+ 配置一次,永久自动保存。四个 hook 完全覆盖会话生命周期:
1063
240
 
1064
- | 工具 | 功能 |
1065
- |------|------|
1066
- | `session_start` | 加载项目上下文。返回身份、洞察、活跃房间、跨项目匹配、最近活动、以及来自历史纠正的 `watch_for` 预警。一次调用,约 400 token。 |
1067
- | `remember` | 保存记忆。自动分类内容(bug 修复、架构决策、洞察、会话笔记)并路由到正确的存储。自动生成语义化名称便于未来检索。 |
1068
- | `recall` | 通过**互惠排名融合(RRF)**一次搜索所有记忆 每个来源内部独立排名,再按位置合并,避免任何单一来源靠原始分数主导结果。返回带稳定 ID 的排名结果。支持 `feedback` 评价:正面提升排名,负面降低。查询感知 — 某次搜索的反馈不影响无关查询。 |
1069
- | `session_end` | 一次调用保存全部。写入日志、更新感知、整合到宫殿、归档被替换的洞察(不删除 支持复活)。 |
1070
- | `check` | 记录你对人类意图的理解。返回历史纠正模式的 `watch_for` 预警。支持记录 `human_correction` 和 `delta`。3+ 次的强模式自动提升为感知洞察。 |
1071
-
1072
- ### 旧版工具
1073
-
1074
- 原始 22 个子系统工具(palace_write、journal_capture、awareness_update 等)通过 SDK 和 CLI 仍然可用,适用于向后兼容和高级用例。MCP 服务器默认不注册这些工具。
241
+ | Hook | 触发时机 | 功能 |
242
+ |------|---------|------|
243
+ | `hook-start` | 会话开始 | 打印身份 + 洞察 + `watch_for` 警告 |
244
+ | `hook-correction` | 每条用户消息 | 静默捕获纠正信号,无需 agent 手动调用 |
245
+ | `hook-ambient` | 每条用户消息 | 提取关键词 自动召回 注入上下文 |
246
+ | `hook-end` | 会话关闭 | 追加轻量级结束日志 |
1075
247
 
1076
248
  ---
1077
249
 
1078
- ## 记忆如何复合增长
1079
-
1080
- <p align="center">
1081
- <a href="#1-自动命名"><img src="https://img.shields.io/badge/1-自动命名-5D34F2?style=for-the-badge" alt="自动命名"></a>
1082
- <a href="#2-索引"><img src="https://img.shields.io/badge/2-索引-0EA5E9?style=for-the-badge" alt="索引"></a>
1083
- <a href="#3-关联性"><img src="https://img.shields.io/badge/3-关联性-10B981?style=for-the-badge" alt="关联性"></a>
1084
- <a href="#4-权重与衰减"><img src="https://img.shields.io/badge/4-权重与衰减-F59E0B?style=for-the-badge" alt="权重与衰减"></a>
1085
- <a href="#5-反馈回路"><img src="https://img.shields.io/badge/5-反馈回路-EF4444?style=for-the-badge" alt="反馈回路"></a>
1086
- </p>
1087
-
1088
- > 记忆不是清单,而是一个 1+1+1 > 3 的复合系统。每个子系统喂养下一个 — 命名使检索成为可能,检索使反馈成为可能,反馈使排名成为可能,排名让正确的记忆在正确的时间浮现。10 个会话后,系统知道的比任何单条记忆都多。
1089
-
1090
- ### 1. 自动命名
1091
-
1092
- Agent 在保存的瞬间对内容理解最深。AgentRecall 把这种理解捕获为语义化的名称 — 不是 `"mcp-verified"` 而是 `"verified-agentrecall-mcp-22tools-functional"`。
1093
-
1094
- ```
1095
- 内容: "修复了支付处理器在退款时崩溃的严重 bug"
1096
- → 类型检测: bug-fix
1097
- → 关键词提取: payment, processor, crashed, refunds
1098
- → 生成名称: bug-fix-payment-processor-crashed
1099
- ```
1100
-
1101
- 好的命名本身就是检索的第一层。一个命名良好的记忆,不需要搜索算法就能被找到 80%。
1102
-
1103
- ### 2. 索引
1104
-
1105
- 每条记忆在三个索引系统中都有地址:
1106
-
1107
- | 索引 | 追踪什么 | Token 开销 |
1108
- |------|---------|-----------|
1109
- | **宫殿索引** | 房间目录 + 显著性评分 | 扫描约 50 token |
1110
- | **洞察索引** | 跨项目教训 + 关键词匹配 | 查询约 30 token |
1111
- | **感知文档** | 200 行复合文档(强制合并) | 约 200 token,但每一行都承载交叉验证的权重 |
1112
-
1113
- 索引是轻量指针。Agent 先扫描索引,只在需要时才加载完整内容。
1114
-
1115
- ### 3. 关联性
1116
-
1117
- 相关的记忆会自动连接 — 无需手写 wikilinks。
1118
-
1119
- ```
1120
- Agent 写入: "JWT 刷新令牌轮换防止会话固定攻击"
1121
- → 关键词: jwt, refresh, rotation, session
1122
- → "architecture" 房间标签: ["technical"]
1123
- → "knowledge" 房间有 "session management" 教训
1124
- → 自动创建边: architecture ←→ knowledge (权重 0.3)
1125
- ```
1126
-
1127
- 当你 `recall("会话安全")` 时,系统不只是关键词匹配 — 它沿着边跳 1 步,从关联房间中浮现相关记忆。关联性把孤立的记忆变成知识图谱。
1128
-
1129
- ### 4. 权重与衰减
1130
-
1131
- 不是所有记忆都平等。显著性评分确保最重要的记忆先浮现:
250
+ ## 6 个 MCP 工具
1132
251
 
1133
- ```
1134
- 显著性 = 时效性(0.30) + 访问频率(0.25) + 连接数(0.20) + 紧迫性(0.15) + 重要性(0.10)
1135
- ```
1136
-
1137
- - 架构决策以 0.98/天 衰减(持久)。阻塞项以 0.90/天 衰减(短暂)。
1138
- - 你实际访问的记忆越来越强。从不回顾的记忆逐渐淡化。
1139
- - 被替换的洞察不会消亡 — 它们进入归档。如果未来的洞察匹配,它们会复活。
1140
-
1141
- `recall` 基于**艾宾浩斯遗忘曲线**(1885)`R(t) = e^(−t/S)` 对不同记忆类型设定不同衰减强度:
1142
-
1143
- | 记忆类型 | S(天) | 1天后保留率 | 1周后保留率 |
1144
- |----------|---------|------------|------------|
1145
- | 日志(情景记忆) | 2 | 60% | ~7% |
1146
- | 知识 / Bug 修复(程序记忆) | 180 | 99% | 96% |
1147
- | 宫殿 / 架构决策(语义记忆) | 9999 | ≈100% | ≈100% |
1148
-
1149
- 旧日志的噪音在数天内消退,架构决策永久保留。相同查询,始终得到正确结果。
1150
-
1151
- ### 5. 反馈回路
1152
-
1153
- 系统通过**贝叶斯 Beta 分布**学习什么有用、什么没用——这是从二元观察中估计"真实有用性"的数学最优解(`E[Beta(α,β)] = (pos+1)/(pos+neg+2)`):
1154
-
1155
- ```
1156
- 会话 1: recall("认证设计") → 返回 5 条结果
1157
- Agent 评价: 结果 #1 有用, 结果 #3 没用
1158
- → 存入 feedback-log.json(带查询上下文)
1159
-
1160
- 会话 2: recall("认证模式") → 类似查询
1161
- → 结果 #1: Beta(2,1) → E[U]=0.67 → ×1.33 分数倍增
1162
- → 结果 #3: Beta(1,2) → E[U]=0.33 → ×0.67 分数惩罚
1163
- → 排名变化: 有用的记忆上升,噪音下沉
1164
- ```
1165
-
1166
- 无反馈的条目保持中性(×1.0)。反馈是查询感知的 — 把一条结果标记为"对认证设计没用"不会惩罚它在"数据库设计"中的表现。系统按上下文学习,而非全局惩罚。
1167
-
1168
- ### 复合效应
1169
-
1170
- ```
1171
- 会话 1: 保存 3 条记忆(自动命名、索引、创建边)
1172
- 会话 5: recall 浮现会话 1-4 的记忆,反馈优化排名
1173
- 会话 10: watch_for 在错误重复之前警告 agent
1174
- 会话 20: 感知包含 10 条交叉验证的洞察(从 40+ 条原始观察合并)
1175
- 会话 50: Agent 了解你的优先级、盲点和沟通风格
1176
- — 不是因为被告知,而是因为每次纠正都在复合增长
1177
- ```
1178
-
1179
- 每一层放大其他层。自动命名让索引有意义。索引让关联性成为可能。关联性让检索精准。精准检索产生有意义的反馈。反馈让下一次检索更好。循环复合增长。
1180
-
1181
- ---
1182
-
1183
- ## SDK API
1184
-
1185
- `agent-recall-sdk` 提供 `AgentRecall` 类 — 完整记忆系统的编程接口。可用于 LangChain、CrewAI、Vercel AI SDK 或任何自定义 JS/TS 智能体框架。
1186
-
1187
- ```typescript
1188
- import { AgentRecall } from "agent-recall-sdk";
1189
- const ar = new AgentRecall({ project: "my-project" });
1190
- ```
1191
-
1192
- | 方法 | 说明 |
252
+ | 工具 | 功能 |
1193
253
  |------|------|
1194
- | `capture(question, answer, opts?)` | 快速问答捕获(L1 记忆) |
1195
- | `journalWrite(content, opts?)` | 写入每日日志 |
1196
- | `coldStart()` | 宫殿优先上下文加载(~200 token) |
1197
- | `palaceWrite(room, content, opts?)` | 写入房间,自动扇出交叉引用 |
1198
- | `palaceRead(room?, topic?)` | 读取房间内容 |
1199
- | `walk(depth?, focus?)` | 渐进式宫殿漫步 |
1200
- | `awarenessUpdate(insights, opts?)` | 复合新洞察到感知系统 |
1201
- | `recallInsight(context, opts?)` | 跨项目洞察召回 |
1202
- | `alignmentCheck(input)` | 记录置信度和假设 |
1203
- | `synthesize(opts?)` | L3 合成,可选宫殿整合 |
254
+ | `session_start` | 加载项目上下文,返回身份、洞察、活跃房间、跨项目匹配、`watch_for` 警告 |
255
+ | `remember` | 保存记忆,自动分类路由到正确存储 |
256
+ | `recall` | RRF 融合搜索所有存储,结果可反馈调权 |
257
+ | `session_end` | 一次调用保存所有:日志 + 感知 + 宫殿整合 |
258
+ | `check` | 记录 agent 对用户意图的理解,返回历史纠正的 `watch_for` 模式 |
259
+ | `digest` | 上下文缓存——存储预计算分析结果,避免重复推理。**重复分析节省 83% token** |
1204
260
 
1205
261
  ---
1206
262
 
1207
- ## CLI 命令
263
+ ## 基准测试(诚实说明)
1208
264
 
1209
- `agent-recall-cli` 提供 `ar` 命令,用于终端工作流和 CI 管道。
265
+ > 以下数据为建模估算,并非长期生产数据。简单任务中 AR 是纯开销;3+ 会话后开始回本,随后持续节省。
1210
266
 
1211
- ```bash
1212
- # 日志
1213
- ar read [--date YYYY-MM-DD] [--section <name>]
1214
- ar write <content> [--section <name>]
1215
- ar capture <question> <answer> [--tags tag1,tag2]
1216
- ar search <query> [--include-palace]
1217
- ar rollup [--min-age-days N] [--dry-run]
1218
-
1219
- # 宫殿
1220
- ar palace read [<room>]
1221
- ar palace write <room> <content> [--importance high|medium|low]
1222
- ar palace walk [--depth identity|active|relevant|full]
1223
- ar palace search <query>
1224
-
1225
- # 感知与洞察
1226
- ar awareness read
1227
- ar awareness update --insight "标题" --evidence "证据" --applies-when kw1,kw2
1228
- ar insight <context> [--limit N]
1229
-
1230
- # 全局选项
1231
- --root <path> 存储根目录(默认:~/.agent-recall)
1232
- --project <slug> 项目覆盖
1233
- ```
1234
-
1235
- ---
1236
-
1237
- ## 架构
1238
-
1239
- ### 五层记忆模型
1240
-
1241
- ```
1242
- L1: 工作记忆 journal_capture 「发生了什么」
1243
- L2: 情景记忆 journal_write 「这意味着什么」
1244
- L3: 记忆宫殿 palace_write / walk 「跨会话的知识」
1245
- L4: 感知系统 awareness_update 「复合的洞察」
1246
- L5: 洞察索引 recall_insight 「跨项目的经验」
1247
- ```
1248
-
1249
- ### 核心机制
1250
-
1251
- **扇出写入** — 写入一个房间,相关房间通过 `[[wikilinks]]` 自动更新交叉引用。零 LLM 成本。
1252
-
1253
- **显著性评分** — `时效性(0.30) + 访问频率(0.25) + 连接数(0.20) + 紧迫性(0.15) + 重要性(0.10)`。高显著性房间优先展示,低于阈值自动归档。
1254
-
1255
- **复合感知** — `awareness.md` 上限 200 行。新洞察与相似的合并(增强),与不相似的竞争(最低确认次数的被替换)。约束创造压缩,压缩创造复合。
267
+ | 场景 | 无 AR | 有 AR | 节省 |
268
+ |------|:-----:|:-----:|:----:|
269
+ | A:简单(2 次会话,0 次纠正) | 567 | 1,131 | **+99% 开销** |
270
+ | B:中等(5 次会话,1 次纠正) | 6,220 | 4,382 | **-30%** |
271
+ | C:复杂(20 次会话,5 次纠正) | 40,910 | 17,520 | **-57%** |
272
+ | D:多 agent(3 agent × 5 次) | 20,781 | 13,140 | **-37%** |
273
+ | E:Digest 缓存(重复分析) | ~2,400 | ~400 | **-83%** |
1256
274
 
1257
- **跨项目洞察召回** 通过关键词将洞察映射到场景。`recall_insight("构建质量检查")` 返回来自任何项目的相关教训。
1258
-
1259
- **Obsidian 兼容** — YAML frontmatter + `[[wikilinks]]`。将 `palace/` 作为 Obsidian vault 打开即可。零 Obsidian 依赖。
1260
-
1261
- ---
1262
-
1263
- ## 平台兼容性
1264
-
1265
- | 平台 | MCP | SDK | CLI | 说明 |
1266
- |------|:---:|:---:|:---:|------|
1267
- | Claude Code | ✅ | ✅ | ✅ | 完整支持 — MCP + 技能 + 命令 |
1268
- | Cursor | ✅ | ✅ | ✅ | MCP via .cursor/mcp.json |
1269
- | VS Code (Copilot) | ✅ | ✅ | ✅ | MCP via .vscode/mcp.json |
1270
- | Windsurf | ✅ | ✅ | ✅ | MCP via mcp_config.json |
1271
- | OpenAI Codex | ✅ | ✅ | ✅ | `codex mcp add` |
1272
- | LangChain / CrewAI | — | ✅ | — | SDK 集成到你的 chain 中 |
1273
- | Vercel AI SDK | — | ✅ | — | SDK 在 server actions 中使用 |
1274
- | CI / GitHub Actions | — | — | ✅ | `npx agent-recall-cli` |
1275
- | 任何 MCP 智能体 | ✅ | — | — | 标准 MCP 协议 |
1276
-
1277
- ---
1278
-
1279
- ## 文档
1280
-
1281
- | 文档 | 说明 |
1282
- |------|------|
1283
- | [智能距离协议](docs/intelligent-distance-protocol.md) | 基础理论 — 人类与 AI 之间的差距是结构性的,如何减少两个物种之间的沟通信息损失 |
1284
- | [评分设计原理](docs/SCORING.md) | 评分系统的工作原理 — RRF、艾宾浩斯、Beta 分布及其修复的 bug |
1285
- | [MCP 适配器规范](docs/mcp-adapter-spec.md) | 基于 AgentRecall 构建适配器的技术规范 |
1286
- | [SDK 设计](docs/sdk-design.md) | SDK 架构设计文档 |
1287
- | [v3.4 升级说明](UPGRADE-v3.4.md) | 周报压缩、宫殿优先冷启动、提升验证 |
275
+ **盈亏平衡点:约 3-4 次会话。**
1288
276
 
1289
277
  ---
1290
278
 
1291
- ## 贡献
1292
-
1293
- 由 [tongwu](https://github.com/Goldentrii) 在 [Novada](https://www.novada.com) 构建。
1294
-
1295
- - Issues & 反馈:[GitHub Issues](https://github.com/Goldentrii/AgentRecall/issues)
1296
- - 邮箱:[tong.wu@novada.com](mailto:tong.wu@novada.com)
1297
- - 网站:[novada.com](https://www.novada.com)
279
+ ## 相关链接
1298
280
 
1299
- MIT 许可证。
281
+ - **完整文档:** [主 README](../../README.md)
282
+ - **SDK API:** [agent-recall-core](../core/README.md)
283
+ - **GitHub:** [Goldentrii/AgentRecall](https://github.com/Goldentrii/AgentRecall)
284
+ - **问题反馈:** [GitHub Issues](https://github.com/Goldentrii/AgentRecall/issues)