agent-working-memory 0.3.0
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.
- package/LICENSE +21 -0
- package/README.md +311 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/routes.d.ts +53 -0
- package/dist/api/routes.d.ts.map +1 -0
- package/dist/api/routes.js +388 -0
- package/dist/api/routes.js.map +1 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +245 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/decay.d.ts +36 -0
- package/dist/core/decay.d.ts.map +1 -0
- package/dist/core/decay.js +38 -0
- package/dist/core/decay.js.map +1 -0
- package/dist/core/embeddings.d.ts +33 -0
- package/dist/core/embeddings.d.ts.map +1 -0
- package/dist/core/embeddings.js +76 -0
- package/dist/core/embeddings.js.map +1 -0
- package/dist/core/hebbian.d.ts +38 -0
- package/dist/core/hebbian.d.ts.map +1 -0
- package/dist/core/hebbian.js +74 -0
- package/dist/core/hebbian.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/query-expander.d.ts +24 -0
- package/dist/core/query-expander.d.ts.map +1 -0
- package/dist/core/query-expander.js +58 -0
- package/dist/core/query-expander.js.map +1 -0
- package/dist/core/reranker.d.ts +25 -0
- package/dist/core/reranker.d.ts.map +1 -0
- package/dist/core/reranker.js +75 -0
- package/dist/core/reranker.js.map +1 -0
- package/dist/core/salience.d.ts +30 -0
- package/dist/core/salience.d.ts.map +1 -0
- package/dist/core/salience.js +81 -0
- package/dist/core/salience.js.map +1 -0
- package/dist/engine/activation.d.ts +38 -0
- package/dist/engine/activation.d.ts.map +1 -0
- package/dist/engine/activation.js +516 -0
- package/dist/engine/activation.js.map +1 -0
- package/dist/engine/connections.d.ts +31 -0
- package/dist/engine/connections.d.ts.map +1 -0
- package/dist/engine/connections.js +74 -0
- package/dist/engine/connections.js.map +1 -0
- package/dist/engine/consolidation-scheduler.d.ts +31 -0
- package/dist/engine/consolidation-scheduler.d.ts.map +1 -0
- package/dist/engine/consolidation-scheduler.js +115 -0
- package/dist/engine/consolidation-scheduler.js.map +1 -0
- package/dist/engine/consolidation.d.ts +62 -0
- package/dist/engine/consolidation.d.ts.map +1 -0
- package/dist/engine/consolidation.js +368 -0
- package/dist/engine/consolidation.js.map +1 -0
- package/dist/engine/eval.d.ts +22 -0
- package/dist/engine/eval.d.ts.map +1 -0
- package/dist/engine/eval.js +79 -0
- package/dist/engine/eval.js.map +1 -0
- package/dist/engine/eviction.d.ts +29 -0
- package/dist/engine/eviction.d.ts.map +1 -0
- package/dist/engine/eviction.js +86 -0
- package/dist/engine/eviction.js.map +1 -0
- package/dist/engine/index.d.ts +7 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +7 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/retraction.d.ts +32 -0
- package/dist/engine/retraction.d.ts.map +1 -0
- package/dist/engine/retraction.js +77 -0
- package/dist/engine/retraction.js.map +1 -0
- package/dist/engine/staging.d.ts +33 -0
- package/dist/engine/staging.d.ts.map +1 -0
- package/dist/engine/staging.js +63 -0
- package/dist/engine/staging.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +24 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +532 -0
- package/dist/mcp.js.map +1 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/sqlite.d.ts +116 -0
- package/dist/storage/sqlite.d.ts.map +1 -0
- package/dist/storage/sqlite.js +750 -0
- package/dist/storage/sqlite.js.map +1 -0
- package/dist/types/agent.d.ts +30 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +23 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/checkpoint.d.ts +50 -0
- package/dist/types/checkpoint.d.ts.map +1 -0
- package/dist/types/checkpoint.js +8 -0
- package/dist/types/checkpoint.js.map +1 -0
- package/dist/types/engram.d.ts +165 -0
- package/dist/types/engram.d.ts.map +1 -0
- package/dist/types/engram.js +8 -0
- package/dist/types/engram.js.map +1 -0
- package/dist/types/eval.d.ts +84 -0
- package/dist/types/eval.d.ts.map +1 -0
- package/dist/types/eval.js +11 -0
- package/dist/types/eval.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +55 -0
- package/src/api/index.ts +1 -0
- package/src/api/routes.ts +528 -0
- package/src/cli.ts +260 -0
- package/src/core/decay.ts +61 -0
- package/src/core/embeddings.ts +82 -0
- package/src/core/hebbian.ts +91 -0
- package/src/core/index.ts +3 -0
- package/src/core/query-expander.ts +64 -0
- package/src/core/reranker.ts +99 -0
- package/src/core/salience.ts +95 -0
- package/src/engine/activation.ts +577 -0
- package/src/engine/connections.ts +101 -0
- package/src/engine/consolidation-scheduler.ts +123 -0
- package/src/engine/consolidation.ts +443 -0
- package/src/engine/eval.ts +100 -0
- package/src/engine/eviction.ts +99 -0
- package/src/engine/index.ts +6 -0
- package/src/engine/retraction.ts +98 -0
- package/src/engine/staging.ts +72 -0
- package/src/index.ts +100 -0
- package/src/mcp.ts +635 -0
- package/src/storage/index.ts +1 -0
- package/src/storage/sqlite.ts +893 -0
- package/src/types/agent.ts +65 -0
- package/src/types/checkpoint.ts +44 -0
- package/src/types/engram.ts +194 -0
- package/src/types/eval.ts +98 -0
- package/src/types/index.ts +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CompleteIdeas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# AgentWorkingMemory (AWM)
|
|
2
|
+
|
|
3
|
+
**Cognitive memory for AI agents — so they stop forgetting everything between conversations.**
|
|
4
|
+
|
|
5
|
+
If you've used Claude, ChatGPT, or any AI coding assistant for more than a day, you've hit the wall: it forgets. Every new conversation starts from zero. You re-explain your project, your stack, your preferences, your decisions — over and over. Long conversations go circular as the AI loses context from earlier in the same chat. It's like working with the smartest person in the world who gets amnesia at the end of every shift.
|
|
6
|
+
|
|
7
|
+
AWM fixes that. It gives AI agents a persistent, self-organizing memory that works like a sharp senior developer's brain — not a search engine. It decides what's worth remembering (77% of noise filtered at write time), connects related knowledge through associative links that strengthen with use, and periodically consolidates memories the way your brain does during sleep: reinforcing important patterns, building cross-topic shortcuts, and letting unused noise fade away. The result is an AI that remembers your architecture decisions from three weeks ago, surfaces relevant context without being asked, and doesn't waste your time re-learning things it already knew.
|
|
8
|
+
|
|
9
|
+
## How It's Different
|
|
10
|
+
|
|
11
|
+
Most "memory for AI" projects are glorified vector databases — they embed everything, retrieve by cosine similarity, and dump results into the prompt. That's a search engine, not memory. AWM is fundamentally different:
|
|
12
|
+
|
|
13
|
+
| Feature | Typical RAG/Vector Store | AWM |
|
|
14
|
+
|---------|------------------------|-----|
|
|
15
|
+
| **What gets stored** | Everything | Only salient events (salience scoring filters 77% of noise at write time) |
|
|
16
|
+
| **Retrieval** | Single-signal cosine similarity | 10-phase pipeline: BM25 + vectors + cross-encoder reranking + graph walk + temporal decay |
|
|
17
|
+
| **Connections** | None | Hebbian associative edges that strengthen when memories are co-retrieved |
|
|
18
|
+
| **Over time** | Grows forever, gets noisier | Sleep cycle consolidation: strengthens clusters, prunes noise, builds cross-topic bridges |
|
|
19
|
+
| **Forgetting** | Manual cleanup or TTL | Cognitive forgetting: unretrieved memories fade, confirmed knowledge persists for months |
|
|
20
|
+
| **Feedback** | None | Explicit useful/not-useful signals tune confidence, affecting retrieval rank and forgetting resistance |
|
|
21
|
+
| **Self-correction** | Delete and re-insert | Retraction system: wrong memories get invalidated, corrections link back, confidence penalties propagate |
|
|
22
|
+
|
|
23
|
+
AWM is modeled on established cognitive science — ACT-R activation decay, Hebbian learning, complementary learning systems, and hippocampal memory staging. It's not a database with a prompt wrapper; it's a cognitive architecture that gets better the more you use it.
|
|
24
|
+
|
|
25
|
+
## Benchmarks
|
|
26
|
+
|
|
27
|
+
| Eval | Score | What it tests |
|
|
28
|
+
|------|-------|---------------|
|
|
29
|
+
| Edge Cases | **100% (34/34)** | 9 failure modes: hub toxicity, flashbulb distortion, narcissistic interference, identity collision, contradiction preservation, bridge overshoot, noise forgetting benefit |
|
|
30
|
+
| Stress Test | **92.3% (48/52)** | 500 memories, 100 sleep cycles, catastrophic forgetting, adversarial spam, recovery |
|
|
31
|
+
| A/B Test | **AWM 100% vs Baseline 83%** | 100 project events, 24 recall questions |
|
|
32
|
+
| Self-Test | **97.4% EXCELLENT** | 31 pipeline component checks |
|
|
33
|
+
| Workday | **86.7% GOOD** | 43 memories across 4 simulated work sessions |
|
|
34
|
+
| Real-World | **93.1% EXCELLENT** | 300 code chunks from a 71K-line production monorepo |
|
|
35
|
+
| Token Savings | **64.5% savings** | Memory-guided context vs full conversation history |
|
|
36
|
+
|
|
37
|
+
## Getting Started
|
|
38
|
+
|
|
39
|
+
### Prerequisites
|
|
40
|
+
|
|
41
|
+
You need **Node.js 20 or newer** installed on your machine. That's it — no Python, no Docker, no API keys, no cloud accounts.
|
|
42
|
+
|
|
43
|
+
**Don't have Node.js?** Download the LTS version from [nodejs.org](https://nodejs.org). Run `node --version` in your terminal to check — if you see `v20.x.x` or higher, you're good.
|
|
44
|
+
|
|
45
|
+
### Step 1: Get the Code
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/CompleteIdeas/AgentWorkingMemory.git
|
|
49
|
+
cd AgentWorkingMemory
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Step 2: Install Dependencies
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm install
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
This installs everything AWM needs. Takes about a minute depending on your internet connection.
|
|
59
|
+
|
|
60
|
+
### Step 3: Start the Server
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npx tsx src/index.ts
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**The first time you run this, it downloads three small ML models (~124MB total).** These are cached locally in a `models/` folder — you'll never need to download them again. No API keys, no cloud calls. Everything runs on your machine.
|
|
67
|
+
|
|
68
|
+
Once you see `AWM server listening on port 8400`, the server is ready.
|
|
69
|
+
|
|
70
|
+
### Step 4: Try It Out
|
|
71
|
+
|
|
72
|
+
Open a second terminal. Write a memory:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
curl -X POST http://localhost:8400/memory/write \
|
|
76
|
+
-H "Content-Type: application/json" \
|
|
77
|
+
-d '{
|
|
78
|
+
"agentId": "my-agent",
|
|
79
|
+
"concept": "Express error handling",
|
|
80
|
+
"content": "Use centralized error middleware as the last app.use()",
|
|
81
|
+
"eventType": "causal",
|
|
82
|
+
"surprise": 0.5,
|
|
83
|
+
"causalDepth": 0.7
|
|
84
|
+
}'
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Now recall it by asking a question:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
curl -X POST http://localhost:8400/memory/activate \
|
|
91
|
+
-H "Content-Type: application/json" \
|
|
92
|
+
-d '{
|
|
93
|
+
"agentId": "my-agent",
|
|
94
|
+
"context": "How should I handle errors in my Express API?"
|
|
95
|
+
}'
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
You should see the memory come back with a relevance score and an explanation of why it matched. That's the 10-phase retrieval pipeline doing its thing.
|
|
99
|
+
|
|
100
|
+
### Tips for Technical People
|
|
101
|
+
|
|
102
|
+
- **Change the port:** `AWM_PORT=3000 npx tsx src/index.ts`
|
|
103
|
+
- **Custom database location:** `AWM_DB_PATH=/path/to/memory.db npx tsx src/index.ts`
|
|
104
|
+
- **Run unit tests:** `npx vitest run` (47 tests, no server needed)
|
|
105
|
+
- **Run eval suite:** Start the server first, then `npm run test:self` in another terminal
|
|
106
|
+
- **Data lives in a single file:** `memory.db` in the project root (SQLite). Back it up, move it, delete it to start fresh.
|
|
107
|
+
- **Models are cached locally:** First run downloads to `models/`. No network calls after that.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Using with Claude Code (MCP Integration)
|
|
112
|
+
|
|
113
|
+
This is the main use case — giving Claude Code persistent memory across conversations. AWM connects to Claude Code through the [Model Context Protocol (MCP)](https://modelcontextprotocol.io), which lets Claude use AWM's memory tools directly.
|
|
114
|
+
|
|
115
|
+
### Step 1: Find your project's MCP config
|
|
116
|
+
|
|
117
|
+
In the project where you want Claude to have memory, create or edit `.mcp.json` in the project root:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"mcpServers": {
|
|
122
|
+
"agent-working-memory": {
|
|
123
|
+
"command": "npx",
|
|
124
|
+
"args": ["tsx", "C:/path/to/AgentWorkingMemory/src/mcp.ts"],
|
|
125
|
+
"env": {
|
|
126
|
+
"AWM_DB_PATH": "C:/path/to/memory.db",
|
|
127
|
+
"AWM_AGENT_ID": "claude-code"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**Replace the paths** with the actual location where you cloned AgentWorkingMemory. Use forward slashes even on Windows.
|
|
135
|
+
|
|
136
|
+
### Step 2: Restart Claude Code
|
|
137
|
+
|
|
138
|
+
Close and reopen Claude Code (or run `/mcp` to reload). Claude will now have 9 new tools:
|
|
139
|
+
|
|
140
|
+
| Tool | What it does |
|
|
141
|
+
|------|-------------|
|
|
142
|
+
| `memory_write` | Store a memory with salience metadata |
|
|
143
|
+
| `memory_recall` | Retrieve relevant memories by context |
|
|
144
|
+
| `memory_feedback` | Tell AWM if a memory was useful or not |
|
|
145
|
+
| `memory_retract` | Mark a wrong memory as invalid |
|
|
146
|
+
| `memory_stats` | View memory health metrics |
|
|
147
|
+
| `memory_task_add` | Create a prioritized task |
|
|
148
|
+
| `memory_task_update` | Change task status/priority |
|
|
149
|
+
| `memory_task_list` | List tasks by status |
|
|
150
|
+
| `memory_task_next` | Get the highest-priority actionable task |
|
|
151
|
+
|
|
152
|
+
### Step 3: Use it naturally
|
|
153
|
+
|
|
154
|
+
You don't need to tell Claude to "use memory." Once MCP is connected, Claude will automatically write important decisions, recall relevant context, and learn from feedback. Over time, it builds up project knowledge that persists across every conversation.
|
|
155
|
+
|
|
156
|
+
**Pro tip:** You can use the same `memory.db` file across multiple projects if you want shared knowledge. Or use different databases per project for isolation — your call.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Docker (Quick Alternative)
|
|
161
|
+
|
|
162
|
+
If you'd rather not install Node.js locally:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
docker build -t awm .
|
|
166
|
+
docker run -p 8400:8400 -v awm-data:/data -v awm-models:/models awm
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
This gives you the HTTP server on port 8400. The `-v` flags persist your database and models across container restarts. For MCP integration with Docker, point your `.mcp.json` to the HTTP API instead of the MCP script.
|
|
170
|
+
|
|
171
|
+
## How It Works
|
|
172
|
+
|
|
173
|
+
### The Memory Lifecycle
|
|
174
|
+
|
|
175
|
+
1. **Write** — Agent sends an observation, decision, or event. Salience scoring evaluates surprise, causal depth, and resolution effort. High-salience memories go active immediately; borderline ones enter a staging buffer; noise is discarded.
|
|
176
|
+
|
|
177
|
+
2. **Connect** — Each memory gets a vector embedding (MiniLM-L6-v2, 384d). Temporal edges link it to recent memories in the same session. Hebbian edges form between memories that are retrieved together — the more often they co-activate, the stronger the link.
|
|
178
|
+
|
|
179
|
+
3. **Retrieve** — The 10-phase activation pipeline combines keyword search (BM25), semantic search (cosine similarity), cross-encoder reranking, temporal decay (ACT-R), associative graph walks, and confidence gating. It returns the most relevant memories with explanations of why each scored the way it did.
|
|
180
|
+
|
|
181
|
+
4. **Consolidate** — A periodic "sleep cycle" runs 7 phases modeled on how the brain processes memories during sleep:
|
|
182
|
+
- **Replay** — Find clusters of semantically similar memories
|
|
183
|
+
- **Strengthen** — Reinforce edges within clusters (access-weighted)
|
|
184
|
+
- **Bridge** — Create cross-cluster shortcuts between related topics
|
|
185
|
+
- **Decay** — Weaken unused edges (confidence-modulated half-life)
|
|
186
|
+
- **Homeostasis** — Normalize outgoing edge weights to prevent hub explosion
|
|
187
|
+
- **Forget** — Archive unretrieved, weakly-connected memories (age-gated, access-scaled)
|
|
188
|
+
- **Prune redundancy** — Archive semantically duplicate low-quality memories
|
|
189
|
+
- **Sweep staging** — Promote staging memories that resonate with active ones
|
|
190
|
+
|
|
191
|
+
5. **Feedback** — Agents report whether recalled memories were useful. Positive feedback raises confidence (improving retrieval rank and forgetting resistance); negative feedback lowers it.
|
|
192
|
+
|
|
193
|
+
### Cognitive Model
|
|
194
|
+
|
|
195
|
+
AWM is built on established cognitive science, not ad-hoc heuristics:
|
|
196
|
+
|
|
197
|
+
- **ACT-R base-level activation** (Anderson 1993) — memories decay with time but strengthen with use. Confidence modulates the decay exponent: confirmed knowledge decays slower.
|
|
198
|
+
- **Hebbian learning** — "neurons that fire together wire together." Co-retrieved memories form stronger associative edges, enabling graph-based spreading activation.
|
|
199
|
+
- **Complementary Learning Systems** — fast capture (salience filter + staging) combined with slow consolidation (sleep cycle). Mirrors hippocampal-neocortical memory transfer.
|
|
200
|
+
- **Synaptic homeostasis** — total connection weight per memory is normalized to prevent any single "hub" from dominating retrieval. Similar to how the brain downscales synaptic strength during sleep.
|
|
201
|
+
- **Forgetting as feature** — noise removal improves signal-to-noise ratio for connected memories. Unretrieved noise gets pruned; confirmed knowledge gets stronger. In benchmarks, aggressive forgetting improves quality recall from 3/5 to 5/5.
|
|
202
|
+
|
|
203
|
+
## Architecture
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
src/
|
|
207
|
+
core/ # Cognitive primitives
|
|
208
|
+
embeddings.ts - Local vector embeddings (MiniLM-L6-v2, 384d)
|
|
209
|
+
reranker.ts - Cross-encoder passage scoring (ms-marco-MiniLM)
|
|
210
|
+
query-expander.ts - Synonym expansion (flan-t5-small)
|
|
211
|
+
salience.ts - Write-time importance scoring
|
|
212
|
+
decay.ts - ACT-R temporal activation decay
|
|
213
|
+
hebbian.ts - Association strengthening/weakening
|
|
214
|
+
engine/ # Processing pipelines
|
|
215
|
+
activation.ts - 10-phase retrieval pipeline
|
|
216
|
+
consolidation.ts - 7-phase sleep cycle consolidation
|
|
217
|
+
connections.ts - Discover links between memories
|
|
218
|
+
staging.ts - Weak signal buffer (promote or discard)
|
|
219
|
+
retraction.ts - Negative memory / corrections
|
|
220
|
+
eviction.ts - Capacity enforcement
|
|
221
|
+
storage/
|
|
222
|
+
sqlite.ts - SQLite + FTS5 persistence layer
|
|
223
|
+
api/
|
|
224
|
+
routes.ts - HTTP endpoints (memory + task + system)
|
|
225
|
+
mcp.ts - MCP server (9 tools for Claude Code)
|
|
226
|
+
index.ts - HTTP server entry point
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Task Management
|
|
230
|
+
|
|
231
|
+
Tasks are first-class memory objects with status and priority tracking:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# Create a task
|
|
235
|
+
curl -X POST http://localhost:8400/task/create \
|
|
236
|
+
-H "Content-Type: application/json" \
|
|
237
|
+
-d '{
|
|
238
|
+
"agentId": "my-agent",
|
|
239
|
+
"concept": "Fix login redirect bug",
|
|
240
|
+
"content": "Users get 404 after OAuth callback",
|
|
241
|
+
"priority": "urgent"
|
|
242
|
+
}'
|
|
243
|
+
|
|
244
|
+
# Get next actionable task
|
|
245
|
+
curl http://localhost:8400/task/next/my-agent
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Priority levels: `urgent` > `high` > `medium` > `low`. Tasks can be blocked by other tasks and automatically unblock when dependencies complete.
|
|
249
|
+
|
|
250
|
+
## Testing & Evaluation
|
|
251
|
+
|
|
252
|
+
AWM has been through extensive testing — unit tests, integration tests, and multiple evaluation suites that simulate realistic use. Every component of the cognitive pipeline has been validated both in isolation and under real-world-like conditions.
|
|
253
|
+
|
|
254
|
+
### Unit Tests (no server needed)
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
npx vitest run # 47 tests — salience scoring, decay curves, Hebbian learning, etc.
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Eval Suites (start the server first: `npx tsx src/index.ts`)
|
|
261
|
+
|
|
262
|
+
| Command | What it tests | Score |
|
|
263
|
+
|---------|--------------|-------|
|
|
264
|
+
| `npm run test:self` | 31 pipeline component checks — embedding quality, BM25 recall, reranker ordering, decay curves, confidence gating, Hebbian strengthening, graph walks, staging promotion | **97.4% EXCELLENT** |
|
|
265
|
+
| `npm run test:edge` | 9 adversarial failure modes — context collapse (100 routine vs 5 rare), mega-hub toxicity (50-link hub node), flashbulb distortion (high-emotion memory overwriting facts), narcissistic interference (30 self-referential claims vs 4 facts), identity collision (same name, different people), contradiction trapping, bridge overshoot, noise forgetting benefit | **100% (34/34)** |
|
|
266
|
+
| `npm run test:stress` | 500 memories, 100 sleep cycles, catastrophic forgetting resistance, adversarial spam injection (200 noise memories), long-term knowledge recovery after 50 days of neglect | **92.3% (48/52)** |
|
|
267
|
+
| `npm run test:workday` | Simulates a coding assistant's workday — 43 memories across 4 projects (Express, React, CI/CD, PostgreSQL), then 14 recall challenges testing knowledge transfer, context switching, cross-cutting queries, and noise rejection | **86.7% GOOD** |
|
|
268
|
+
| `npm run test:ab` | Head-to-head comparison: AWM's full pipeline vs a keyword-only baseline, 100 project events, 24 recall questions | **AWM 100% vs Baseline 83%** |
|
|
269
|
+
| `npm run test:tokens` | Measures token savings — how much prompt context AWM saves vs dumping full conversation history | **64.5% savings** |
|
|
270
|
+
| `npm run test:realworld` | Ingests 300 code chunks from a 71K-line production monorepo (EquiHub/SportsManagement), tests domain knowledge recall, architecture questions, and noise rejection | **93.1% EXCELLENT** |
|
|
271
|
+
| `npm run test:sleep` | Targeted sleep cycle consolidation test | — |
|
|
272
|
+
| `npm run test:locomo` | Academic benchmark (LoCoMo dataset) — multi-hop conversational memory | — |
|
|
273
|
+
|
|
274
|
+
### What the Edge Cases Prove
|
|
275
|
+
|
|
276
|
+
The edge case suite is particularly important because it tests the failure modes that kill other memory systems:
|
|
277
|
+
|
|
278
|
+
- **Context Collapse** — Can AWM find 5 rare but important memories buried under 100 routine ones? (Yes — salience scoring and feedback bonuses keep confirmed knowledge afloat.)
|
|
279
|
+
- **Mega-Hub Toxicity** — If one memory has 50 connections, does it hijack every query? (No — synaptic homeostasis normalizes edge weights.)
|
|
280
|
+
- **Flashbulb Distortion** — Does a high-emotion memory overwrite the actual facts? (No — retraction system and confidence scoring keep specifics intact.)
|
|
281
|
+
- **Narcissistic Interference** — Can 30 self-referential "I am amazing" claims drown out 4 real facts? (No — redundancy pruning archives the clones, feedback bonuses elevate confirmed knowledge.)
|
|
282
|
+
- **Noise Forgetting Benefit** — Does forgetting 150 noise memories hurt the 5 quality ones? (Opposite — recall stays 5/5 because forgetting *improves* signal-to-noise ratio for connected memories.)
|
|
283
|
+
|
|
284
|
+
## Environment Variables
|
|
285
|
+
|
|
286
|
+
| Variable | Default | Purpose |
|
|
287
|
+
|----------|---------|---------|
|
|
288
|
+
| `AWM_PORT` | `8400` | HTTP server port |
|
|
289
|
+
| `AWM_DB_PATH` | `memory.db` | SQLite database path |
|
|
290
|
+
| `AWM_AGENT_ID` | `claude-code` | Default agent ID (MCP) |
|
|
291
|
+
| `AWM_EMBED_MODEL` | `Xenova/all-MiniLM-L6-v2` | Embedding model |
|
|
292
|
+
| `AWM_EMBED_DIMS` | `384` | Embedding dimensions |
|
|
293
|
+
| `AWM_RERANKER_MODEL` | `Xenova/ms-marco-MiniLM-L-6-v2` | Reranker model |
|
|
294
|
+
|
|
295
|
+
## Tech Stack
|
|
296
|
+
|
|
297
|
+
| Component | Technology |
|
|
298
|
+
|-----------|-----------|
|
|
299
|
+
| Language | TypeScript (ES2022, strict) |
|
|
300
|
+
| Database | SQLite via better-sqlite3 + FTS5 |
|
|
301
|
+
| HTTP | Fastify 5 |
|
|
302
|
+
| MCP | @modelcontextprotocol/sdk |
|
|
303
|
+
| ML Runtime | @huggingface/transformers (local ONNX) |
|
|
304
|
+
| Tests | Vitest 4 |
|
|
305
|
+
| Validation | Zod 4 |
|
|
306
|
+
|
|
307
|
+
All three ML models (embedding, reranker, query expander) run locally via ONNX — no OpenAI, no Anthropic API, no external calls for retrieval. The entire system is a single SQLite file + a Node.js process.
|
|
308
|
+
|
|
309
|
+
## License
|
|
310
|
+
|
|
311
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Routes — the black box interface agents interact with.
|
|
3
|
+
*
|
|
4
|
+
* Core (agent-facing):
|
|
5
|
+
* POST /memory/write — write a memory (salience filter decides disposition)
|
|
6
|
+
* POST /memory/activate — retrieve by context activation
|
|
7
|
+
* POST /memory/feedback — report whether a memory was useful
|
|
8
|
+
* POST /memory/retract — invalidate a wrong memory
|
|
9
|
+
*
|
|
10
|
+
* Checkpointing:
|
|
11
|
+
* POST /memory/checkpoint — save explicit execution state
|
|
12
|
+
* GET /memory/restore/:agentId — restore state + targeted recall + async mini-consolidation
|
|
13
|
+
*
|
|
14
|
+
* Task management:
|
|
15
|
+
* POST /task/create — create a prioritized task
|
|
16
|
+
* POST /task/update — update status, priority, or blocking
|
|
17
|
+
* GET /task/list/:agentId — list tasks (filtered by status)
|
|
18
|
+
* GET /task/next/:agentId — get highest-priority actionable task
|
|
19
|
+
*
|
|
20
|
+
* Diagnostic (debugging/eval):
|
|
21
|
+
* POST /memory/search — deterministic search (not cognitive)
|
|
22
|
+
* GET /memory/:id — get a specific engram
|
|
23
|
+
* GET /agent/:id/stats — memory stats for an agent
|
|
24
|
+
* GET /agent/:id/metrics — eval metrics
|
|
25
|
+
* POST /agent/register — register a new agent
|
|
26
|
+
*
|
|
27
|
+
* System:
|
|
28
|
+
* POST /system/evict — trigger eviction check
|
|
29
|
+
* POST /system/decay — trigger edge decay
|
|
30
|
+
* POST /system/consolidate — run sleep cycle (strengthen, decay, sweep)
|
|
31
|
+
* GET /health — health check
|
|
32
|
+
*/
|
|
33
|
+
import type { FastifyInstance } from 'fastify';
|
|
34
|
+
import type { EngramStore } from '../storage/sqlite.js';
|
|
35
|
+
import type { ActivationEngine } from '../engine/activation.js';
|
|
36
|
+
import type { ConnectionEngine } from '../engine/connections.js';
|
|
37
|
+
import type { EvictionEngine } from '../engine/eviction.js';
|
|
38
|
+
import type { RetractionEngine } from '../engine/retraction.js';
|
|
39
|
+
import type { EvalEngine } from '../engine/eval.js';
|
|
40
|
+
import type { ConsolidationEngine } from '../engine/consolidation.js';
|
|
41
|
+
import type { ConsolidationScheduler } from '../engine/consolidation-scheduler.js';
|
|
42
|
+
export interface MemoryDeps {
|
|
43
|
+
store: EngramStore;
|
|
44
|
+
activationEngine: ActivationEngine;
|
|
45
|
+
connectionEngine: ConnectionEngine;
|
|
46
|
+
evictionEngine: EvictionEngine;
|
|
47
|
+
retractionEngine: RetractionEngine;
|
|
48
|
+
evalEngine: EvalEngine;
|
|
49
|
+
consolidationEngine: ConsolidationEngine;
|
|
50
|
+
consolidationScheduler: ConsolidationScheduler;
|
|
51
|
+
}
|
|
52
|
+
export declare function registerRoutes(app: FastifyInstance, deps: MemoryDeps): void;
|
|
53
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/api/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAQnF,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,WAAW,CAAC;IACnB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,UAAU,EAAE,UAAU,CAAC;IACvB,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,sBAAsB,EAAE,sBAAsB,CAAC;CAChD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI,CAmd3E"}
|