@tangle-network/agent-knowledge 3.2.1 → 4.0.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/CHANGELOG.md +37 -0
- package/README.md +306 -40
- package/dist/benchmarks/index.d.ts +1 -2
- package/dist/benchmarks/index.js +1 -4
- package/dist/chunk-DW6APRTX.js +3292 -0
- package/dist/chunk-DW6APRTX.js.map +1 -0
- package/dist/chunk-UWOTQNBI.js +4740 -0
- package/dist/chunk-UWOTQNBI.js.map +1 -0
- package/dist/index-Bqg1mBPt.d.ts +822 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.js +44 -8
- package/dist/index.js.map +1 -1
- package/dist/memory/index.d.ts +491 -4
- package/dist/memory/index.js +44 -3
- package/package.json +7 -5
- package/dist/chunk-RIHIYCX2.js +0 -1853
- package/dist/chunk-RIHIYCX2.js.map +0 -1
- package/dist/chunk-VN2OGUUP.js +0 -851
- package/dist/chunk-VN2OGUUP.js.map +0 -1
- package/dist/chunk-XVU5FFQA.js +0 -49
- package/dist/chunk-XVU5FFQA.js.map +0 -1
- package/dist/index-BHQk7jOT.d.ts +0 -429
- package/dist/types-BFRyr390.d.ts +0 -319
package/dist/memory/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { b as AgentMemoryAdapter, j as AgentMemorySearchOptions, d as AgentMemoryContext, f as AgentMemoryHit, i as AgentMemoryScope, k as AgentMemoryWriteInput, l as AgentMemoryWriteResult, v as KnowledgeBenchmarkFamily, E as KnowledgeBenchmarkSplit, J as KnowledgeMemoryBenchmarkTaskKind, M as KnowledgeMemoryFactMatcher, h as AgentMemoryRunLease, L as KnowledgeMemoryEvent, H as KnowledgeMemoryBenchmarkCase, e as AgentMemoryControllerMode, A as AgentMemoryAcquireRunLease } from '../index-Bqg1mBPt.js';
|
|
2
|
+
export { c as AgentMemoryBranchIsolation, g as AgentMemoryKind, T as OwnedAgentMemoryRunLease, $ as RetrievalHoldoutBypassReason, a0 as RetrievalHoldoutCallContext, a1 as RetrievalHoldoutConfig, a2 as RetrievalHoldoutEligibleItem, a3 as RetrievalHoldoutEvent, a4 as RetrievalHoldoutOffPolicyOptions, a5 as RetrievalHoldoutOffPolicyResult, a6 as RetrievalHoldoutResult, a7 as RetrievalHoldoutSessionState, a8 as RetrievalHoldoutSessionSummary, ak as acquireAgentMemoryRunLease, al as applyRetrievalHoldout, am as applySessionStickyRetrievalHoldout, aw as deterministicRng, ax as emitRetrievalHoldoutBypass, aD as resetRetrievalHoldoutRegistry, aI as retrievalHoldoutConfigHash, aS as toOffPolicyTrajectory } from '../index-Bqg1mBPt.js';
|
|
3
|
+
import { CampaignResult, Scenario, DispatchContext, CampaignStorage, CostLedgerHandle, JudgeConfig, HeldoutSignificance, Lineage, GovernorContext, GovernorOp, SurfaceProposer, LineageStore, HeldoutSignificanceOptions } from '@tangle-network/agent-eval/campaign';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
import { S as SourceRecord } from '../types-6x0OpfW6.js';
|
|
5
6
|
import '@tangle-network/agent-eval/rl';
|
|
@@ -7,9 +8,489 @@ import '@tangle-network/agent-eval/rl';
|
|
|
7
8
|
declare function defaultGetMemoryContext(adapter: Pick<AgentMemoryAdapter, 'search'>, query: string, options?: AgentMemorySearchOptions): Promise<AgentMemoryContext>;
|
|
8
9
|
declare function renderMemoryContext(hits: AgentMemoryHit[]): string;
|
|
9
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
|
+
/** Converts existing ordered memory benchmark cases into executable histories. */
|
|
261
|
+
declare function buildAgentMemorySequencesFromBenchmarkCases(cases: readonly KnowledgeMemoryBenchmarkCase[], options?: BuildAgentMemorySequencesFromBenchmarkCasesOptions): AgentMemorySequence[];
|
|
262
|
+
/** Runs ordered, branch-isolated memory histories across candidate systems. */
|
|
263
|
+
declare function runAgentMemoryExperiment(options: RunAgentMemoryExperimentOptions): Promise<RunAgentMemoryExperimentResult>;
|
|
264
|
+
declare function buildAgentMemorySequenceScenarios(sequences: readonly AgentMemorySequence[], candidates: readonly Pick<AgentMemoryExperimentCandidate, 'id'>[]): AgentMemorySequenceScenario[];
|
|
265
|
+
declare function agentMemorySequenceJudge(): JudgeConfig<AgentMemorySequenceArtifact, AgentMemorySequenceScenario>;
|
|
266
|
+
|
|
267
|
+
interface GraphitiMcpClientLike {
|
|
268
|
+
callTool(request: {
|
|
269
|
+
name: string;
|
|
270
|
+
arguments?: Record<string, unknown>;
|
|
271
|
+
}): Promise<unknown>;
|
|
272
|
+
}
|
|
273
|
+
interface GraphitiMemoryAdapterOptions {
|
|
274
|
+
client: GraphitiMcpClientLike;
|
|
275
|
+
id?: string;
|
|
276
|
+
/** Stable server/deployment identity for cache-key helpers. Never put credentials here. */
|
|
277
|
+
backendRef?: string;
|
|
278
|
+
defaultScope?: AgentMemoryScope;
|
|
279
|
+
consistency?: 'queued' | 'visible';
|
|
280
|
+
ingestionTimeoutMs?: number;
|
|
281
|
+
pollIntervalMs?: number;
|
|
282
|
+
/** Maximum episodes inspected to prove a queued write became visible. */
|
|
283
|
+
episodeScanLimit?: number;
|
|
284
|
+
provenanceEpisodeLimit?: number;
|
|
285
|
+
search?: readonly ('facts' | 'nodes')[];
|
|
286
|
+
toolNames?: Partial<GraphitiToolNames>;
|
|
287
|
+
}
|
|
288
|
+
interface GraphitiToolNames {
|
|
289
|
+
addMemory: string;
|
|
290
|
+
searchFacts: string;
|
|
291
|
+
searchNodes: string;
|
|
292
|
+
getEpisodes: string;
|
|
293
|
+
clearGraph: string;
|
|
294
|
+
}
|
|
295
|
+
/** Connects the official Graphiti MCP server without coupling to its Python internals. */
|
|
296
|
+
declare function createGraphitiMemoryAdapter(options: GraphitiMemoryAdapterOptions): AgentMemoryAdapter;
|
|
297
|
+
declare function graphitiMemoryAdapterIdentity(options: Pick<GraphitiMemoryAdapterOptions, 'id' | 'consistency' | 'ingestionTimeoutMs' | 'pollIntervalMs' | 'episodeScanLimit' | 'provenanceEpisodeLimit' | 'search' | 'toolNames' | 'defaultScope'> & {
|
|
298
|
+
backendRef: string;
|
|
299
|
+
}): string;
|
|
300
|
+
|
|
301
|
+
interface AgentMemoryImprovementSeed<TConfig> {
|
|
302
|
+
config: TConfig;
|
|
303
|
+
track: string;
|
|
304
|
+
vision?: string;
|
|
305
|
+
proposer: string;
|
|
306
|
+
}
|
|
307
|
+
interface AgentMemoryDimensionComparison {
|
|
308
|
+
dimension: string;
|
|
309
|
+
n: number;
|
|
310
|
+
expectedN: number;
|
|
311
|
+
measured: boolean;
|
|
312
|
+
meanDelta: number;
|
|
313
|
+
low: number;
|
|
314
|
+
high: number;
|
|
315
|
+
tolerance: number;
|
|
316
|
+
regressed: boolean;
|
|
317
|
+
}
|
|
318
|
+
interface AgentMemoryPromotionDecision {
|
|
319
|
+
status: 'promote' | 'hold' | 'no-change';
|
|
320
|
+
reasons: readonly string[];
|
|
321
|
+
baselineScore: number;
|
|
322
|
+
winnerScore: number;
|
|
323
|
+
lift: number;
|
|
324
|
+
significance?: HeldoutSignificance;
|
|
325
|
+
criticalDimensions: readonly AgentMemoryDimensionComparison[];
|
|
326
|
+
}
|
|
327
|
+
interface AgentMemoryActivation {
|
|
328
|
+
id: string;
|
|
329
|
+
status: 'not-eligible' | 'not-configured' | 'pending' | 'activated' | 'recovered' | 'already-activated';
|
|
330
|
+
journalPath: string;
|
|
331
|
+
}
|
|
332
|
+
interface AgentMemoryActivationDriver<TConfig> {
|
|
333
|
+
/** Change whenever activation behavior or the external target changes. */
|
|
334
|
+
ref: string;
|
|
335
|
+
/** Return the exact currently active configuration. */
|
|
336
|
+
readCurrent(): Promise<TConfig>;
|
|
337
|
+
/** Atomically replace expectedConfig with config, or fail on a concurrent change. */
|
|
338
|
+
compareAndSet(input: {
|
|
339
|
+
activationId: string;
|
|
340
|
+
expectedConfig: TConfig;
|
|
341
|
+
expectedSurfaceHash: string;
|
|
342
|
+
config: TConfig;
|
|
343
|
+
surfaceHash: string;
|
|
344
|
+
decision: AgentMemoryPromotionDecision;
|
|
345
|
+
lineage: Lineage;
|
|
346
|
+
holdout: RunAgentMemoryExperimentResult;
|
|
347
|
+
}): Promise<void>;
|
|
348
|
+
}
|
|
349
|
+
type AgentMemoryImprovementRunLease = AgentMemoryRunLease;
|
|
350
|
+
interface AgentMemoryGovernor {
|
|
351
|
+
decide(context: GovernorContext & {
|
|
352
|
+
costLedger: CostLedgerHandle;
|
|
353
|
+
costPhase: string;
|
|
354
|
+
}): GovernorOp | Promise<GovernorOp>;
|
|
355
|
+
}
|
|
356
|
+
interface RunAgentMemoryImprovementOptions<TConfig> {
|
|
357
|
+
experimentId: string;
|
|
358
|
+
trainSequences: readonly AgentMemorySequence[];
|
|
359
|
+
holdoutSequences: readonly AgentMemorySequence[];
|
|
360
|
+
/** First entry is the current baseline; remaining entries seed independent search tracks. */
|
|
361
|
+
seeds: readonly AgentMemoryImprovementSeed<TConfig>[];
|
|
362
|
+
createCandidate(input: {
|
|
363
|
+
config: TConfig;
|
|
364
|
+
candidateId: string;
|
|
365
|
+
surfaceHash: string;
|
|
366
|
+
}): Omit<AgentMemoryExperimentCandidate, 'id'> | Promise<Omit<AgentMemoryExperimentCandidate, 'id'>>;
|
|
367
|
+
proposer: SurfaceProposer;
|
|
368
|
+
/** Optional proposer implementations keyed by seed and branch proposer labels. */
|
|
369
|
+
proposers?: Readonly<Record<string, SurfaceProposer>>;
|
|
370
|
+
/** Stable version or commit for the candidate factory, proposer, and governor. */
|
|
371
|
+
improvementRef: string;
|
|
372
|
+
governor?: AgentMemoryGovernor;
|
|
373
|
+
budget: {
|
|
374
|
+
maxSteps: number;
|
|
375
|
+
};
|
|
376
|
+
populationSize?: number;
|
|
377
|
+
candidateConcurrency?: number;
|
|
378
|
+
sequenceConcurrency?: number;
|
|
379
|
+
runDir: string;
|
|
380
|
+
repo?: string;
|
|
381
|
+
storage?: CampaignStorage;
|
|
382
|
+
lineageStore?: LineageStore;
|
|
383
|
+
/** Required with custom storage when all controllers are confined to one process. */
|
|
384
|
+
controllerMode?: AgentMemoryControllerMode;
|
|
385
|
+
/** Required for distributed controllers using custom storage. Worker concurrency is independent. */
|
|
386
|
+
acquireRunLease?: AgentMemoryAcquireRunLease;
|
|
387
|
+
seed?: number;
|
|
388
|
+
reps?: number;
|
|
389
|
+
resumable?: boolean;
|
|
390
|
+
dispatchTimeoutMs?: number;
|
|
391
|
+
cleanupTimeoutMs?: number;
|
|
392
|
+
maxRecoveryAttempts?: number;
|
|
393
|
+
maxRecoveryRetriesPerAttempt?: number;
|
|
394
|
+
maxTotalCostUsd?: number;
|
|
395
|
+
executeStep?: RunAgentMemoryExperimentOptions['executeStep'];
|
|
396
|
+
executeStepRef?: string;
|
|
397
|
+
onBranchSnapshot?: RunAgentMemoryExperimentOptions['onBranchSnapshot'];
|
|
398
|
+
cleanupBranches?: boolean;
|
|
399
|
+
serializeConfig?: (config: TConfig) => string;
|
|
400
|
+
parseConfig?: (surface: string) => TConfig;
|
|
401
|
+
significance?: HeldoutSignificanceOptions;
|
|
402
|
+
criticalDimensions?: readonly string[];
|
|
403
|
+
criticalDimensionTolerance?: number;
|
|
404
|
+
minHoldoutScore?: number;
|
|
405
|
+
activation?: AgentMemoryActivationDriver<TConfig>;
|
|
406
|
+
activationTimeoutMs?: number;
|
|
407
|
+
now?: () => Date;
|
|
408
|
+
}
|
|
409
|
+
interface RunAgentMemoryImprovementResult<TConfig> {
|
|
410
|
+
lineage: Lineage;
|
|
411
|
+
baselineConfig: TConfig;
|
|
412
|
+
winnerConfig: TConfig;
|
|
413
|
+
baselineSurface: string;
|
|
414
|
+
winnerSurface: string;
|
|
415
|
+
baselineSurfaceHash: string;
|
|
416
|
+
winnerSurfaceHash: string;
|
|
417
|
+
decision: AgentMemoryPromotionDecision;
|
|
418
|
+
activation: AgentMemoryActivation;
|
|
419
|
+
holdout?: RunAgentMemoryExperimentResult;
|
|
420
|
+
totalCostUsd: number;
|
|
421
|
+
resultJsonPath: string;
|
|
422
|
+
}
|
|
423
|
+
/** Searches branchable memory configurations and activates only a fresh holdout win. */
|
|
424
|
+
declare function runAgentMemoryImprovement<TConfig>(options: RunAgentMemoryImprovementOptions<TConfig>): Promise<RunAgentMemoryImprovementResult<TConfig>>;
|
|
425
|
+
|
|
426
|
+
declare const DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS = 180000;
|
|
427
|
+
declare class AgentMemoryLifecycleTimeoutError extends Error {
|
|
428
|
+
readonly operation: string;
|
|
429
|
+
readonly timeoutMs: number;
|
|
430
|
+
constructor(operation: string, timeoutMs: number);
|
|
431
|
+
}
|
|
432
|
+
declare class AgentMemoryLifecycleUnsafeError extends Error {
|
|
433
|
+
readonly operation: string;
|
|
434
|
+
readonly priorTimeout: AgentMemoryLifecycleTimeoutError;
|
|
435
|
+
constructor(operation: string, priorTimeout: AgentMemoryLifecycleTimeoutError);
|
|
436
|
+
}
|
|
437
|
+
declare function resolveMemoryCleanupTimeoutMs(value: number | undefined, label: string): number;
|
|
438
|
+
declare function runBoundedMemoryLifecycle<T>(input: {
|
|
439
|
+
operation: string;
|
|
440
|
+
timeoutMs: number;
|
|
441
|
+
/** Prevent later operations from using the same client while timed-out work may still be running. */
|
|
442
|
+
resource?: object;
|
|
443
|
+
/** Cooperatively cancel provider work before reporting a timeout. */
|
|
444
|
+
abortController?: AbortController;
|
|
445
|
+
run(): Promise<T> | T;
|
|
446
|
+
}): Promise<T>;
|
|
447
|
+
declare function memoryRecoveryDelayMs(adapter: AgentMemoryAdapter): number;
|
|
448
|
+
declare function sleepForMemoryRecovery(delayMs: number, assertOwned: () => Promise<void>, timeoutMs?: number, operation?: string): Promise<void>;
|
|
449
|
+
declare function createMemoryExecutionPool(limit: number): {
|
|
450
|
+
run<T>(operation: () => Promise<T>): Promise<T>;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
type Mem0ClientMode = 'hosted' | 'oss';
|
|
454
|
+
interface Mem0ClientLike {
|
|
455
|
+
add(messages: Array<{
|
|
456
|
+
role: string;
|
|
457
|
+
content: string;
|
|
458
|
+
}>, options?: Record<string, unknown>): Promise<unknown>;
|
|
459
|
+
search(query: string, options?: Record<string, unknown>): Promise<unknown>;
|
|
460
|
+
getAll?(options?: Record<string, unknown>): Promise<unknown>;
|
|
461
|
+
delete?(memoryId: string, options?: Record<string, unknown>): Promise<unknown>;
|
|
462
|
+
}
|
|
463
|
+
interface Mem0MemoryAdapterOptions {
|
|
464
|
+
client: Mem0ClientLike;
|
|
465
|
+
mode: Mem0ClientMode;
|
|
466
|
+
id?: string;
|
|
467
|
+
appId?: string;
|
|
468
|
+
infer?: boolean;
|
|
469
|
+
rerank?: boolean;
|
|
470
|
+
latestOnly?: boolean;
|
|
471
|
+
/** Bounds delayed-delete visibility checks and abandoned hosted-write recovery waits. */
|
|
472
|
+
ingestionTimeoutMs?: number;
|
|
473
|
+
pollIntervalMs?: number;
|
|
474
|
+
/** Stable deployment/account identity for cache-key helpers. Never put credentials here. */
|
|
475
|
+
backendRef?: string;
|
|
476
|
+
defaultScope?: AgentMemoryScope;
|
|
477
|
+
}
|
|
478
|
+
/** Connects both the hosted Mem0 client and the open-source `Memory` class. */
|
|
479
|
+
declare function createMem0MemoryAdapter(options: Mem0MemoryAdapterOptions): AgentMemoryAdapter;
|
|
480
|
+
/** Stable identity useful for dispatch/cache keys without exposing client credentials. */
|
|
481
|
+
declare function mem0MemoryAdapterIdentity(options: Pick<Mem0MemoryAdapterOptions, 'mode' | 'id' | 'appId' | 'infer' | 'rerank' | 'latestOnly' | 'ingestionTimeoutMs' | 'pollIntervalMs' | 'defaultScope'> & {
|
|
482
|
+
backendRef: string;
|
|
483
|
+
}): string;
|
|
484
|
+
|
|
10
485
|
interface Neo4jAgentMemoryAdapterOptions {
|
|
11
|
-
client:
|
|
486
|
+
client: object;
|
|
487
|
+
/** Match the transport passed to the official MemoryClient. */
|
|
488
|
+
transport: 'rest' | 'bridge';
|
|
489
|
+
/** Use Neo4j's whole-conversation context instead of query-based search. */
|
|
490
|
+
contextMode?: 'search' | 'native';
|
|
12
491
|
id?: string;
|
|
492
|
+
/** Assert that the client owns disposable external state for this exact branch. */
|
|
493
|
+
branchId?: string;
|
|
13
494
|
}
|
|
14
495
|
declare function createNeo4jAgentMemoryAdapter(options: Neo4jAgentMemoryAdapterOptions): AgentMemoryAdapter;
|
|
15
496
|
|
|
@@ -24,6 +505,9 @@ declare const AgentMemoryKindSchema: z.ZodEnum<{
|
|
|
24
505
|
declare const AgentMemoryScopeSchema: z.ZodObject<{
|
|
25
506
|
tenantId: z.ZodOptional<z.ZodString>;
|
|
26
507
|
userId: z.ZodOptional<z.ZodString>;
|
|
508
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
509
|
+
teamId: z.ZodOptional<z.ZodString>;
|
|
510
|
+
runId: z.ZodOptional<z.ZodString>;
|
|
27
511
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
28
512
|
namespace: z.ZodOptional<z.ZodString>;
|
|
29
513
|
tags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
@@ -77,6 +561,9 @@ declare const AgentMemoryWriteInputSchema: z.ZodObject<{
|
|
|
77
561
|
scope: z.ZodOptional<z.ZodObject<{
|
|
78
562
|
tenantId: z.ZodOptional<z.ZodString>;
|
|
79
563
|
userId: z.ZodOptional<z.ZodString>;
|
|
564
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
565
|
+
teamId: z.ZodOptional<z.ZodString>;
|
|
566
|
+
runId: z.ZodOptional<z.ZodString>;
|
|
80
567
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
81
568
|
namespace: z.ZodOptional<z.ZodString>;
|
|
82
569
|
tags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
@@ -93,4 +580,4 @@ declare function memoryWriteResultToSourceRecord(result: AgentMemoryWriteResult,
|
|
|
93
580
|
scope?: AgentMemoryScope;
|
|
94
581
|
}): SourceRecord;
|
|
95
582
|
|
|
96
|
-
export { AgentMemoryAdapter, AgentMemoryContext, AgentMemoryHit, AgentMemoryHitSchema, AgentMemoryKindSchema, AgentMemoryScope, AgentMemoryScopeSchema, AgentMemorySearchOptions, AgentMemoryWriteInputSchema, AgentMemoryWriteResult, type Neo4jAgentMemoryAdapterOptions, createNeo4jAgentMemoryAdapter, defaultGetMemoryContext, memoryHitToSourceRecord, memoryWriteResultToSourceRecord, renderMemoryContext };
|
|
583
|
+
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, type RunAgentMemoryExperimentOptions, type RunAgentMemoryExperimentResult, type RunAgentMemoryImprovementOptions, type RunAgentMemoryImprovementResult, agentMemorySequenceJudge, buildAgentMemorySequenceScenarios, buildAgentMemorySequencesFromBenchmarkCases, createAgentMemoryBranch, createGraphitiMemoryAdapter, createMem0MemoryAdapter, createMemoryExecutionPool, createNeo4jAgentMemoryAdapter, defaultGetMemoryContext, forkAgentMemoryBranchSnapshot, graphitiMemoryAdapterIdentity, mem0MemoryAdapterIdentity, memoryHitToSourceRecord, memoryRecoveryDelayMs, memoryWriteResultToSourceRecord, renderMemoryContext, resolveMemoryCleanupTimeoutMs, runAgentMemoryExperiment, runAgentMemoryImprovement, runBoundedMemoryLifecycle, sleepForMemoryRecovery };
|
package/dist/memory/index.js
CHANGED
|
@@ -3,38 +3,79 @@ import {
|
|
|
3
3
|
AgentMemoryKindSchema,
|
|
4
4
|
AgentMemoryScopeSchema,
|
|
5
5
|
AgentMemoryWriteInputSchema,
|
|
6
|
+
agentMemorySequenceJudge,
|
|
6
7
|
applyRetrievalHoldout,
|
|
7
8
|
applySessionStickyRetrievalHoldout,
|
|
9
|
+
buildAgentMemorySequenceScenarios,
|
|
10
|
+
buildAgentMemorySequencesFromBenchmarkCases,
|
|
11
|
+
createAgentMemoryBranch,
|
|
12
|
+
createGraphitiMemoryAdapter,
|
|
13
|
+
createMem0MemoryAdapter,
|
|
8
14
|
createNeo4jAgentMemoryAdapter,
|
|
9
15
|
defaultGetMemoryContext,
|
|
10
16
|
deterministicRng,
|
|
11
17
|
emitRetrievalHoldoutBypass,
|
|
18
|
+
forkAgentMemoryBranchSnapshot,
|
|
19
|
+
graphitiMemoryAdapterIdentity,
|
|
20
|
+
mem0MemoryAdapterIdentity,
|
|
12
21
|
renderMemoryContext,
|
|
13
22
|
resetRetrievalHoldoutRegistry,
|
|
14
23
|
retrievalHoldoutConfigHash,
|
|
24
|
+
runAgentMemoryExperiment,
|
|
25
|
+
runAgentMemoryImprovement,
|
|
15
26
|
toOffPolicyTrajectory
|
|
16
|
-
} from "../chunk-
|
|
27
|
+
} from "../chunk-UWOTQNBI.js";
|
|
17
28
|
import {
|
|
29
|
+
AgentMemoryLifecycleTimeoutError,
|
|
30
|
+
AgentMemoryLifecycleUnsafeError,
|
|
31
|
+
DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS,
|
|
32
|
+
acquireAgentMemoryRunLease,
|
|
33
|
+
createMemoryExecutionPool,
|
|
18
34
|
memoryHitToSourceRecord,
|
|
19
|
-
|
|
20
|
-
|
|
35
|
+
memoryRecoveryDelayMs,
|
|
36
|
+
memoryWriteResultToSourceRecord,
|
|
37
|
+
resolveMemoryCleanupTimeoutMs,
|
|
38
|
+
runBoundedMemoryLifecycle,
|
|
39
|
+
sleepForMemoryRecovery
|
|
40
|
+
} from "../chunk-DW6APRTX.js";
|
|
41
|
+
import "../chunk-DQ3PDMDP.js";
|
|
21
42
|
import "../chunk-YMKHCTS2.js";
|
|
22
43
|
export {
|
|
23
44
|
AgentMemoryHitSchema,
|
|
24
45
|
AgentMemoryKindSchema,
|
|
46
|
+
AgentMemoryLifecycleTimeoutError,
|
|
47
|
+
AgentMemoryLifecycleUnsafeError,
|
|
25
48
|
AgentMemoryScopeSchema,
|
|
26
49
|
AgentMemoryWriteInputSchema,
|
|
50
|
+
DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS,
|
|
51
|
+
acquireAgentMemoryRunLease,
|
|
52
|
+
agentMemorySequenceJudge,
|
|
27
53
|
applyRetrievalHoldout,
|
|
28
54
|
applySessionStickyRetrievalHoldout,
|
|
55
|
+
buildAgentMemorySequenceScenarios,
|
|
56
|
+
buildAgentMemorySequencesFromBenchmarkCases,
|
|
57
|
+
createAgentMemoryBranch,
|
|
58
|
+
createGraphitiMemoryAdapter,
|
|
59
|
+
createMem0MemoryAdapter,
|
|
60
|
+
createMemoryExecutionPool,
|
|
29
61
|
createNeo4jAgentMemoryAdapter,
|
|
30
62
|
defaultGetMemoryContext,
|
|
31
63
|
deterministicRng,
|
|
32
64
|
emitRetrievalHoldoutBypass,
|
|
65
|
+
forkAgentMemoryBranchSnapshot,
|
|
66
|
+
graphitiMemoryAdapterIdentity,
|
|
67
|
+
mem0MemoryAdapterIdentity,
|
|
33
68
|
memoryHitToSourceRecord,
|
|
69
|
+
memoryRecoveryDelayMs,
|
|
34
70
|
memoryWriteResultToSourceRecord,
|
|
35
71
|
renderMemoryContext,
|
|
36
72
|
resetRetrievalHoldoutRegistry,
|
|
73
|
+
resolveMemoryCleanupTimeoutMs,
|
|
37
74
|
retrievalHoldoutConfigHash,
|
|
75
|
+
runAgentMemoryExperiment,
|
|
76
|
+
runAgentMemoryImprovement,
|
|
77
|
+
runBoundedMemoryLifecycle,
|
|
78
|
+
sleepForMemoryRecovery,
|
|
38
79
|
toOffPolicyTrajectory
|
|
39
80
|
};
|
|
40
81
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-knowledge",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Source-grounded, eval-gated knowledge growth primitives for agents.",
|
|
5
5
|
"homepage": "https://github.com/tangle-network/agent-knowledge#readme",
|
|
6
6
|
"repository": {
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"dist",
|
|
53
53
|
"docs",
|
|
54
54
|
"AGENTS.md",
|
|
55
|
+
"CHANGELOG.md",
|
|
55
56
|
"README.md"
|
|
56
57
|
],
|
|
57
58
|
"publishConfig": {
|
|
@@ -69,19 +70,20 @@
|
|
|
69
70
|
"verify:package": "node scripts/verify-package.mjs"
|
|
70
71
|
},
|
|
71
72
|
"dependencies": {
|
|
72
|
-
"@tangle-network/agent-eval": "^0.122.
|
|
73
|
+
"@tangle-network/agent-eval": "^0.122.8",
|
|
73
74
|
"@tangle-network/agent-interface": "^0.31.0",
|
|
74
75
|
"proper-lockfile": "4.1.2",
|
|
75
|
-
"zod": "^4.3
|
|
76
|
+
"zod": "^4.4.3"
|
|
76
77
|
},
|
|
77
78
|
"devDependencies": {
|
|
78
|
-
"@biomejs/biome": "^2.4
|
|
79
|
+
"@biomejs/biome": "^2.5.4",
|
|
79
80
|
"@neo4j-labs/agent-memory": "0.4.0",
|
|
80
81
|
"@tangle-network/sandbox": "^0.9.7",
|
|
81
82
|
"@types/node": "^25.6.0",
|
|
82
83
|
"@types/proper-lockfile": "4.1.4",
|
|
84
|
+
"mem0ai": "3.1.0",
|
|
83
85
|
"tsup": "^8.0.0",
|
|
84
|
-
"tsx": "^4.
|
|
86
|
+
"tsx": "^4.23.1",
|
|
85
87
|
"typescript": "^5.7.0",
|
|
86
88
|
"vitest": "^3.0.0"
|
|
87
89
|
},
|