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