agent-working-memory 0.8.8 → 0.9.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/README.md +165 -46
- package/dist/api/routes.js +7 -7
- package/dist/cli/migrate.js +29 -29
- package/dist/cli.js +104 -104
- package/dist/coordination/circuit-breaker.js +23 -23
- package/dist/core/write-pipeline.d.ts.map +1 -1
- package/dist/core/write-pipeline.js +17 -0
- package/dist/core/write-pipeline.js.map +1 -1
- package/dist/engine/activation.d.ts +28 -0
- package/dist/engine/activation.d.ts.map +1 -1
- package/dist/engine/activation.js +341 -11
- package/dist/engine/activation.js.map +1 -1
- package/dist/engine/connections.d.ts +12 -0
- package/dist/engine/connections.d.ts.map +1 -1
- package/dist/engine/connections.js +95 -0
- package/dist/engine/connections.js.map +1 -1
- package/dist/mcp.js +90 -90
- package/dist/storage/pglite-schema.js +143 -143
- package/dist/storage/pglite.js +138 -138
- package/dist/types/engram.d.ts +1 -0
- package/dist/types/engram.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api/index.ts +3 -3
- package/src/cli/migrate.ts +307 -307
- package/src/coordination/circuit-breaker.ts +83 -83
- package/src/coordination/failure-modes.ts +50 -50
- package/src/core/decay.ts +63 -63
- package/src/core/embeddings.ts +110 -110
- package/src/core/index.ts +5 -5
- package/src/core/logger.ts +36 -36
- package/src/core/ml-worker-entry.ts +194 -194
- package/src/core/ml-worker.ts +281 -281
- package/src/core/query-expander.ts +122 -122
- package/src/core/reranker.ts +119 -119
- package/src/core/write-pipeline.ts +15 -0
- package/src/engine/activation.ts +328 -11
- package/src/engine/confidence.ts +120 -120
- package/src/engine/connections.ts +94 -0
- package/src/engine/consolidation-scheduler.ts +242 -242
- package/src/engine/eval.ts +102 -102
- package/src/engine/eviction.ts +101 -101
- package/src/engine/index.ts +8 -8
- package/src/engine/retraction.ts +366 -366
- package/src/engine/staging.ts +74 -74
- package/src/storage/factory.ts +147 -147
- package/src/storage/index.ts +3 -3
- package/src/storage/pglite-schema.ts +166 -166
- package/src/storage/pglite.ts +1363 -1363
- package/src/storage/store.ts +80 -80
- package/src/types/agent.ts +67 -67
- package/src/types/checkpoint.ts +46 -46
- package/src/types/engram.ts +1 -0
- package/src/types/eval.ts +100 -100
- package/src/types/index.ts +6 -6
package/README.md
CHANGED
|
@@ -84,59 +84,134 @@ Most "memory for AI" projects are vector databases with a retrieval wrapper. AWM
|
|
|
84
84
|
|
|
85
85
|
The design is based on cognitive science — ACT-R activation decay, Hebbian learning, complementary learning systems, synaptic homeostasis, and synaptic tagging — rather than ad-hoc heuristics. See [How It Works](#how-it-works) and [docs/cognitive-model.md](docs/cognitive-model.md) for details.
|
|
86
86
|
|
|
87
|
+
> **New to AWM?** [`docs/pipeline-walkthrough.html`](docs/pipeline-walkthrough.html) is a visual, plain-language walkthrough (no background required) — what happens when AWM learns and recalls a fact, why it's built this way, and how it differs from a plain vector store. Open it in a browser.
|
|
88
|
+
|
|
89
|
+
> **Build an agent on it:** the [AWM-Native Agent Harness pattern](docs/patterns/awm-native-harness.md) shows how to use AWM as an always-on cognitive *substrate* (not a tool the model calls) so the agent learns automatically by working — letting a cheap model perform at a high level and get cheaper + better over time. Measured: gpt-5.4-mini + AWM beat a frontier model on a domain workload at ~1/40th the cost.
|
|
90
|
+
|
|
91
|
+
> **For builders & researchers:** [`docs/awm-for-agents.html`](docs/awm-for-agents.html) is the agent playbook — why AWM exists (the context-window wall), the PRIME→ACT→VERIFY→LEARN harness, the full agent feature surface (workspace, session IDs, bearer-token hooks, supersede/feedback), how multi-hop is solved in the harness, and the honest gauntlet findings (where AWM wins, ties, and what isn't measured yet). Open it in a browser.
|
|
92
|
+
|
|
87
93
|
---
|
|
88
94
|
|
|
89
|
-
##
|
|
95
|
+
## Why it matters at scale
|
|
90
96
|
|
|
91
|
-
|
|
97
|
+
The reason AWM exists: **past roughly half a million tokens, you can no longer keep a large project's context alive by carrying it.** The codebase, the docs, the decision history, and the meeting/work transcripts outgrow every model's window — and summarizing to fit silently drops the fact you needed next.
|
|
92
98
|
|
|
93
|
-
|
|
94
|
-
|-------|---|---|-----------|---------------|
|
|
95
|
-
| Retrieval | **Recall@5 = 0.980** | 0.800 | >= 0.80 | 200 facts, 50 queries — BM25 + vector + reranker pipeline precision |
|
|
96
|
-
| Associative | **success@10 = 1.000** | 1.000 | >= 0.70 | 20 multi-hop causal chains — graph walk finds non-obvious connections |
|
|
97
|
-
| Redundancy | **dedup F1 = 0.966** | 0.966 | >= 0.80 | 50 clusters × 4 paraphrases — consolidation removes duplicates correctly |
|
|
98
|
-
| Temporal | **Spearman = 0.932** | 0.932 | >= 0.75 | 25 facts with controlled age/access — ACT-R decay ranking accuracy |
|
|
99
|
+
These figures come from real-world use on a large software platform project, where a single work agent has accumulated **20,000+ memories** over a multi-million-token codebase and documentation set:
|
|
99
100
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
> Clones near the anchor get near-zero boost; genuine lateral candidates
|
|
106
|
-
> (low textMatch, shared entities) still get the full boost.
|
|
107
|
-
> Result: Recall@5 0.46 → 0.980 with all 4 eval suites green.
|
|
101
|
+
| To answer one question, carry… | tokens | AWM scoped recall |
|
|
102
|
+
|---|---|---|
|
|
103
|
+
| the accumulated memory (~20K memories) | ~1.3M | **~630, flat** |
|
|
104
|
+
| the project's notes & transcript docs | ~2M | **~630, flat** |
|
|
105
|
+
| the whole system (code + docs) | ~29M — fits in no window, any tier | **~630, flat** |
|
|
108
106
|
|
|
109
|
-
|
|
107
|
+
A scoped recall answers from the relevant *slice*, independent of how large the store grows. Measured consequences on real questions against the real project:
|
|
108
|
+
|
|
109
|
+
- **~2,000× fewer tokens per query** than carrying the memory store — and **~5× fewer** than opening the single best-matching documentation file (a floor; agents usually open several and still miss cross-file facts).
|
|
110
|
+
- **At scale, "carry everything" isn't an option.** At ~20K memories no context window holds it, so retrieval is not an optimization — it is the only door. A static notes file or long-context approach is forced to truncate, which silently drops facts.
|
|
111
|
+
|
|
112
|
+
Two structural advantages a file or a flat vector store cannot match:
|
|
110
113
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
|
135
|
-
|
|
136
|
-
|
|
|
137
|
-
|
|
|
138
|
-
|
|
139
|
-
|
|
114
|
+
- **Staleness is tracked.** When a fact changes, `memory_supersede` retires the old value and recall stops returning it — the system *knows* what changed. A notes file or repo goes stale silently; you would re-scan everything to find out. (This work agent has superseded and retracted dozens of facts as the project moved.)
|
|
115
|
+
- **Dead weight costs nothing.** ~90% of accumulated memories are never recalled for a given task — a notes file pays for all of them in every prompt; recall pays for ≈zero.
|
|
116
|
+
|
|
117
|
+
### Honest about the trade-offs
|
|
118
|
+
|
|
119
|
+
- AWM does **not** win on small, one-shot tasks — write/recall overhead exceeds the savings until knowledge is reused or the corpus grows past what fits in context.
|
|
120
|
+
- Recall is not free: a few seconds of latency per query buys the token reduction.
|
|
121
|
+
- Recall accuracy is bounded by what was written — write quality matters (lead with the fact; tag with identifiers like file, table, ticket).
|
|
122
|
+
- It does not replace your source of truth. The intended pattern is: **recall first, read/grep the code for ground truth on a miss, and supersede when reality differs.**
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Benchmarks
|
|
127
|
+
|
|
128
|
+
Two kinds of tests, both reproducible (see [Testing & Evaluation](#testing--evaluation)).
|
|
129
|
+
First, **recall quality** — does the pipeline return the right memory? Second,
|
|
130
|
+
**behavior under stress** — does it stay honest, filter noise, and hold up as the
|
|
131
|
+
store grows and ages? Numbers below were re-run on the 0.9-staged line (2026-06-17).
|
|
132
|
+
|
|
133
|
+
### 1 · Recall quality (eval harness)
|
|
134
|
+
|
|
135
|
+
Each suite has a pass threshold; all four pass.
|
|
136
|
+
|
|
137
|
+
| Suite | Score | Threshold | What it measures |
|
|
138
|
+
|-------|-------|-----------|------------------|
|
|
139
|
+
| Retrieval | **Recall@5 = 0.980** | ≥ 0.80 | 200 facts, 50 queries — does the BM25 + vector + reranker pipeline surface the right fact in the top 5? |
|
|
140
|
+
| Associative | **success@10 = 1.000** | ≥ 0.70 | 20 multi-hop causal chains — does the graph walk find non-obvious connections? |
|
|
141
|
+
| Redundancy | **dedup F1 = 0.966** | ≥ 0.80 | 50 clusters × 4 paraphrases — does consolidation merge duplicates without losing the original? |
|
|
142
|
+
| Temporal | **Spearman = 0.932** | ≥ 0.75 | 25 facts with controlled age/access — does ACT-R decay rank recent/used memories ahead of stale ones? |
|
|
143
|
+
|
|
144
|
+
### 2 · Behavior under stress & adversarial conditions
|
|
145
|
+
|
|
146
|
+
These are graded suites (not pass/fail). The headline risk they guard against is a
|
|
147
|
+
memory system that confidently returns the *wrong* thing — so the weakest area is
|
|
148
|
+
called out, not hidden.
|
|
149
|
+
|
|
150
|
+
| Suite | Score | What it measures |
|
|
151
|
+
|-------|-------|------------------|
|
|
152
|
+
| `test:run` (unit) | **569 / 569** | Salience, decay, Hebbian, supersession, coordination, scheduler |
|
|
153
|
+
| `test:self` | **93.9% (EXCELLENT)** | Every cognitive subsystem end-to-end; weakest = exact-topic retrieval |
|
|
154
|
+
| `test:workday` | **85.4% (GOOD)** | A realistic mixed day — 43 memories across 4 projects, cross-cutting queries; weakest = noise filtering |
|
|
155
|
+
| `test:edge` | **~32 / 34** | Named failure modes: identity collision, contradiction trapping, bridge overshoot, false generalization |
|
|
156
|
+
| `test:ab` | **AWM 10 / 11 vs keyword baseline 8 / 11** | Where the cognitive pipeline beats plain keyword search |
|
|
157
|
+
| `test:pilot` | **14 / 15** (5/5 noise rejected) | Production-like queries that must reject planted distractors |
|
|
158
|
+
| `test:locomo` | **25.7%** | LoCoMo conversational-memory benchmark (a *chatbot* benchmark — see note) |
|
|
159
|
+
| `test:mcp` | **5 / 5** | MCP protocol smoke: write, recall, feedback, retract, stats |
|
|
160
|
+
|
|
161
|
+
> **On LoCoMo (25.7%):** LoCoMo measures *chatbot* recall ("what did we say about X"
|
|
162
|
+
> across long conversations). It is not the workload AWM is tuned for (productivity /
|
|
163
|
+
> engineering, staying on topic, rejecting noise), and ~66% of AWM's misses there are
|
|
164
|
+
> retriever-coverage (the gold turn isn't in the top-10), not extraction. The 0.9 recall
|
|
165
|
+
> work lifted it from 22.7% with every category up. We report it for comparability, not
|
|
166
|
+
> as the headline.
|
|
167
|
+
|
|
168
|
+
### 3 · The sleep cycle (consolidation)
|
|
169
|
+
|
|
170
|
+
The **sleep cycle** is AWM's offline maintenance pass (the term is borrowed from how
|
|
171
|
+
human memory consolidates during sleep). On each cycle it **clusters** related
|
|
172
|
+
memories, builds **cross-topic bridges**, **strengthens** co-used edges, **decays**
|
|
173
|
+
unused ones, and **prunes** duplicates. You run it so the association graph stays
|
|
174
|
+
*healthy and navigable* as the store grows — without it, edges accumulate into noise.
|
|
175
|
+
|
|
176
|
+
> **Reading the score:** `test:sleep` = **78.6%** is a *consolidation-quality* score —
|
|
177
|
+
> it asks "after the maintenance pass, is recall at least as good and is the structure
|
|
178
|
+
> better?" **It is not recall falling to 78.6%.** In this fixture recall is held flat
|
|
179
|
+
> across three cycles (78.6% before = 78.6% after) while the graph reorganizes. The
|
|
180
|
+
> scaling picture is the real proof:
|
|
181
|
+
|
|
182
|
+
| Under a 100-cycle stress run | Observed |
|
|
183
|
+
|---|---|
|
|
184
|
+
| Recall across cycles | **holds 90–100%** (no catastrophic forgetting) |
|
|
185
|
+
| Cross-topic recall | **~80%**, stable |
|
|
186
|
+
| Graph self-pruning | edges grow to ~2,300 then prune back to ~1,500 as unused links decay |
|
|
187
|
+
| Clusters / bridges per cycle | ~10 clusters, bridges formed early then settle |
|
|
188
|
+
|
|
189
|
+
So consolidation *protects* recall over the long run — the per-cycle score measures the
|
|
190
|
+
health of the maintenance, and the stress run shows recall doesn't degrade.
|
|
191
|
+
|
|
192
|
+
### 4 · Token economics — honest
|
|
193
|
+
|
|
194
|
+
The win that matters is **structural**: at the scale AWM targets you can't carry the
|
|
195
|
+
project at all (see [Why it matters at scale](#why-it-matters-at-scale)). On real coding
|
|
196
|
+
sessions, scoped recall costs **9.8× less in aggregate** than the Read/Grep/Glob
|
|
197
|
+
rediscovery it replaces (`scripts/measure-claude-vs-awm.ts`).
|
|
198
|
+
|
|
199
|
+
The per-turn micro-benchmark (`test:tokens`) reports against **two** baselines, because the
|
|
200
|
+
baseline you pick *is* the result:
|
|
201
|
+
|
|
202
|
+
- **vs carrying the full history** (what a memoryless agent must actually do — it can't know
|
|
203
|
+
which past turn matters): **+67% savings at 97.5% recall accuracy.** This is the honest,
|
|
204
|
+
apples-to-apples number.
|
|
205
|
+
- **vs an oracle that pre-scoped context to the exactly-relevant task**: **≈ −13%.** A
|
|
206
|
+
deliberately brutal bar — it gives the baseline the very scoping that retrieval exists to do —
|
|
207
|
+
and on a tiny 6–8-turn task a fixed top-5 recall is break-even-to-negative *by construction*.
|
|
208
|
+
|
|
209
|
+
An earlier build reported ~56% on the oracle bar, but that was an **artifact**: pre-v0.8.5,
|
|
210
|
+
reinforce-on-duplicate silently *discarded* memory content, so recalls were artificially tiny.
|
|
211
|
+
v0.8.5 fixed the data loss (accuracy ~72% → 97.5%); better recall now fills all five slots,
|
|
212
|
+
which *lowers* the oracle-bar number while *raising* correctness. Net: the at-scale structural
|
|
213
|
+
win above is the real story; the oracle bar shows AWM roughly matches perfect manual scoping
|
|
214
|
+
even on a corpus far too small to play to its strengths.
|
|
140
215
|
|
|
141
216
|
---
|
|
142
217
|
|
|
@@ -475,6 +550,49 @@ npm run test:locomo # LoCoMo industry benchmark (28.2%)
|
|
|
475
550
|
|
|
476
551
|
All three ML models run locally via ONNX. No external API calls for retrieval. The entire system is a single SQLite file + a Node.js process.
|
|
477
552
|
|
|
553
|
+
## What's New in v0.9.0
|
|
554
|
+
|
|
555
|
+
A recall-quality default + new tuning knobs + a builder/researcher doc set.
|
|
556
|
+
Every change is an **env-revertible default** with no API changes — existing
|
|
557
|
+
callers keep working unmodified. Validated: official LoCoMo **22.7% → 25.7%**
|
|
558
|
+
(every category up) **and** adversarial precision **73.4 → 74.9** (strictly
|
|
559
|
+
better on each axis); recall latency ~35 → ~77ms (sub-100ms, tunable); zero
|
|
560
|
+
regression across the standard suite (eval 4-suite identical, 569/569 unit,
|
|
561
|
+
edge 32/34, workday = old config).
|
|
562
|
+
|
|
563
|
+
- **Wide rerank pool + top-K abstention (the win).** A pipeline-attribution
|
|
564
|
+
study (new tracer, `tests/locomo-eval/trace.ts`) found the dominant recall
|
|
565
|
+
loss wasn't candidate generation *or* the reranker — it was the stage between:
|
|
566
|
+
~50% of answerable queries had gold that *cleared the candidate floor* but was
|
|
567
|
+
squeezed out of the rerank pool by the decay-compressed composite **before the
|
|
568
|
+
high-lift (+3.29) reranker saw it**. Fix: the composite becomes a cheap **wide
|
|
569
|
+
pre-filter** (`AWM_TOPN_MULT=8`, was 3×), the reranker discriminates on a wider
|
|
570
|
+
pool (`AWM_RERANK_POOL=max(limit*4,40)`, was `max(limit*2,15)`), and the
|
|
571
|
+
out-of-domain abstention gate judges only the **post-rerank top-K**
|
|
572
|
+
(`AWM_ABSTAIN_GATE_K=5`) so widening for recall doesn't inflate the in-domain
|
|
573
|
+
signal. Reverses the v0.7.13 "pool reduction" change. See
|
|
574
|
+
[reference.md → Recall tuning](docs/reference.md#recall-tuning-env-overrides).
|
|
575
|
+
|
|
576
|
+
- **Tunable similarity floors.** `AWM_SIM_FLOOR_TARGETED` / `_EXPLORATORY`
|
|
577
|
+
(defaults 0.50 / 0.35, unchanged) and the candidate-entry floors are now env
|
|
578
|
+
overrides for retuning against a different embedder.
|
|
579
|
+
|
|
580
|
+
- **Opt-in / experimental flags (default-off).** `AWM_QUERY_BRIDGE`
|
|
581
|
+
(query-named-entity boost — lifts attribution "what does X think" 36% → 92% on
|
|
582
|
+
a controlled eval; small adversarial cost, so opt-in), `AWM_AUTOTAG`
|
|
583
|
+
(write-time `entity:`/`cat:` meta-tags), `AWM_BROAD_EDGES`. `AWM_SPREAD`
|
|
584
|
+
(in-engine spreading activation) is **parked** — it regressed recall by
|
|
585
|
+
displacing gold; multi-hop is solved harness-side instead (see the playbook).
|
|
586
|
+
|
|
587
|
+
- **New docs for builders & researchers.** [`docs/awm-for-agents.html`](docs/awm-for-agents.html)
|
|
588
|
+
— the agent playbook (why AWM exists, the PRIME→ACT→VERIFY→LEARN harness, the
|
|
589
|
+
full agent feature surface, how multi-hop is solved, and the honest gauntlet
|
|
590
|
+
findings). [`docs/pipeline-walkthrough.html`](docs/pipeline-walkthrough.html)
|
|
591
|
+
redesigned for devs/researchers. Both are published on GitHub Pages. A new
|
|
592
|
+
**Storage Backends + Postgres roadmap** section in
|
|
593
|
+
[architecture.md](docs/architecture.md) documents SQLite (default) vs PGlite
|
|
594
|
+
and the path to a networked-Postgres backend (v1 target).
|
|
595
|
+
|
|
478
596
|
## What's New in v0.8.5
|
|
479
597
|
|
|
480
598
|
A research-grounded hardening pass on recall quality, retraction propagation,
|
|
@@ -582,6 +700,7 @@ callers keep working without modification. Full validation at the milestone:
|
|
|
582
700
|
## What's New in v0.7.13
|
|
583
701
|
|
|
584
702
|
- **Reranker pool size reduction** — cross-encoder pool dropped from `max(limit*3, 30)` to `max(limit*2, 15)`. For typical agent queries (limit=5 or 10), that's 15-20 candidates reranked instead of 30, halving the cross-encoder cost. Top-K quality preserved (8/8 top-1, identical top-5/top-10 overlap) — reranking the 21st-30th candidates was wasted when the user only wants top-5 anyway.
|
|
703
|
+
> **⚠️ Superseded in 0.9.0 — this reduction was reversed.** A pipeline-attribution study found that "wasted" tail was actually where ~50% of retrievable answers were being squeezed out *before* the reranker saw them (the small 8-query A/B above missed it). 0.9.0 widens the pool back to `max(limit*4, 40)` and adds a top-K abstention gate — lifting LoCoMo recall 22.7%→25.7% **and** adversarial precision 73.4→74.9, with no regression. See the CHANGELOG and `docs/reference.md` → "Recall tuning."
|
|
585
704
|
|
|
586
705
|
## What's New in v0.7.12
|
|
587
706
|
|
package/dist/api/routes.js
CHANGED
|
@@ -655,9 +655,9 @@ export function registerRoutes(app, deps) {
|
|
|
655
655
|
return reply.code(501).send({ error: 'export endpoint requires the SQLite backend' });
|
|
656
656
|
}
|
|
657
657
|
const db = store.getDb();
|
|
658
|
-
let engramSql = `SELECT id, agent_id, concept, content, confidence, salience, access_count,
|
|
659
|
-
last_accessed, created_at, salience_features, reason_codes, stage, ttl,
|
|
660
|
-
retracted, retracted_by, retracted_at, tags
|
|
658
|
+
let engramSql = `SELECT id, agent_id, concept, content, confidence, salience, access_count,
|
|
659
|
+
last_accessed, created_at, salience_features, reason_codes, stage, ttl,
|
|
660
|
+
retracted, retracted_by, retracted_at, tags
|
|
661
661
|
FROM engrams`;
|
|
662
662
|
const conditions = [];
|
|
663
663
|
const params = [];
|
|
@@ -675,7 +675,7 @@ export function registerRoutes(app, deps) {
|
|
|
675
675
|
engramSql += ' ORDER BY created_at ASC';
|
|
676
676
|
const engrams = db.prepare(engramSql).all(...params);
|
|
677
677
|
const engramIds = new Set(engrams.map(e => e.id));
|
|
678
|
-
const allAssocs = db.prepare(`SELECT id, from_engram_id, to_engram_id, weight, confidence, type, activation_count, created_at, last_activated
|
|
678
|
+
const allAssocs = db.prepare(`SELECT id, from_engram_id, to_engram_id, weight, confidence, type, activation_count, created_at, last_activated
|
|
679
679
|
FROM associations`).all();
|
|
680
680
|
const associations = allAssocs.filter(a => engramIds.has(a.from_engram_id) && engramIds.has(a.to_engram_id));
|
|
681
681
|
return reply.send({
|
|
@@ -700,9 +700,9 @@ export function registerRoutes(app, deps) {
|
|
|
700
700
|
if (coordEnabled && typeof deps.store.getDb === 'function') {
|
|
701
701
|
try {
|
|
702
702
|
const db = deps.store.getDb();
|
|
703
|
-
const stats = db.prepare(`SELECT
|
|
704
|
-
(SELECT COUNT(*) FROM coord_agents WHERE status != 'dead') AS agents_alive,
|
|
705
|
-
(SELECT COUNT(*) FROM coord_assignments WHERE status = 'pending') AS pending_tasks,
|
|
703
|
+
const stats = db.prepare(`SELECT
|
|
704
|
+
(SELECT COUNT(*) FROM coord_agents WHERE status != 'dead') AS agents_alive,
|
|
705
|
+
(SELECT COUNT(*) FROM coord_assignments WHERE status = 'pending') AS pending_tasks,
|
|
706
706
|
(SELECT COUNT(*) FROM coord_locks) AS active_locks`).get();
|
|
707
707
|
Object.assign(base, stats);
|
|
708
708
|
}
|
package/dist/cli/migrate.js
CHANGED
|
@@ -72,17 +72,17 @@ export async function migrate(opts) {
|
|
|
72
72
|
const embedding = r.embedding
|
|
73
73
|
? vectorLiteral(Array.from(bufferToFloat32Array(r.embedding)))
|
|
74
74
|
: null;
|
|
75
|
-
await dst.query(`INSERT INTO engrams (
|
|
76
|
-
id, agent_id, concept, content, embedding, embedding_model,
|
|
77
|
-
confidence, salience, access_count, last_accessed, created_at,
|
|
78
|
-
salience_features, reason_codes, stage, ttl,
|
|
79
|
-
retracted, retracted_by, retracted_at, tags, memory_type,
|
|
80
|
-
memory_class, superseded_by, supersedes, episode_id,
|
|
81
|
-
task_status, task_priority, blocked_by, sequence, references_json
|
|
82
|
-
) VALUES (
|
|
83
|
-
$1, $2, $3, $4, $5::vector, $6, $7, $8, $9, $10, $11,
|
|
84
|
-
$12, $13, $14, $15, $16, $17, $18, $19, $20,
|
|
85
|
-
$21, $22, $23, $24, $25, $26, $27, $28, $29
|
|
75
|
+
await dst.query(`INSERT INTO engrams (
|
|
76
|
+
id, agent_id, concept, content, embedding, embedding_model,
|
|
77
|
+
confidence, salience, access_count, last_accessed, created_at,
|
|
78
|
+
salience_features, reason_codes, stage, ttl,
|
|
79
|
+
retracted, retracted_by, retracted_at, tags, memory_type,
|
|
80
|
+
memory_class, superseded_by, supersedes, episode_id,
|
|
81
|
+
task_status, task_priority, blocked_by, sequence, references_json
|
|
82
|
+
) VALUES (
|
|
83
|
+
$1, $2, $3, $4, $5::vector, $6, $7, $8, $9, $10, $11,
|
|
84
|
+
$12, $13, $14, $15, $16, $17, $18, $19, $20,
|
|
85
|
+
$21, $22, $23, $24, $25, $26, $27, $28, $29
|
|
86
86
|
)`, [
|
|
87
87
|
r.id, r.agent_id, r.concept, r.content, embedding, r.embedding_model,
|
|
88
88
|
r.confidence, r.salience, r.access_count, r.last_accessed, r.created_at,
|
|
@@ -112,9 +112,9 @@ export async function migrate(opts) {
|
|
|
112
112
|
for (let i = 0; i < assocRows.length; i += batchSize) {
|
|
113
113
|
const batch = assocRows.slice(i, i + batchSize);
|
|
114
114
|
for (const r of batch) {
|
|
115
|
-
await dst.query(`INSERT INTO associations (
|
|
116
|
-
id, from_engram_id, to_engram_id, weight, confidence, type,
|
|
117
|
-
activation_count, created_at, last_activated
|
|
115
|
+
await dst.query(`INSERT INTO associations (
|
|
116
|
+
id, from_engram_id, to_engram_id, weight, confidence, type,
|
|
117
|
+
activation_count, created_at, last_activated
|
|
118
118
|
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)`, [
|
|
119
119
|
r.id, r.from_engram_id, r.to_engram_id, r.weight, r.confidence,
|
|
120
120
|
r.type ?? 'hebbian', r.activation_count ?? 0,
|
|
@@ -133,7 +133,7 @@ export async function migrate(opts) {
|
|
|
133
133
|
console.log(`agents: ${agentRows.length} rows`);
|
|
134
134
|
if (dst && agentRows.length > 0) {
|
|
135
135
|
for (const r of agentRows) {
|
|
136
|
-
await dst.query(`INSERT INTO agents (id, name, created_at, config) VALUES ($1,$2,$3,$4)
|
|
136
|
+
await dst.query(`INSERT INTO agents (id, name, created_at, config) VALUES ($1,$2,$3,$4)
|
|
137
137
|
ON CONFLICT (id) DO NOTHING`, [r.id, r.name, r.created_at, r.config ?? '{}']);
|
|
138
138
|
stats.agents++;
|
|
139
139
|
}
|
|
@@ -148,8 +148,8 @@ export async function migrate(opts) {
|
|
|
148
148
|
if (dst && aeRows.length > 0) {
|
|
149
149
|
for (let i = 0; i < aeRows.length; i += batchSize) {
|
|
150
150
|
for (const r of aeRows.slice(i, i + batchSize)) {
|
|
151
|
-
await dst.query(`INSERT INTO activation_events
|
|
152
|
-
(id, agent_id, timestamp, context, results_returned, top_score, latency_ms, engram_ids)
|
|
151
|
+
await dst.query(`INSERT INTO activation_events
|
|
152
|
+
(id, agent_id, timestamp, context, results_returned, top_score, latency_ms, engram_ids)
|
|
153
153
|
VALUES ($1,$2,$3,$4,$5,$6,$7,$8)`, [r.id, r.agent_id, r.timestamp, r.context, r.results_returned,
|
|
154
154
|
r.top_score, r.latency_ms, r.engram_ids ?? '[]']);
|
|
155
155
|
stats.activationEvents++;
|
|
@@ -165,7 +165,7 @@ export async function migrate(opts) {
|
|
|
165
165
|
console.log(`staging_events: ${seRows.length} rows`);
|
|
166
166
|
if (dst && seRows.length > 0) {
|
|
167
167
|
for (const r of seRows) {
|
|
168
|
-
await dst.query(`INSERT INTO staging_events (engram_id, agent_id, action, resonance_score, timestamp, age_ms)
|
|
168
|
+
await dst.query(`INSERT INTO staging_events (engram_id, agent_id, action, resonance_score, timestamp, age_ms)
|
|
169
169
|
VALUES ($1,$2,$3,$4,$5,$6)`, [r.engram_id, r.agent_id, r.action, r.resonance_score, r.timestamp, r.age_ms]);
|
|
170
170
|
stats.stagingEvents++;
|
|
171
171
|
}
|
|
@@ -179,8 +179,8 @@ export async function migrate(opts) {
|
|
|
179
179
|
console.log(`retrieval_feedback: ${rfRows.length} rows`);
|
|
180
180
|
if (dst && rfRows.length > 0) {
|
|
181
181
|
for (const r of rfRows) {
|
|
182
|
-
await dst.query(`INSERT INTO retrieval_feedback
|
|
183
|
-
(id, activation_event_id, engram_id, useful, context, timestamp)
|
|
182
|
+
await dst.query(`INSERT INTO retrieval_feedback
|
|
183
|
+
(id, activation_event_id, engram_id, useful, context, timestamp)
|
|
184
184
|
VALUES ($1,$2,$3,$4,$5,$6)`, [r.id, r.activation_event_id, r.engram_id, intToBool(r.useful), r.context, r.timestamp]);
|
|
185
185
|
stats.retrievalFeedback++;
|
|
186
186
|
}
|
|
@@ -199,8 +199,8 @@ export async function migrate(opts) {
|
|
|
199
199
|
const embedding = r.embedding
|
|
200
200
|
? vectorLiteral(Array.from(bufferToFloat32Array(r.embedding)))
|
|
201
201
|
: null;
|
|
202
|
-
await dst.query(`INSERT INTO episodes
|
|
203
|
-
(id, agent_id, label, embedding, engram_count, start_time, end_time, created_at)
|
|
202
|
+
await dst.query(`INSERT INTO episodes
|
|
203
|
+
(id, agent_id, label, embedding, engram_count, start_time, end_time, created_at)
|
|
204
204
|
VALUES ($1,$2,$3,$4::vector,$5,$6,$7,$8)`, [r.id, r.agent_id, r.label, embedding, r.engram_count ?? 0,
|
|
205
205
|
r.start_time, r.end_time, r.created_at]);
|
|
206
206
|
stats.episodes++;
|
|
@@ -221,13 +221,13 @@ export async function migrate(opts) {
|
|
|
221
221
|
console.log(`conscious_state: ${csRows.length} rows`);
|
|
222
222
|
if (dst && csRows.length > 0) {
|
|
223
223
|
for (const r of csRows) {
|
|
224
|
-
await dst.query(`INSERT INTO conscious_state (
|
|
225
|
-
agent_id, last_write_id, last_recall_context, last_recall_ids,
|
|
226
|
-
last_activity_at, write_count_since_consolidation,
|
|
227
|
-
recall_count_since_consolidation, execution_state, checkpoint_at,
|
|
228
|
-
last_consolidation_at, last_mini_consolidation_at,
|
|
229
|
-
consolidation_cycle_count, updated_at
|
|
230
|
-
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)
|
|
224
|
+
await dst.query(`INSERT INTO conscious_state (
|
|
225
|
+
agent_id, last_write_id, last_recall_context, last_recall_ids,
|
|
226
|
+
last_activity_at, write_count_since_consolidation,
|
|
227
|
+
recall_count_since_consolidation, execution_state, checkpoint_at,
|
|
228
|
+
last_consolidation_at, last_mini_consolidation_at,
|
|
229
|
+
consolidation_cycle_count, updated_at
|
|
230
|
+
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)
|
|
231
231
|
ON CONFLICT (agent_id) DO NOTHING`, [
|
|
232
232
|
r.agent_id, r.last_write_id, r.last_recall_context,
|
|
233
233
|
r.last_recall_ids ?? '[]', r.last_activity_at,
|