@tangle-network/agent-knowledge 7.0.0 → 7.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ### Added
6
+
7
+ - Added `runAgentMemoryLearningExperiment` for matched stateful-versus-stateless memory measurement under one shared cost limit.
8
+ - Added exact paired gain, explicitly labeled transfer probes, and repeated-probe forgetting reports.
9
+ - Limited learning gain to post-first-step probes, averaged repetitions within independent sequences, and added per-candidate intervals.
10
+ - Added recorded arm order for counterbalanced runs and exact sequence references for safe crash recovery.
11
+ - Added abort and resume support, content-addressed comparison and probe evidence, and exact cell artifact hashes.
12
+
13
+ ### Changed
14
+
15
+ - Memory experiment artifacts and cache identities now record `memoryMode` and a full `comparisonRef`; non-equivalent arms fail comparison.
16
+
17
+ ## 7.0.1
18
+
19
+ ### Changed
20
+
21
+ - Updated `@tangle-network/agent-eval` to `0.135.4` and `@tangle-network/agent-interface` to `0.37.0` so one installed stack uses the same exact trace-ingestion, source-identity, and interface contracts without older nested copies.
22
+
3
23
  ## 7.0.0
4
24
 
5
25
  ### Breaking Changes
@@ -49,7 +69,7 @@
49
69
 
50
70
  - Load `proper-lockfile` with a dynamic import inside the functions that take a lock, instead of at module scope.
51
71
  It pulls in `graceful-fs`, which patches Node's `fs` at import time (`fs.close = ...`).
52
- workerd exposes those as getter-only accessors, so the assignment threw while Cloudflare validated an uploaded Worker (`Cannot set property close of #<Object> which has only a getter [code: 10021]`), rejecting the whole Worker — including consumers that never take a lock.
72
+ workerd exposes those as getter-only accessors, so the assignment threw while Cloudflare validated an uploaded Worker (`Cannot set property close of #<Object> which has only a getter [code: 10021]`), rejecting the whole Worker, including consumers that never take a lock.
53
73
  `verify:package` now fails on any static import of a module that patches a Node builtin, because `wrangler deploy --dry-run` bundles without executing and cannot see this class of failure.
54
74
 
55
75
  ## 6.1.8
package/README.md CHANGED
@@ -239,6 +239,36 @@ Positive external work without a receipt is recorded as incomplete cost accounti
239
239
  Use `0` only for a free local path.
240
240
  Paid memory improvement defaults to a zero-dollar total limit; set `maxTotalCostUsd` and `maximumEvaluationCostUsd` before enabling paid work.
241
241
 
242
+ Use `runAgentMemoryLearningExperiment` to measure whether retained memory helps across ordered steps:
243
+
244
+ ```ts
245
+ import { runAgentMemoryLearningExperiment } from '@tangle-network/agent-knowledge/memory'
246
+
247
+ const result = await runAgentMemoryLearningExperiment({
248
+ experimentId: 'support-memory',
249
+ runDir: 'support-memory',
250
+ candidates: [memoryCandidate],
251
+ sequences,
252
+ seed: 42,
253
+ reps: 5,
254
+ armOrder: 'stateful-first',
255
+ costCeiling: 10,
256
+ })
257
+
258
+ console.log(result.comparison.gain)
259
+ ```
260
+
261
+ The function runs matched stateful and stateless arms with the same immutable candidate, tasks, executor, policy, seed, and repetitions.
262
+ The stateless arm clears declared scopes between steps; adapters must support scoped `clear`.
263
+ Gain excludes first-step probes and averages candidates and repetitions within each independent sequence.
264
+ Use `transferKey` on later probes for transfer and repeat one `retentionKey` across steps for forgetting.
265
+ Unmarked probes are not assigned those meanings.
266
+
267
+ Both arms share one cost limit and must have identical comparison references.
268
+ Run independent experiments with opposite `armOrder` values when provider behavior may drift.
269
+ Each saved probe includes the exact scoring input and content hash, so protect the run directory like the memory data itself.
270
+ Pass `signal` to cancel; rerun the same options and directory to resume completed work and cost records.
271
+
242
272
  ## Run benchmarks
