agent-working-memory 0.9.0 → 0.10.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.
Files changed (55) hide show
  1. package/dist/cli/migrate.js +29 -29
  2. package/dist/cli.js +324 -219
  3. package/dist/cli.js.map +1 -1
  4. package/dist/coordination/circuit-breaker.js +23 -23
  5. package/dist/core/salience.d.ts.map +1 -1
  6. package/dist/core/salience.js +10 -1
  7. package/dist/core/salience.js.map +1 -1
  8. package/dist/core/write-pipeline.d.ts.map +1 -1
  9. package/dist/core/write-pipeline.js +5 -1
  10. package/dist/core/write-pipeline.js.map +1 -1
  11. package/dist/storage/factory.d.ts +1 -1
  12. package/dist/storage/factory.d.ts.map +1 -1
  13. package/dist/storage/factory.js +16 -2
  14. package/dist/storage/factory.js.map +1 -1
  15. package/dist/storage/pglite-schema.js +143 -143
  16. package/dist/storage/pglite.d.ts.map +1 -1
  17. package/dist/storage/pglite.js +146 -138
  18. package/dist/storage/pglite.js.map +1 -1
  19. package/dist/storage/postgres.d.ts +228 -0
  20. package/dist/storage/postgres.d.ts.map +1 -0
  21. package/dist/storage/postgres.js +1221 -0
  22. package/dist/storage/postgres.js.map +1 -0
  23. package/package.json +3 -1
  24. package/src/api/index.ts +3 -3
  25. package/src/cli/migrate.ts +307 -307
  26. package/src/cli.ts +266 -268
  27. package/src/coordination/circuit-breaker.ts +83 -83
  28. package/src/coordination/failure-modes.ts +50 -50
  29. package/src/core/decay.ts +63 -63
  30. package/src/core/embeddings.ts +110 -110
  31. package/src/core/index.ts +5 -5
  32. package/src/core/logger.ts +36 -36
  33. package/src/core/ml-worker-entry.ts +194 -194
  34. package/src/core/ml-worker.ts +281 -281
  35. package/src/core/query-expander.ts +122 -122
  36. package/src/core/reranker.ts +119 -119
  37. package/src/core/salience.ts +10 -1
  38. package/src/core/write-pipeline.ts +5 -1
  39. package/src/engine/confidence.ts +120 -120
  40. package/src/engine/consolidation-scheduler.ts +242 -242
  41. package/src/engine/eval.ts +102 -102
  42. package/src/engine/eviction.ts +101 -101
  43. package/src/engine/index.ts +8 -8
  44. package/src/engine/retraction.ts +366 -366
  45. package/src/engine/staging.ts +74 -74
  46. package/src/storage/factory.ts +159 -147
  47. package/src/storage/index.ts +3 -3
  48. package/src/storage/pglite-schema.ts +166 -166
  49. package/src/storage/pglite.ts +1372 -1363
  50. package/src/storage/postgres.ts +1475 -0
  51. package/src/storage/store.ts +80 -80
  52. package/src/types/agent.ts +67 -67
  53. package/src/types/checkpoint.ts +46 -46
  54. package/src/types/eval.ts +100 -100
  55. package/src/types/index.ts +6 -6
@@ -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,