@tangle-network/agent-knowledge 4.1.0 → 5.0.1

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.
@@ -1,706 +1,8 @@
1
- import { b as AgentMemoryAdapter, j as AgentMemorySearchOptions, d as AgentMemoryContext, f as AgentMemoryHit, i as AgentMemoryScope, k as AgentMemoryWriteInput, l as AgentMemoryWriteResult, u as KnowledgeBenchmarkFamily, D as KnowledgeBenchmarkSplit, H as KnowledgeMemoryBenchmarkTaskKind, J as KnowledgeMemoryFactMatcher, h as AgentMemoryRunLease, I as KnowledgeMemoryEvent, G as KnowledgeMemoryBenchmarkCase, e as AgentMemoryControllerMode, A as AgentMemoryAcquireRunLease, $ as RetrievalHoldoutConfig, _ as RetrievalHoldoutCallContext, a2 as RetrievalHoldoutResult, Z as RetrievalHoldoutBypassReason, a1 as RetrievalHoldoutEvent } from '../types-DP38encz.js';
2
- export { c as AgentMemoryBranchIsolation, g as AgentMemoryKind, Q as OwnedAgentMemoryRunLease, a0 as RetrievalHoldoutEligibleItem, a3 as RetrievalHoldoutSessionState, af as acquireAgentMemoryRunLease } from '../types-DP38encz.js';
3
- import { CampaignResult, Scenario, DispatchContext, CampaignStorage, CostLedgerHandle, JudgeConfig, HeldoutSignificance, Lineage, GovernorContext, GovernorOp, SurfaceProposer, LineageStore, HeldoutSignificanceOptions } from '@tangle-network/agent-eval/campaign';
4
- import { OffPolicyTrajectory } from '@tangle-network/agent-eval/rl';
5
- import { z } from 'zod';
6
- import { S as SourceRecord } from '../types-6x0OpfW6.js';
7
-
8
- declare function defaultGetMemoryContext(adapter: Pick<AgentMemoryAdapter, 'search'>, query: string, options?: AgentMemorySearchOptions): Promise<AgentMemoryContext>;
9
- declare function renderMemoryContext(hits: AgentMemoryHit[]): string;
10
-
11
- type AgentMemoryVisibility = 'private' | 'team' | 'shared';
12
- type AgentMemoryBranchLifetime = 'resumable' | 'attempt';
13
- interface AgentMemorySharingPolicy {
14
- read: readonly AgentMemoryVisibility[];
15
- write: AgentMemoryVisibility;
16
- }
17
- interface AgentMemoryJournalEntry {
18
- sequence: number;
19
- input: AgentMemoryWriteInput;
20
- result: AgentMemoryWriteResult;
21
- }
22
- interface AgentMemoryBranchSnapshot {
23
- branchId: string;
24
- lifetime: AgentMemoryBranchLifetime;
25
- parentBranchId?: string;
26
- adapterId: string;
27
- policy: AgentMemorySharingPolicy;
28
- baseScope: AgentMemoryScope;
29
- journal: readonly AgentMemoryJournalEntry[];
30
- digest: `sha256:${string}`;
31
- }
32
- interface AgentMemoryBranch extends AgentMemoryAdapter {
33
- readonly branchId: string;
34
- readonly lifetime: AgentMemoryBranchLifetime;
35
- readonly parentBranchId?: string;
36
- readonly policy: AgentMemorySharingPolicy;
37
- snapshot(): Promise<AgentMemoryBranchSnapshot>;
38
- fork(options: {
39
- branchId: string;
40
- adapter?: AgentMemoryAdapter;
41
- policy?: AgentMemorySharingPolicy;
42
- baseScope?: AgentMemoryScope;
43
- lifetime?: AgentMemoryBranchLifetime;
44
- }): Promise<AgentMemoryBranch>;
45
- }
46
- interface CreateAgentMemoryBranchOptions {
47
- adapter: AgentMemoryAdapter;
48
- branchId: string;
49
- parentBranchId?: string;
50
- policy?: AgentMemorySharingPolicy;
51
- baseScope?: AgentMemoryScope;
52
- /** Attempt branches use a new ID after a process restart and cannot bind persisted state. */
53
- lifetime?: AgentMemoryBranchLifetime;
54
- /** Rebind a persisted branch whose external memory is still present. */
55
- snapshot?: AgentMemoryBranchSnapshot;
56
- /** Optional exact logical scopes allowed to write, used by crash-safe experiments. */
57
- allowedWriteScopes?: readonly AgentMemoryScope[];
58
- }
59
- interface ForkAgentMemoryBranchSnapshotOptions {
60
- snapshot: AgentMemoryBranchSnapshot;
61
- adapter: AgentMemoryAdapter;
62
- branchId: string;
63
- policy?: AgentMemorySharingPolicy;
64
- baseScope?: AgentMemoryScope;
65
- lifetime?: AgentMemoryBranchLifetime;
66
- }
67
- /**
68
- * Isolates one candidate branch and records accepted writes for durable resume
69
- * or replay into a child branch, including a child backed by another provider.
70
- */
71
- declare function createAgentMemoryBranch(options: CreateAgentMemoryBranchOptions): AgentMemoryBranch;
72
- /** Replays a durable journal into a fresh provider branch. */
73
- declare function forkAgentMemoryBranchSnapshot(options: ForkAgentMemoryBranchSnapshotOptions): Promise<AgentMemoryBranch>;
74
-
75
- interface AgentMemorySequenceProbe {
76
- id: string;
77
- query: string;
78
- scope?: AgentMemoryScope;
79
- limit?: number;
80
- taskKind?: KnowledgeMemoryBenchmarkTaskKind;
81
- requiredFacts?: readonly KnowledgeMemoryFactMatcher[];
82
- forbiddenFacts?: readonly KnowledgeMemoryFactMatcher[];
83
- expectedEventIds?: readonly string[];
84
- expectedActorIds?: readonly string[];
85
- referenceAnswer?: string;
86
- }
87
- interface AgentMemorySequenceStep {
88
- id: string;
89
- instruction?: string;
90
- scope?: AgentMemoryScope;
91
- writes?: readonly AgentMemoryWriteInput[];
92
- parallelWrites?: boolean;
93
- probes?: readonly AgentMemorySequenceProbe[];
94
- parallelProbes?: boolean;
95
- metadata?: Record<string, unknown>;
96
- }
97
- interface AgentMemorySequence {
98
- id: string;
99
- family: KnowledgeBenchmarkFamily | string;
100
- split?: KnowledgeBenchmarkSplit;
101
- steps: readonly AgentMemorySequenceStep[];
102
- /** Exact scopes a runtime callback may write beyond scopes declared by steps. */
103
- cleanupScopes?: readonly AgentMemoryScope[];
104
- tags?: readonly string[];
105
- metadata?: Record<string, unknown>;
106
- }
107
- interface BuildAgentMemorySequencesFromBenchmarkCasesOptions {
108
- memoryAgentId?: string;
109
- eventScope?: (input: {
110
- event: KnowledgeMemoryEvent;
111
- case: KnowledgeMemoryBenchmarkCase;
112
- eventIndex: number;
113
- }) => AgentMemoryScope;
114
- probeScope?: (testCase: KnowledgeMemoryBenchmarkCase) => AgentMemoryScope;
115
- }
116
- interface AgentMemoryExperimentCandidate {
117
- id: string;
118
- label?: string;
119
- /** Change when provider configuration changes so cached cells cannot be reused. */
120
- ref: string;
121
- /** Local construction is free; call markExternalCall before billable provisioning or reconnects. */
122
- createAdapter(input: {
123
- branchId: string;
124
- sequence: AgentMemorySequence;
125
- rep: number;
126
- seed: number;
127
- purpose: 'execute' | 'recovery';
128
- signal: AbortSignal;
129
- markExternalCall(): void;
130
- }): AgentMemoryAdapter | null | Promise<AgentMemoryAdapter | null>;
131
- policy?: AgentMemorySharingPolicy;
132
- baseScope?: AgentMemoryScope;
133
- /** Conservative external provider charge for one complete history. */
134
- externalCostUsdPerSequence?: number;
135
- /** Conservative extra provider charge when recovering one interrupted history. */
136
- externalRecoveryCostUsdPerAttempt?: number;
137
- /** Release resources and, when cleanupBranches is false, delete the isolated state. */
138
- disposeAdapter?(adapter: AgentMemoryAdapter): Promise<void>;
139
- }
140
- interface AgentMemorySequenceProbeResult {
141
- id: string;
142
- stepId: string;
143
- query: string;
144
- score: number;
145
- passed: boolean;
146
- dimensions: Record<string, number>;
147
- applicableDimensions: readonly string[];
148
- notes: string;
149
- hitIds: readonly string[];
150
- }
151
- interface AgentMemorySequenceArtifact {
152
- candidateId: string;
153
- sequenceId: string;
154
- score: number;
155
- passed: boolean;
156
- dimensions: Record<string, number>;
157
- dimensionSampleCounts: Record<string, number>;
158
- probes: readonly AgentMemorySequenceProbeResult[];
159
- branchDigest: string;
160
- journalEntries: number;
161
- durationMs: number;
162
- }
163
- interface AgentMemorySequenceScenario extends Scenario {
164
- kind: 'agent-memory-sequence';
165
- candidateId: string;
166
- sequenceId: string;
167
- sequence: AgentMemorySequence;
168
- seedGroup: string;
169
- }
170
- interface AgentMemoryExperimentRankingRow {
171
- rank: number;
172
- candidateId: string;
173
- label: string;
174
- scoreMean: number;
175
- passRate: number;
176
- totalSequences: number;
177
- totalCells: number;
178
- totalProbes: number;
179
- cellsFailed: number;
180
- totalCostUsd: number;
181
- durationMs: number;
182
- dimensions: Record<string, number>;
183
- }
184
- interface RunAgentMemoryExperimentOptions {
185
- experimentId: string;
186
- /** Stable external branch namespace; distributed workers must use the same value. */
187
- experimentRunId?: string;
188
- sequences: readonly AgentMemorySequence[];
189
- candidates: readonly AgentMemoryExperimentCandidate[];
190
- /** Retired candidates retained only so interrupted branches can be cleaned on resume. */
191
- recoveryCandidates?: readonly AgentMemoryExperimentCandidate[];
192
- runDir: string;
193
- executeStep?: (input: {
194
- memory: AgentMemoryBranch;
195
- candidateId: string;
196
- sequence: AgentMemorySequence;
197
- step: AgentMemorySequenceStep;
198
- context: DispatchContext;
199
- }) => Promise<void>;
200
- /** Required with executeStep; identify the runtime/profile behavior in cache keys. */
201
- executeStepRef?: string;
202
- onBranchSnapshot?: (input: {
203
- candidateId: string;
204
- sequenceId: string;
205
- cellId: string;
206
- snapshot: AgentMemoryBranchSnapshot;
207
- }) => Promise<void> | void;
208
- cleanupBranches?: boolean;
209
- storage?: CampaignStorage;
210
- repo?: string;
211
- seed?: number;
212
- reps?: number;
213
- resumable?: boolean;
214
- costCeiling?: number;
215
- /** Shared across nested experiments when an outer improvement run owns spend. */
216
- costLedger?: CostLedgerHandle;
217
- costPhase?: string;
218
- maxConcurrency?: number;
219
- dispatchTimeoutMs?: number;
220
- /** Total deadline for each provider cleanup, close, or recovery operation. */
221
- cleanupTimeoutMs?: number;
222
- /** Refuse a damaged run with more unfinished attempts than this. Default 1000. */
223
- maxRecoveryAttempts?: number;
224
- /** Bound repeated provider cleanup after process crashes. Default 3 per attempt. */
225
- maxRecoveryRetriesPerAttempt?: number;
226
- now?: () => Date;
227
- /** Required with custom storage when all controllers are confined to one process. */
228
- controllerMode?: AgentMemoryControllerMode;
229
- /** Required for distributed controllers that share custom storage. */
230
- acquireRunLease?: AgentMemoryAcquireRunLease;
231
- }
232
- type AgentMemoryExperimentRunLease = AgentMemoryRunLease;
233
- interface AgentMemoryAttemptEvent {
234
- schema: 2;
235
- status: 'started' | 'cleaned';
236
- branchId: string;
237
- candidateId: string;
238
- candidateRef: string;
239
- sequenceId: string;
240
- rep: number;
241
- seed: number;
242
- cleanupBranches: boolean;
243
- externalCostUsdPerSequence: number;
244
- externalRecoveryCostUsdPerAttempt: number;
245
- recordedAt: string;
246
- recovery: boolean;
247
- }
248
- interface RunAgentMemoryExperimentResult {
249
- campaign: CampaignResult<AgentMemorySequenceArtifact, AgentMemorySequenceScenario>;
250
- rows: readonly AgentMemoryExperimentRankingRow[];
251
- totalCostUsd: number;
252
- /** Recovery spend for retired candidates, excluded from ranking rows but included in totalCostUsd. */
253
- unrankedRecoveryCostUsd: number;
254
- leaderCandidateId?: string;
255
- rankingJsonPath: string;
256
- rankingMarkdownPath: string;
257
- attemptLogPath: string;
258
- recoveryLogPath: string;
259
- }
260
-
261
- /** Converts existing ordered memory benchmark cases into executable histories. */
262
-
263
- declare function buildAgentMemorySequencesFromBenchmarkCases(cases: readonly KnowledgeMemoryBenchmarkCase[], options?: BuildAgentMemorySequencesFromBenchmarkCasesOptions): AgentMemorySequence[];
264
- declare function buildAgentMemorySequenceScenarios(sequences: readonly AgentMemorySequence[], candidates: readonly Pick<AgentMemoryExperimentCandidate, 'id'>[]): AgentMemorySequenceScenario[];
265
- declare function agentMemorySequenceJudge(): JudgeConfig<AgentMemorySequenceArtifact, AgentMemorySequenceScenario>;
266
-
267
- /** Runs ordered, branch-isolated memory histories across candidate systems. */
268
- declare function runAgentMemoryExperiment(options: RunAgentMemoryExperimentOptions): Promise<RunAgentMemoryExperimentResult>;
269
-
270
- interface GraphitiMcpClientLike {
271
- callTool(request: {
272
- name: string;
273
- arguments?: Record<string, unknown>;
274
- }): Promise<unknown>;
275
- }
276
- interface GraphitiMemoryAdapterOptions {
277
- client: GraphitiMcpClientLike;
278
- id?: string;
279
- /** Stable server/deployment identity for cache-key helpers. Never put credentials here. */
280
- backendRef?: string;
281
- defaultScope?: AgentMemoryScope;
282
- consistency?: 'queued' | 'visible';
283
- ingestionTimeoutMs?: number;
284
- pollIntervalMs?: number;
285
- /** Maximum episodes inspected to prove a queued write became visible. */
286
- episodeScanLimit?: number;
287
- provenanceEpisodeLimit?: number;
288
- search?: readonly ('facts' | 'nodes')[];
289
- toolNames?: Partial<GraphitiToolNames>;
290
- }
291
- interface GraphitiToolNames {
292
- addMemory: string;
293
- searchFacts: string;
294
- searchNodes: string;
295
- getEpisodes: string;
296
- clearGraph: string;
297
- }
298
- /** Connects the official Graphiti MCP server without coupling to its Python internals. */
299
- declare function createGraphitiMemoryAdapter(options: GraphitiMemoryAdapterOptions): AgentMemoryAdapter;
300
- declare function graphitiMemoryAdapterIdentity(options: Pick<GraphitiMemoryAdapterOptions, 'id' | 'consistency' | 'ingestionTimeoutMs' | 'pollIntervalMs' | 'episodeScanLimit' | 'provenanceEpisodeLimit' | 'search' | 'toolNames' | 'defaultScope'> & {
301
- backendRef: string;
302
- }): string;
303
-
304
- /**
305
- * Deterministic uniform [0,1) for assignment draws. The sha256 key derivation is ours — it makes
306
- * every draw replayable from the logged keys alone (design rule D5) — while the generator core is
307
- * the substrate's `mulberry32` (@tangle-network/agent-eval statistics vocabulary), seeded with the
308
- * top 32 bits of the digest, so the statistical machinery is reused rather than forked.
309
- */
310
- declare function deterministicRng(key: string): number;
311
- /**
312
- * Value-hash of the knobs that DEFINE the experiment (epsilon + watchlist, order-independent).
313
- * Everything else on the config (callbacks, attribution stamps, privacy flags) does not change
314
- * which assignments are drawn, so it stays out of the hash.
315
- */
316
- declare function retrievalHoldoutConfigHash(config: Pick<RetrievalHoldoutConfig, 'epsilon' | 'watchlist'>): string;
317
- /**
318
- * Pure per-call holdout: takes post-filter hits, returns delivered hits plus the log event
319
- * and the next session state. Suppression only removes items (no backfill), and it happens
320
- * before rendering so a drop session's context is byte-identical to a natural smaller retrieval.
321
- */
322
- declare function applyRetrievalHoldout(hits: AgentMemoryHit[], config: RetrievalHoldoutConfig, ctx?: RetrievalHoldoutCallContext): RetrievalHoldoutResult;
323
- /**
324
- * Logs a holdout event for adapter context paths that answer WITHOUT going through the
325
- * search→render seam (Neo4j short-term conversation context, raw-string getContext results),
326
- * so a consumer with a holdout configured still sees every call and the fraction-under-experiment
327
- * denominator stays honest instead of silently losing these calls. No suppression is applied:
328
- * dropping is only meaningful for retrieved memory hits, never for conversation context.
329
- */
330
- declare function emitRetrievalHoldoutBypass(hits: AgentMemoryHit[], config: RetrievalHoldoutConfig, ctx: Omit<RetrievalHoldoutCallContext, 'session'>, bypassReason: RetrievalHoldoutBypassReason): RetrievalHoldoutEvent;
331
- /**
332
- * Clears all sticky-session state. For test isolation and experiment-epoch boundaries;
333
- * sessions in flight afterwards re-draw deterministically (same rng keys), so with the default
334
- * rng a reset is invisible in the logs unless eligibility sets changed in between.
335
- */
336
- declare function resetRetrievalHoldoutRegistry(): void;
337
- /**
338
- * Convenience wrapper that threads session state internally, keyed by the VALUE of the
339
- * experiment-defining knobs (configHash = epsilon + sorted watchlist) plus sessionId, so a fresh
340
- * config object per call — the natural pattern when options are built inline — keeps full
341
- * stickiness. Distinct experiments never share session state; two config objects with the same
342
- * epsilon/watchlist are the same experiment by definition.
343
- */
344
- declare function applySessionStickyRetrievalHoldout(hits: AgentMemoryHit[], config: RetrievalHoldoutConfig, ctx?: Omit<RetrievalHoldoutCallContext, 'session'>): RetrievalHoldoutResult;
345
- /** Aggregated view of one session's holdout exposure — the randomization unit of this design. */
346
- interface RetrievalHoldoutSessionSummary {
347
- /** `${configHash}:${sessionIdHash}` — the trajectory's runId. */
348
- runId: string;
349
- configHash: string;
350
- sessionIdHash: string;
351
- sessionHoldout: boolean;
352
- sessionTargetId: string | null;
353
- /** Item actually suppressed in this session (equals sessionTargetId when a drop occurred). */
354
- droppedId: string | null;
355
- /** |watchlist ∩ E| at the session's first intersecting randomized call; 0 when never intersecting. */
356
- firstCandidateCount: number;
357
- /** Randomized retrieval calls observed for this session. */
358
- callCount: number;
359
- /** Adapter bypass calls observed for this session (logged, never randomized). */
360
- bypassCallCount: number;
361
- /** Session-level probability of the OBSERVED assignment under the behavior policy. */
362
- behaviorProb: number;
363
- /** True when the session's events disagree on arm or target (e.g. registry eviction re-draw). */
364
- mixedExposure: boolean;
365
- /** Present only on sessions surfaced in `excluded` rather than converted. */
366
- exclusionReason?: 'mixed-exposure' | 'no-randomized-calls';
367
- }
368
- interface RetrievalHoldoutOffPolicyOptions {
369
- /**
370
- * Realized outcome PER SESSION, keyed by sessionIdHash — the session is the randomization
371
- * unit, so rewards are per session, never per call. A missing entry for an included session
372
- * throws: silently dropping unscored sessions would corrupt the estimator's denominator, so
373
- * filter events to scored sessions upstream instead.
374
- */
375
- rewards: Record<string, number>;
376
- /**
377
- * Target-policy probability of the session's observed assignment. Default models the
378
- * always-deliver-in-full policy: 1 for full-delivery sessions, 0 for drop sessions.
379
- */
380
- targetProb?: (session: RetrievalHoldoutSessionSummary) => number;
381
- /** Per-session reward-model prediction enabling `doublyRobust`; when absent, qHat is null. */
382
- qHat?: (session: RetrievalHoldoutSessionSummary) => number | null;
383
- }
384
- interface RetrievalHoldoutOffPolicyResult {
385
- /** One trajectory per (configHash, sessionIdHash), never per call. */
386
- trajectories: OffPolicyTrajectory[];
387
- /** 1:1 with `trajectories` (same order): the diagnostic view of each converted session. */
388
- sessions: RetrievalHoldoutSessionSummary[];
389
- /** Sessions not converted because exposure was mixed or retrieval was bypassed. */
390
- excluded: RetrievalHoldoutSessionSummary[];
391
- /** Events with no sessionIdHash: outside session randomization, cannot join a reward. */
392
- unattributableEvents: number;
393
- }
394
- /**
395
- * Maps retrieval-dropout events onto one `OffPolicyTrajectory` per session for use with
396
- * `inverseProbabilityWeighting`, `selfNormalizedImportanceWeighting`, or `doublyRobust`.
397
- * Randomization occurs once per session: the arm is selected with P(dropout) = epsilon and
398
- * the sticky target is drawn once,
399
- * uniformly over watchlist ∩ E at the session's first intersecting call.
400
- *
401
- * Session-level action space and behavior probabilities (they sum to 1 by construction):
402
- * - full delivery: `1 - epsilon`;
403
- * - drop candidate i of k = |watchlist ∩ E_first|: `epsilon / k` each (the draw event's logged
404
- * `dropPropensity`);
405
- * - sessions whose eligibility sets never intersect the watchlist: probability 1, because full
406
- * delivery was certain in either arm.
407
- *
408
- * Per-call events are repeated observations WITHIN one session-level randomization; per-call
409
- * IPW is statistically invalid for this design (per-call "propensities" imply an action
410
- * distribution summing to more than 1 and bias IPS downward). Calls where the sticky target is
411
- * absent from E, and adapter bypass calls, fold into the session summary (callCount /
412
- * bypassCallCount) instead of generating independent propensities.
413
- *
414
- * Join contract: `rewards` is keyed by `sessionIdHash` (sha256(sessionId) first 16 hex; compute
415
- * the same prefix over the outcome table's session ids, or log with
416
- * `includePlaintextIdentifiers: true` and join on raw ids upstream). Events are grouped per
417
- * (configHash, sessionIdHash) so different experiment configs are never pooled. Mixed-exposure
418
- * sessions (arm or target disagreement, e.g. after registry eviction) are excluded from the
419
- * trajectories and surfaced in `excluded` for analysis.
420
- */
421
- declare function toOffPolicyTrajectory(events: RetrievalHoldoutEvent[], options: RetrievalHoldoutOffPolicyOptions): RetrievalHoldoutOffPolicyResult;
422
-
423
- interface AgentMemoryImprovementSeed<TConfig> {
424
- config: TConfig;
425
- track: string;
426
- vision?: string;
427
- proposer: string;
428
- }
429
- interface AgentMemoryDimensionComparison {
430
- dimension: string;
431
- n: number;
432
- expectedN: number;
433
- measured: boolean;
434
- meanDelta: number;
435
- low: number;
436
- high: number;
437
- tolerance: number;
438
- regressed: boolean;
439
- }
440
- interface AgentMemoryPromotionDecision {
441
- status: 'promote' | 'hold' | 'no-change';
442
- reasons: readonly string[];
443
- baselineScore: number;
444
- winnerScore: number;
445
- lift: number;
446
- significance?: HeldoutSignificance;
447
- criticalDimensions: readonly AgentMemoryDimensionComparison[];
448
- }
449
- interface AgentMemoryActivation {
450
- id: string;
451
- status: 'not-eligible' | 'not-configured' | 'pending' | 'activated' | 'recovered' | 'already-activated';
452
- journalPath: string;
453
- }
454
- interface AgentMemoryActivationDriver<TConfig> {
455
- /** Change whenever activation behavior or the external target changes. */
456
- ref: string;
457
- /** Return the exact currently active configuration. */
458
- readCurrent(): Promise<TConfig>;
459
- /** Atomically replace expectedConfig with config, or fail on a concurrent change. */
460
- compareAndSet(input: {
461
- activationId: string;
462
- expectedConfig: TConfig;
463
- expectedSurfaceHash: string;
464
- config: TConfig;
465
- surfaceHash: string;
466
- decision: AgentMemoryPromotionDecision;
467
- lineage: Lineage;
468
- holdout: RunAgentMemoryExperimentResult;
469
- }): Promise<void>;
470
- }
471
- type AgentMemoryImprovementRunLease = AgentMemoryRunLease;
472
- interface AgentMemoryGovernor {
473
- decide(context: GovernorContext & {
474
- costLedger: CostLedgerHandle;
475
- costPhase: string;
476
- }): GovernorOp | Promise<GovernorOp>;
477
- }
478
- interface RunAgentMemoryImprovementOptions<TConfig> {
479
- experimentId: string;
480
- trainSequences: readonly AgentMemorySequence[];
481
- holdoutSequences: readonly AgentMemorySequence[];
482
- /** First entry is the current baseline; remaining entries seed independent search tracks. */
483
- seeds: readonly AgentMemoryImprovementSeed<TConfig>[];
484
- createCandidate(input: {
485
- config: TConfig;
486
- candidateId: string;
487
- surfaceHash: string;
488
- }): Omit<AgentMemoryExperimentCandidate, 'id'> | Promise<Omit<AgentMemoryExperimentCandidate, 'id'>>;
489
- proposer: SurfaceProposer;
490
- /** Optional proposer implementations keyed by seed and branch proposer labels. */
491
- proposers?: Readonly<Record<string, SurfaceProposer>>;
492
- /** Stable version or commit for the candidate factory, proposer, and governor. */
493
- improvementRef: string;
494
- governor?: AgentMemoryGovernor;
495
- budget: {
496
- maxSteps: number;
497
- };
498
- populationSize?: number;
499
- candidateConcurrency?: number;
500
- sequenceConcurrency?: number;
501
- runDir: string;
502
- repo?: string;
503
- storage?: CampaignStorage;
504
- lineageStore?: LineageStore;
505
- /** Required with custom storage when all controllers are confined to one process. */
506
- controllerMode?: AgentMemoryControllerMode;
507
- /** Required for distributed controllers using custom storage. Worker concurrency is independent. */
508
- acquireRunLease?: AgentMemoryAcquireRunLease;
509
- seed?: number;
510
- reps?: number;
511
- resumable?: boolean;
512
- dispatchTimeoutMs?: number;
513
- cleanupTimeoutMs?: number;
514
- maxRecoveryAttempts?: number;
515
- maxRecoveryRetriesPerAttempt?: number;
516
- maxTotalCostUsd?: number;
517
- executeStep?: RunAgentMemoryExperimentOptions['executeStep'];
518
- executeStepRef?: string;
519
- onBranchSnapshot?: RunAgentMemoryExperimentOptions['onBranchSnapshot'];
520
- cleanupBranches?: boolean;
521
- serializeConfig?: (config: TConfig) => string;
522
- parseConfig?: (surface: string) => TConfig;
523
- significance?: HeldoutSignificanceOptions;
524
- criticalDimensions?: readonly string[];
525
- criticalDimensionTolerance?: number;
526
- minHoldoutScore?: number;
527
- activation?: AgentMemoryActivationDriver<TConfig>;
528
- activationTimeoutMs?: number;
529
- now?: () => Date;
530
- }
531
- interface RunAgentMemoryImprovementResult<TConfig> {
532
- lineage: Lineage;
533
- baselineConfig: TConfig;
534
- winnerConfig: TConfig;
535
- baselineSurface: string;
536
- winnerSurface: string;
537
- baselineSurfaceHash: string;
538
- winnerSurfaceHash: string;
539
- decision: AgentMemoryPromotionDecision;
540
- activation: AgentMemoryActivation;
541
- holdout?: RunAgentMemoryExperimentResult;
542
- totalCostUsd: number;
543
- resultJsonPath: string;
544
- }
545
-
546
- /** Searches branchable memory configurations and activates only a fresh holdout win. */
547
- declare function runAgentMemoryImprovement<TConfig>(options: RunAgentMemoryImprovementOptions<TConfig>): Promise<RunAgentMemoryImprovementResult<TConfig>>;
548
-
549
- declare const DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS = 180000;
550
- declare class AgentMemoryLifecycleTimeoutError extends Error {
551
- readonly operation: string;
552
- readonly timeoutMs: number;
553
- constructor(operation: string, timeoutMs: number);
554
- }
555
- declare class AgentMemoryLifecycleUnsafeError extends Error {
556
- readonly operation: string;
557
- readonly priorTimeout: AgentMemoryLifecycleTimeoutError;
558
- constructor(operation: string, priorTimeout: AgentMemoryLifecycleTimeoutError);
559
- }
560
- declare function resolveMemoryCleanupTimeoutMs(value: number | undefined, label: string): number;
561
- declare function runBoundedMemoryLifecycle<T>(input: {
562
- operation: string;
563
- timeoutMs: number;
564
- /** Prevent later operations from using the same client while timed-out work may still be running. */
565
- resource?: object;
566
- /** Cooperatively cancel provider work before reporting a timeout. */
567
- abortController?: AbortController;
568
- run(): Promise<T> | T;
569
- }): Promise<T>;
570
- declare function memoryRecoveryDelayMs(adapter: AgentMemoryAdapter): number;
571
- declare function sleepForMemoryRecovery(delayMs: number, assertOwned: () => Promise<void>, timeoutMs?: number, operation?: string): Promise<void>;
572
- declare function createMemoryExecutionPool(limit: number): {
573
- run<T>(operation: () => Promise<T>): Promise<T>;
574
- };
575
-
576
- type Mem0ClientMode = 'hosted' | 'oss';
577
- interface Mem0ClientLike {
578
- add(messages: Array<{
579
- role: string;
580
- content: string;
581
- }>, options?: Record<string, unknown>): Promise<unknown>;
582
- search(query: string, options?: Record<string, unknown>): Promise<unknown>;
583
- getAll?(options?: Record<string, unknown>): Promise<unknown>;
584
- delete?(memoryId: string, options?: Record<string, unknown>): Promise<unknown>;
585
- }
586
- interface Mem0MemoryAdapterOptions {
587
- client: Mem0ClientLike;
588
- mode: Mem0ClientMode;
589
- id?: string;
590
- appId?: string;
591
- infer?: boolean;
592
- rerank?: boolean;
593
- latestOnly?: boolean;
594
- /** Bounds delayed-delete visibility checks and abandoned hosted-write recovery waits. */
595
- ingestionTimeoutMs?: number;
596
- pollIntervalMs?: number;
597
- /** Stable deployment/account identity for cache-key helpers. Never put credentials here. */
598
- backendRef?: string;
599
- defaultScope?: AgentMemoryScope;
600
- }
601
- /** Connects both the hosted Mem0 client and the open-source `Memory` class. */
602
- declare function createMem0MemoryAdapter(options: Mem0MemoryAdapterOptions): AgentMemoryAdapter;
603
- /** Stable identity useful for dispatch/cache keys without exposing client credentials. */
604
- declare function mem0MemoryAdapterIdentity(options: Pick<Mem0MemoryAdapterOptions, 'mode' | 'id' | 'appId' | 'infer' | 'rerank' | 'latestOnly' | 'ingestionTimeoutMs' | 'pollIntervalMs' | 'defaultScope'> & {
605
- backendRef: string;
606
- }): string;
607
-
608
- interface Neo4jAgentMemoryAdapterOptions {
609
- client: object;
610
- /** Match the transport passed to the official MemoryClient. */
611
- transport: 'rest' | 'bridge';
612
- /** Use Neo4j's whole-conversation context instead of query-based search. */
613
- contextMode?: 'search' | 'native';
614
- id?: string;
615
- /** Assert that the client owns disposable external state for this exact branch. */
616
- branchId?: string;
617
- }
618
- declare function createNeo4jAgentMemoryAdapter(options: Neo4jAgentMemoryAdapterOptions): AgentMemoryAdapter;
619
-
620
- declare const AgentMemoryKindSchema: z.ZodEnum<{
621
- preference: "preference";
622
- message: "message";
623
- entity: "entity";
624
- fact: "fact";
625
- observation: "observation";
626
- "reasoning-trace": "reasoning-trace";
627
- }>;
628
- declare const AgentMemoryScopeSchema: z.ZodObject<{
629
- tenantId: z.ZodOptional<z.ZodString>;
630
- userId: z.ZodOptional<z.ZodString>;
631
- agentId: z.ZodOptional<z.ZodString>;
632
- teamId: z.ZodOptional<z.ZodString>;
633
- runId: z.ZodOptional<z.ZodString>;
634
- sessionId: z.ZodOptional<z.ZodString>;
635
- namespace: z.ZodOptional<z.ZodString>;
636
- tags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
637
- }, z.core.$strip>;
638
- declare const AgentMemoryHitSchema: z.ZodObject<{
639
- id: z.ZodString;
640
- uri: z.ZodString;
641
- kind: z.ZodEnum<{
642
- preference: "preference";
643
- message: "message";
644
- entity: "entity";
645
- fact: "fact";
646
- observation: "observation";
647
- "reasoning-trace": "reasoning-trace";
648
- }>;
649
- text: z.ZodString;
650
- title: z.ZodOptional<z.ZodString>;
651
- score: z.ZodOptional<z.ZodNumber>;
652
- normalizedScore: z.ZodOptional<z.ZodNumber>;
653
- confidence: z.ZodOptional<z.ZodNumber>;
654
- createdAt: z.ZodOptional<z.ZodString>;
655
- validUntil: z.ZodOptional<z.ZodString>;
656
- lastVerifiedAt: z.ZodOptional<z.ZodString>;
657
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
658
- }, z.core.$strip>;
659
- declare const AgentMemoryWriteInputSchema: z.ZodObject<{
660
- kind: z.ZodEnum<{
661
- preference: "preference";
662
- message: "message";
663
- entity: "entity";
664
- fact: "fact";
665
- observation: "observation";
666
- "reasoning-trace": "reasoning-trace";
667
- }>;
668
- text: z.ZodString;
669
- id: z.ZodOptional<z.ZodString>;
670
- title: z.ZodOptional<z.ZodString>;
671
- role: z.ZodOptional<z.ZodEnum<{
672
- system: "system";
673
- user: "user";
674
- assistant: "assistant";
675
- tool: "tool";
676
- }>>;
677
- entityName: z.ZodOptional<z.ZodString>;
678
- entityType: z.ZodOptional<z.ZodString>;
679
- category: z.ZodOptional<z.ZodString>;
680
- predicate: z.ZodOptional<z.ZodString>;
681
- subject: z.ZodOptional<z.ZodString>;
682
- object: z.ZodOptional<z.ZodString>;
683
- confidence: z.ZodOptional<z.ZodNumber>;
684
- scope: z.ZodOptional<z.ZodObject<{
685
- tenantId: z.ZodOptional<z.ZodString>;
686
- userId: z.ZodOptional<z.ZodString>;
687
- agentId: z.ZodOptional<z.ZodString>;
688
- teamId: z.ZodOptional<z.ZodString>;
689
- runId: z.ZodOptional<z.ZodString>;
690
- sessionId: z.ZodOptional<z.ZodString>;
691
- namespace: z.ZodOptional<z.ZodString>;
692
- tags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
693
- }, z.core.$strip>>;
694
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
695
- }, z.core.$strip>;
696
-
697
- declare function memoryHitToSourceRecord(hit: AgentMemoryHit, options?: {
698
- now?: () => Date;
699
- scope?: AgentMemoryScope;
700
- }): SourceRecord;
701
- declare function memoryWriteResultToSourceRecord(result: AgentMemoryWriteResult, text: string, options?: {
702
- now?: () => Date;
703
- scope?: AgentMemoryScope;
704
- }): SourceRecord;
705
-
706
- export { AgentMemoryAcquireRunLease, type AgentMemoryActivation, type AgentMemoryActivationDriver, AgentMemoryAdapter, type AgentMemoryAttemptEvent, type AgentMemoryBranch, type AgentMemoryBranchLifetime, type AgentMemoryBranchSnapshot, AgentMemoryContext, AgentMemoryControllerMode, type AgentMemoryDimensionComparison, type AgentMemoryExperimentCandidate, type AgentMemoryExperimentRankingRow, type AgentMemoryExperimentRunLease, type AgentMemoryGovernor, AgentMemoryHit, AgentMemoryHitSchema, type AgentMemoryImprovementRunLease, type AgentMemoryImprovementSeed, type AgentMemoryJournalEntry, AgentMemoryKindSchema, AgentMemoryLifecycleTimeoutError, AgentMemoryLifecycleUnsafeError, type AgentMemoryPromotionDecision, AgentMemoryRunLease, AgentMemoryScope, AgentMemoryScopeSchema, AgentMemorySearchOptions, type AgentMemorySequence, type AgentMemorySequenceArtifact, type AgentMemorySequenceProbe, type AgentMemorySequenceProbeResult, type AgentMemorySequenceScenario, type AgentMemorySequenceStep, type AgentMemorySharingPolicy, type AgentMemoryVisibility, AgentMemoryWriteInput, AgentMemoryWriteInputSchema, AgentMemoryWriteResult, type BuildAgentMemorySequencesFromBenchmarkCasesOptions, type CreateAgentMemoryBranchOptions, DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, type ForkAgentMemoryBranchSnapshotOptions, type GraphitiMcpClientLike, type GraphitiMemoryAdapterOptions, type GraphitiToolNames, type Mem0ClientLike, type Mem0ClientMode, type Mem0MemoryAdapterOptions, type Neo4jAgentMemoryAdapterOptions, RetrievalHoldoutBypassReason, RetrievalHoldoutCallContext, RetrievalHoldoutConfig, RetrievalHoldoutEvent, type RetrievalHoldoutOffPolicyOptions, type RetrievalHoldoutOffPolicyResult, RetrievalHoldoutResult, type RetrievalHoldoutSessionSummary, type RunAgentMemoryExperimentOptions, type RunAgentMemoryExperimentResult, type RunAgentMemoryImprovementOptions, type RunAgentMemoryImprovementResult, agentMemorySequenceJudge, applyRetrievalHoldout, applySessionStickyRetrievalHoldout, buildAgentMemorySequenceScenarios, buildAgentMemorySequencesFromBenchmarkCases, createAgentMemoryBranch, createGraphitiMemoryAdapter, createMem0MemoryAdapter, createMemoryExecutionPool, createNeo4jAgentMemoryAdapter, defaultGetMemoryContext, deterministicRng, emitRetrievalHoldoutBypass, forkAgentMemoryBranchSnapshot, graphitiMemoryAdapterIdentity, mem0MemoryAdapterIdentity, memoryHitToSourceRecord, memoryRecoveryDelayMs, memoryWriteResultToSourceRecord, renderMemoryContext, resetRetrievalHoldoutRegistry, resolveMemoryCleanupTimeoutMs, retrievalHoldoutConfigHash, runAgentMemoryExperiment, runAgentMemoryImprovement, runBoundedMemoryLifecycle, sleepForMemoryRecovery, toOffPolicyTrajectory };
1
+ export { A as AgentMemoryActivation, b as AgentMemoryActivationDriver, c as AgentMemoryAttemptEvent, d as AgentMemoryBranch, e as AgentMemoryBranchLifetime, f as AgentMemoryBranchSnapshot, g as AgentMemoryDimensionComparison, h as AgentMemoryExecutionContext, i as AgentMemoryExecutionCostMeter, j as AgentMemoryExecutionCostReceipt, k as AgentMemoryExecutionPaidCallInput, l as AgentMemoryExecutionPaidCallResult, m as AgentMemoryExecutionStep, n as AgentMemoryExperimentCandidate, o as AgentMemoryExperimentRankingRow, p as AgentMemoryExperimentRunLease, q as AgentMemoryFinalEvaluation, r as AgentMemoryFinalPair, s as AgentMemoryHitSchema, t as AgentMemoryImprovementRunLease, u as AgentMemoryJournalEntry, v as AgentMemoryKindSchema, w as AgentMemoryLifecycleTimeoutError, x as AgentMemoryLifecycleUnsafeError, y as AgentMemoryPromotionDecision, z as AgentMemoryScopeSchema, B as AgentMemorySequence, C as AgentMemorySequenceArtifact, D as AgentMemorySequenceProbe, E as AgentMemorySequenceProbeResult, F as AgentMemorySequenceScenario, G as AgentMemorySequenceStep, H as AgentMemorySharingPolicy, I as AgentMemoryVisibility, J as AgentMemoryWriteInputSchema, K as BuildAgentMemorySequencesFromBenchmarkCasesOptions, L as CreateAgentMemoryBranchOptions, M as DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, N as ForkAgentMemoryBranchSnapshotOptions, O as GraphitiMcpClientLike, P as GraphitiMemoryAdapterOptions, Q as GraphitiToolNames, S as Mem0ClientLike, T as Mem0ClientMode, U as Mem0MemoryAdapterOptions, V as MemoryConfigScenario, W as Neo4jAgentMemoryAdapterOptions, X as RetrievalHoldoutOffPolicyOptions, Y as RetrievalHoldoutOffPolicyResult, Z as RetrievalHoldoutSessionSummary, _ as RunAgentMemoryExperimentOptions, $ as RunAgentMemoryExperimentResult, a0 as RunAgentMemoryImprovementOptions, a1 as RunAgentMemoryImprovementResult, a4 as agentMemorySequenceJudge, a5 as applyRetrievalHoldout, a6 as applySessionStickyRetrievalHoldout, a7 as buildAgentMemorySequenceScenarios, a8 as buildAgentMemorySequencesFromBenchmarkCases, a9 as createAgentMemoryBranch, aa as createGraphitiMemoryAdapter, ab as createMem0MemoryAdapter, ac as createMemoryExecutionPool, ad as createNeo4jAgentMemoryAdapter, ae as defaultGetMemoryContext, af as deterministicRng, ag as emitRetrievalHoldoutBypass, ah as forkAgentMemoryBranchSnapshot, ai as graphitiMemoryAdapterIdentity, al as mem0MemoryAdapterIdentity, am as memoryHitToSourceRecord, an as memoryRecoveryDelayMs, ao as memoryWriteResultToSourceRecord, ap as renderMemoryContext, aq as resetRetrievalHoldoutRegistry, ar as resolveMemoryCleanupTimeoutMs, as as retrievalHoldoutConfigHash, at as runAgentMemoryExperiment, au as runAgentMemoryImprovement, av as runBoundedMemoryLifecycle, ay as sleepForMemoryRecovery, az as toOffPolicyTrajectory } from '../index-Cf7txrYP.js';
2
+ export { A as AgentMemoryAcquireRunLease, f as AgentMemoryAdapter, g as AgentMemoryBranchIsolation, h as AgentMemoryContext, i as AgentMemoryControllerMode, j as AgentMemoryHit, k as AgentMemoryKind, l as AgentMemoryRunLease, m as AgentMemoryScope, n as AgentMemorySearchOptions, o as AgentMemoryWriteInput, p as AgentMemoryWriteResult, U as OwnedAgentMemoryRunLease, Z as RetrievalHoldoutBypassReason, _ as RetrievalHoldoutCallContext, $ as RetrievalHoldoutConfig, a0 as RetrievalHoldoutEligibleItem, a1 as RetrievalHoldoutEvent, a2 as RetrievalHoldoutResult, a3 as RetrievalHoldoutSessionState, ac as acquireAgentMemoryRunLease } from '../types-BY-xLVw-.js';
3
+ import '@tangle-network/agent-eval/campaign';
4
+ import '@tangle-network/agent-eval';
5
+ import '@tangle-network/agent-eval/rl';
6
+ import '@tangle-network/agent-interface';
7
+ import 'zod';
8
+ import '../types-6x0OpfW6.js';