243
273
 
244
274
  `@tangle-network/agent-knowledge/benchmarks` provides common case and report types for:
@@ -1,2 +1,2 @@
1
- import { A as INDUSTRY_RAG_BENCHMARKS, F as respondToIndustryRagBenchmarkSmokeCase, I as isKnowledgeMemoryBenchmarkCase, L as createInMemoryBenchmarkAdapter, M as buildIndustryMemoryBenchmarkSmokeCases, N as buildIndustryRagBenchmarkSmokeCases, P as respondToIndustryMemoryBenchmarkSmokeCase, R as createNoopMemoryBenchmarkAdapter, a as buildKnowledgeBenchmarkScenarios, c as runKnowledgeBenchmarkSuite, d as summarizeKnowledgeBenchmarkCampaign, i as runMemoryAdapterBenchmark, j as buildFirstPartyMemoryLifecycleBenchmarkCases, k as INDUSTRY_MEMORY_BENCHMARKS, l as scoreKnowledgeBenchmarkArtifact, n as parseKnowledgeBenchmarkJsonl, o as knowledgeBenchmarkJudge, r as parseKnowledgeBenchmarkQrels, s as renderKnowledgeBenchmarkReportMarkdown, t as buildRetrievalBenchmarkCasesFromQrels, u as scoreMemoryBenchmarkArtifact } from "../benchmarks-C8L7HJb4.js";
1
+ import { B as createNoopMemoryBenchmarkAdapter, F as buildIndustryRagBenchmarkSmokeCases, I as respondToIndustryMemoryBenchmarkSmokeCase, L as respondToIndustryRagBenchmarkSmokeCase, M as INDUSTRY_RAG_BENCHMARKS, N as buildFirstPartyMemoryLifecycleBenchmarkCases, P as buildIndustryMemoryBenchmarkSmokeCases, R as isKnowledgeMemoryBenchmarkCase, a as buildKnowledgeBenchmarkScenarios, c as runKnowledgeBenchmarkSuite, d as summarizeKnowledgeBenchmarkCampaign, i as runMemoryAdapterBenchmark, j as INDUSTRY_MEMORY_BENCHMARKS, l as scoreKnowledgeBenchmarkArtifact, n as parseKnowledgeBenchmarkJsonl, o as knowledgeBenchmarkJudge, r as parseKnowledgeBenchmarkQrels, s as renderKnowledgeBenchmarkReportMarkdown, t as buildRetrievalBenchmarkCasesFromQrels, u as scoreMemoryBenchmarkArtifact, z as createInMemoryBenchmarkAdapter } from "../benchmarks-CPl4AO1k.js";
2
2
  export { INDUSTRY_MEMORY_BENCHMARKS, INDUSTRY_RAG_BENCHMARKS, buildFirstPartyMemoryLifecycleBenchmarkCases, buildIndustryMemoryBenchmarkSmokeCases, buildIndustryRagBenchmarkSmokeCases, buildKnowledgeBenchmarkScenarios, buildRetrievalBenchmarkCasesFromQrels, createInMemoryBenchmarkAdapter, createNoopMemoryBenchmarkAdapter, isKnowledgeMemoryBenchmarkCase, knowledgeBenchmarkJudge, parseKnowledgeBenchmarkJsonl, parseKnowledgeBenchmarkQrels, renderKnowledgeBenchmarkReportMarkdown, respondToIndustryMemoryBenchmarkSmokeCase, respondToIndustryRagBenchmarkSmokeCase, runKnowledgeBenchmarkSuite, runMemoryAdapterBenchmark, scoreKnowledgeBenchmarkArtifact, scoreMemoryBenchmarkArtifact, summarizeKnowledgeBenchmarkCampaign };
@@ -1264,6 +1264,8 @@ function isMemoryProviderActor(actor) {
1264
1264
  //#endregion
1265
1265
  //#region src/memory/lifecycle.ts
1266
1266
  const DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS = 18e4;
1267
+ const MEMORY_OPERATION_CANCELLATION_TIMEOUT_MS = 4e3;
1268
+ const MEMORY_CAMPAIGN_DISPATCH_SHUTDOWN_TIMEOUT_MS = 5e3;
1267
1269
  var AgentMemoryLifecycleTimeoutError = class extends Error {
1268
1270
  operation;
1269
1271
  timeoutMs;
@@ -1296,16 +1298,37 @@ function releaseMemoryAdapterCreatedAfterAbort(input) {
1296
1298
  } catch {}
1297
1299
  }, () => void 0);
1298
1300
  }
1301
+ async function createBoundedMemoryAdapter(input) {
1302
+ input.signal?.throwIfAborted();
1303
+ const abortController = new AbortController();
1304
+ const creation = Promise.resolve().then(() => input.create(abortController.signal));
1305
+ releaseMemoryAdapterCreatedAfterAbort({
1306
+ creation,
1307
+ signal: abortController.signal,
1308
+ dispose: input.dispose
1309
+ });
1310
+ return runBoundedMemoryLifecycle({
1311
+ operation: input.operation,
1312
+ timeoutMs: input.timeoutMs,
1313
+ signal: input.signal,
1314
+ abortController,
1315
+ run: () => creation
1316
+ });
1317
+ }
1299
1318
  function resolveMemoryCleanupTimeoutMs(value, label) {
1300
1319
  const timeoutMs = value ?? 18e4;
1301
1320
  if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) throw new Error(`${label} cleanupTimeoutMs must be a positive safe integer`);
1302
1321
  return timeoutMs;
1303
1322
  }
1304
1323
  async function runBoundedMemoryLifecycle(input) {
1324
+ input.signal?.throwIfAborted();
1325
+ if (input.cancellationTimeoutMs !== void 0 && (!Number.isSafeInteger(input.cancellationTimeoutMs) || input.cancellationTimeoutMs <= 0)) throw new Error(`${input.operation} cancellationTimeoutMs must be a positive safe integer`);
1305
1326
  const priorTimeout = input.resource ? timedOutResources.get(input.resource) : void 0;
1306
1327
  if (priorTimeout) throw new AgentMemoryLifecycleUnsafeError(input.operation, priorTimeout);
1307
1328
  let timeout;
1329
+ let cancellationTimeout;
1308
1330
  let timeoutError;
1331
+ let relayAbort;
1309
1332
  const work = Promise.resolve().then(input.run);
1310
1333
  if (input.resource) {
1311
1334
  const resource = input.resource;
@@ -1323,12 +1346,41 @@ async function runBoundedMemoryLifecycle(input) {
1323
1346
  reject(timeoutError);
1324
1347
  }, input.timeoutMs);
1325
1348
  });
1349
+ const signal = input.signal;
1350
+ const cancellation = signal ? new Promise((_, reject) => {
1351
+ relayAbort = () => {
1352
+ const error = memoryLifecycleAbortError(input.operation);
1353
+ input.abortController?.abort(error);
1354
+ if (input.cancellationTimeoutMs === void 0) {
1355
+ reject(signal.reason ?? error);
1356
+ return;
1357
+ }
1358
+ cancellationTimeout = setTimeout(() => {
1359
+ timeoutError = new AgentMemoryLifecycleTimeoutError(`${input.operation} cancellation`, input.cancellationTimeoutMs);
1360
+ if (input.resource) timedOutResources.set(input.resource, timeoutError);
1361
+ reject(timeoutError);
1362
+ }, input.cancellationTimeoutMs);
1363
+ };
1364
+ if (signal.aborted) relayAbort();
1365
+ else signal.addEventListener("abort", relayAbort, { once: true });
1366
+ }) : void 0;
1326
1367
  try {
1327
- return await Promise.race([work, deadline]);
1368
+ return await Promise.race([
1369
+ work,
1370
+ deadline,
1371
+ ...cancellation ? [cancellation] : []
1372
+ ]);
1328
1373
  } finally {
1329
1374
  if (timeout) clearTimeout(timeout);
1375
+ if (cancellationTimeout) clearTimeout(cancellationTimeout);
1376
+ if (relayAbort) signal?.removeEventListener("abort", relayAbort);
1330
1377
  }
1331
1378
  }
1379
+ function memoryLifecycleAbortError(operation) {
1380
+ const error = /* @__PURE__ */ new Error(`${operation} aborted`);
1381
+ error.name = "AbortError";
1382
+ return error;
1383
+ }
1332
1384
  function memoryRecoveryDelayMs(adapter) {
1333
1385
  const isolation = adapter.branchIsolation;
1334
1386
  if (isolation?.mode !== "scoped" || isolation.processExitSafe !== false) return 0;
@@ -1336,13 +1388,29 @@ function memoryRecoveryDelayMs(adapter) {
1336
1388
  if (typeof delayMs !== "number" || !Number.isSafeInteger(delayMs) || delayMs <= 0) throw new Error(`${adapter.id}: processExitSafe=false requires a positive recoveryDelayMs for abandoned writes`);
1337
1389
  return delayMs;
1338
1390
  }
1339
- async function sleepForMemoryRecovery(delayMs, assertOwned, timeoutMs = delayMs, operation = "memory recovery visibility wait") {
1391
+ async function sleepForMemoryRecovery(delayMs, assertOwned, timeoutMs = delayMs, operation = "memory recovery visibility wait", signal) {
1340
1392
  if (delayMs <= 0) return;
1341
1393
  if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) throw new Error(`${operation} timeout must be a positive safe integer`);
1342
- await new Promise((resolve) => setTimeout(resolve, Math.min(delayMs, timeoutMs)));
1394
+ signal?.throwIfAborted();
1395
+ await waitForMemoryRecoveryDelay(Math.min(delayMs, timeoutMs), signal, operation);
1343
1396
  await assertOwned();
1344
1397
  if (delayMs > timeoutMs) throw new AgentMemoryLifecycleTimeoutError(operation, timeoutMs);
1345
1398
  }
1399
+ async function waitForMemoryRecoveryDelay(delayMs, signal, operation) {
1400
+ await new Promise((resolve, reject) => {
1401
+ let timeout;
1402
+ const abort = () => {
1403
+ if (timeout) clearTimeout(timeout);
1404
+ reject(signal?.reason ?? memoryLifecycleAbortError(operation));
1405
+ };
1406
+ timeout = setTimeout(() => {
1407
+ signal?.removeEventListener("abort", abort);
1408
+ resolve();
1409
+ }, delayMs);
1410
+ if (signal?.aborted) abort();
1411
+ else signal?.addEventListener("abort", abort, { once: true });
1412
+ });
1413
+ }
1346
1414
  function createMemoryExecutionPool(limit) {
1347
1415
  let active = 0;
1348
1416
  const waiters = [];
@@ -2713,6 +2781,6 @@ function defaultDocumentTarget(documentId, targetKind) {
2713
2781
  }
2714
2782
  }
2715
2783
  //#endregion
2716
- export { INDUSTRY_RAG_BENCHMARKS as A, memoryWriteResultToSourceRecord as B, appendDurableJournalEvent as C, reconcileInterruptedMemoryPaidCalls as D, readActiveAttemptJournal as E, respondToIndustryRagBenchmarkSmokeCase as F, retrievalRecallJudge as G, partitionRetrievalScenarios as H, isKnowledgeMemoryBenchmarkCase as I, scoreRetrievalArtifact as K, createInMemoryBenchmarkAdapter as L, buildIndustryMemoryBenchmarkSmokeCases as M, buildIndustryRagBenchmarkSmokeCases as N, reserveRecoveryAttempts as O, respondToIndustryMemoryBenchmarkSmokeCase as P, createNoopMemoryBenchmarkAdapter as R, appendAttemptJournalEvent as S, hasSettledPaidCall as T, retrievalConfigFromSurface as U, buildRetrievalEvalDispatch as V, retrievalConfigSurface as W, memoryRecoveryDelayMs as _, buildKnowledgeBenchmarkScenarios as a, runBoundedMemoryLifecycle as b, runKnowledgeBenchmarkSuite as c, summarizeKnowledgeBenchmarkCampaign as d, acquireAgentMemoryRunLease as f, createMemoryExecutionPool as g, DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS as h, runMemoryAdapterBenchmark as i, buildFirstPartyMemoryLifecycleBenchmarkCases as j, INDUSTRY_MEMORY_BENCHMARKS as k, scoreKnowledgeBenchmarkArtifact as l, AgentMemoryLifecycleUnsafeError as m, parseKnowledgeBenchmarkJsonl as n, knowledgeBenchmarkJudge as o, AgentMemoryLifecycleTimeoutError as p, parseKnowledgeBenchmarkQrels as r, renderKnowledgeBenchmarkReportMarkdown as s, buildRetrievalBenchmarkCasesFromQrels as t, scoreMemoryBenchmarkArtifact as u, releaseMemoryAdapterCreatedAfterAbort as v, assertNoInterruptedPaidCalls as w, sleepForMemoryRecovery as x, resolveMemoryCleanupTimeoutMs as y, memoryHitToSourceRecord as z };
2784
+ export { reserveRecoveryAttempts as A, createNoopMemoryBenchmarkAdapter as B, sleepForMemoryRecovery as C, hasSettledPaidCall as D, assertNoInterruptedPaidCalls as E, buildIndustryRagBenchmarkSmokeCases as F, retrievalConfigFromSurface as G, memoryWriteResultToSourceRecord as H, respondToIndustryMemoryBenchmarkSmokeCase as I, scoreRetrievalArtifact as J, retrievalConfigSurface as K, respondToIndustryRagBenchmarkSmokeCase as L, INDUSTRY_RAG_BENCHMARKS as M, buildFirstPartyMemoryLifecycleBenchmarkCases as N, readActiveAttemptJournal as O, buildIndustryMemoryBenchmarkSmokeCases as P, isKnowledgeMemoryBenchmarkCase as R, runBoundedMemoryLifecycle as S, appendDurableJournalEvent as T, buildRetrievalEvalDispatch as U, memoryHitToSourceRecord as V, partitionRetrievalScenarios as W, MEMORY_OPERATION_CANCELLATION_TIMEOUT_MS as _, buildKnowledgeBenchmarkScenarios as a, memoryRecoveryDelayMs as b, runKnowledgeBenchmarkSuite as c, summarizeKnowledgeBenchmarkCampaign as d, acquireAgentMemoryRunLease as f, MEMORY_CAMPAIGN_DISPATCH_SHUTDOWN_TIMEOUT_MS as g, DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS as h, runMemoryAdapterBenchmark as i, INDUSTRY_MEMORY_BENCHMARKS as j, reconcileInterruptedMemoryPaidCalls as k, scoreKnowledgeBenchmarkArtifact as l, AgentMemoryLifecycleUnsafeError as m, parseKnowledgeBenchmarkJsonl as n, knowledgeBenchmarkJudge as o, AgentMemoryLifecycleTimeoutError as p, retrievalRecallJudge as q, parseKnowledgeBenchmarkQrels as r, renderKnowledgeBenchmarkReportMarkdown as s, buildRetrievalBenchmarkCasesFromQrels as t, scoreMemoryBenchmarkArtifact as u, createBoundedMemoryAdapter as v, appendAttemptJournalEvent as w, resolveMemoryCleanupTimeoutMs as x, createMemoryExecutionPool as y, createInMemoryBenchmarkAdapter as z };
2717
2785
 
2718
- //# sourceMappingURL=benchmarks-C8L7HJb4.js.map
2786
+ //# sourceMappingURL=benchmarks-CPl4AO1k.js.map