@tangle-network/agent-knowledge 3.2.1 → 4.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.
- package/CHANGELOG.md +49 -0
- package/README.md +306 -40
- package/dist/benchmarks/index.d.ts +51 -4
- package/dist/benchmarks/index.js +1 -4
- package/dist/chunk-3CAAGJCE.js +4784 -0
- package/dist/chunk-3CAAGJCE.js.map +1 -0
- package/dist/chunk-BBCIB4UL.js +3321 -0
- package/dist/chunk-BBCIB4UL.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +44 -8
- package/dist/index.js.map +1 -1
- package/dist/memory/index.d.ts +618 -5
- package/dist/memory/index.js +44 -3
- package/dist/types-ZzY_x0r7.d.ts +661 -0
- 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
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
import { JsonValue, Scenario, DispatchContext, RunImprovementLoopResult, ParameterCandidate, JudgeConfig, Gate, RunImprovementLoopOptions, MutableSurface, SurfaceProposer, CampaignStorage, CostLedgerHandle, CampaignResult } from '@tangle-network/agent-eval/campaign';
|
|
2
|
+
import { c as KnowledgeIndex, S as SourceRecord } from './types-6x0OpfW6.js';
|
|
3
|
+
|
|
4
|
+
type RetrievalConfig = Record<string, JsonValue>;
|
|
5
|
+
type RetrievalParameterSearchSpace = Record<string, readonly JsonValue[]>;
|
|
6
|
+
type RetrievalGoldTarget = {
|
|
7
|
+
kind: 'page';
|
|
8
|
+
pageId: string;
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'page-path';
|
|
11
|
+
path: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'source';
|
|
14
|
+
sourceId: string;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'source-anchor';
|
|
17
|
+
sourceId: string;
|
|
18
|
+
anchorId: string;
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'source-span';
|
|
21
|
+
sourceId: string;
|
|
22
|
+
charStart: number;
|
|
23
|
+
charEnd: number;
|
|
24
|
+
};
|
|
25
|
+
interface RetrievalEvalScenario extends Scenario {
|
|
26
|
+
kind: 'retrieval-eval';
|
|
27
|
+
query: string;
|
|
28
|
+
expected: RetrievalGoldTarget | readonly RetrievalGoldTarget[];
|
|
29
|
+
k?: number;
|
|
30
|
+
}
|
|
31
|
+
interface RetrievedSourceSpan {
|
|
32
|
+
sourceId: string;
|
|
33
|
+
anchorId?: string;
|
|
34
|
+
charStart?: number;
|
|
35
|
+
charEnd?: number;
|
|
36
|
+
}
|
|
37
|
+
interface RetrievedKnowledgeHit {
|
|
38
|
+
pageId: string;
|
|
39
|
+
path: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
rank: number;
|
|
42
|
+
score?: number;
|
|
43
|
+
normalizedScore?: number;
|
|
44
|
+
sourceIds?: readonly string[];
|
|
45
|
+
sourceSpans?: readonly RetrievedSourceSpan[];
|
|
46
|
+
snippet?: string;
|
|
47
|
+
metadata?: Record<string, JsonValue>;
|
|
48
|
+
}
|
|
49
|
+
interface RetrievalEvalArtifact {
|
|
50
|
+
config: RetrievalConfig;
|
|
51
|
+
query: string;
|
|
52
|
+
requestedK: number;
|
|
53
|
+
hits: readonly RetrievedKnowledgeHit[];
|
|
54
|
+
durationMs: number;
|
|
55
|
+
/** Informational copy. Billable retrievers account through context.cost.runPaidCall. */
|
|
56
|
+
costUsd?: number;
|
|
57
|
+
metadata?: Record<string, JsonValue>;
|
|
58
|
+
}
|
|
59
|
+
interface RetrievalMetricSummary {
|
|
60
|
+
recall: number;
|
|
61
|
+
mrr: number;
|
|
62
|
+
ndcg: number;
|
|
63
|
+
precisionAtK: number;
|
|
64
|
+
expectedCount: number;
|
|
65
|
+
matchedCount: number;
|
|
66
|
+
relevantHitCount: number;
|
|
67
|
+
firstHitRank: number | null;
|
|
68
|
+
matchedTargetIds: readonly string[];
|
|
69
|
+
}
|
|
70
|
+
interface RetrievalEvalRetrieverInput {
|
|
71
|
+
index?: KnowledgeIndex;
|
|
72
|
+
config: RetrievalConfig;
|
|
73
|
+
scenario: RetrievalEvalScenario;
|
|
74
|
+
k: number;
|
|
75
|
+
signal: AbortSignal;
|
|
76
|
+
context: DispatchContext;
|
|
77
|
+
}
|
|
78
|
+
interface RetrievalEvalRetrieverResult {
|
|
79
|
+
hits: readonly RetrievedKnowledgeHit[];
|
|
80
|
+
/** Informational copy. Billable retrievers account through context.cost.runPaidCall. */
|
|
81
|
+
costUsd?: number;
|
|
82
|
+
metadata?: Record<string, JsonValue>;
|
|
83
|
+
}
|
|
84
|
+
type RetrievalEvalRetriever = (input: RetrievalEvalRetrieverInput) => Promise<readonly RetrievedKnowledgeHit[] | RetrievalEvalRetrieverResult>;
|
|
85
|
+
interface BuildRetrievalEvalDispatchOptions {
|
|
86
|
+
index?: KnowledgeIndex;
|
|
87
|
+
defaultK?: number;
|
|
88
|
+
retrieve?: RetrievalEvalRetriever;
|
|
89
|
+
}
|
|
90
|
+
interface RetrievalMetricWeights {
|
|
91
|
+
recall?: number;
|
|
92
|
+
mrr?: number;
|
|
93
|
+
ndcg?: number;
|
|
94
|
+
precisionAtK?: number;
|
|
95
|
+
}
|
|
96
|
+
interface RetrievalRecallJudgeOptions {
|
|
97
|
+
name?: string;
|
|
98
|
+
weights?: RetrievalMetricWeights;
|
|
99
|
+
}
|
|
100
|
+
interface BuildRetrievalParameterCandidatesOptions {
|
|
101
|
+
baseline?: RetrievalConfig;
|
|
102
|
+
}
|
|
103
|
+
interface RetrievalParameterSweepProposerOptions {
|
|
104
|
+
candidates?: readonly ParameterCandidate[];
|
|
105
|
+
searchSpace?: RetrievalParameterSearchSpace;
|
|
106
|
+
baseline?: RetrievalConfig;
|
|
107
|
+
}
|
|
108
|
+
type RetrievalLoopBaseOptions = RunImprovementLoopOptions<RetrievalEvalScenario, RetrievalEvalArtifact>;
|
|
109
|
+
interface RunRetrievalImprovementLoopOptions {
|
|
110
|
+
baseline: RetrievalConfig;
|
|
111
|
+
scenarios: readonly RetrievalEvalScenario[];
|
|
112
|
+
holdoutScenarios?: readonly RetrievalEvalScenario[];
|
|
113
|
+
index?: KnowledgeIndex;
|
|
114
|
+
defaultK?: number;
|
|
115
|
+
retrieve?: RetrievalEvalRetriever;
|
|
116
|
+
candidates?: readonly ParameterCandidate[];
|
|
117
|
+
searchSpace?: RetrievalParameterSearchSpace;
|
|
118
|
+
judges?: readonly JudgeConfig<RetrievalEvalArtifact, RetrievalEvalScenario>[];
|
|
119
|
+
gate?: Gate<RetrievalEvalArtifact, RetrievalEvalScenario>;
|
|
120
|
+
metricWeights?: RetrievalMetricWeights;
|
|
121
|
+
targetRecall?: number;
|
|
122
|
+
holdoutFraction?: number;
|
|
123
|
+
splitSeed?: number;
|
|
124
|
+
deltaThreshold?: number;
|
|
125
|
+
runDir?: RetrievalLoopBaseOptions['runDir'];
|
|
126
|
+
seed?: RetrievalLoopBaseOptions['seed'];
|
|
127
|
+
reps?: RetrievalLoopBaseOptions['reps'];
|
|
128
|
+
resumable?: RetrievalLoopBaseOptions['resumable'];
|
|
129
|
+
costCeiling?: RetrievalLoopBaseOptions['costCeiling'];
|
|
130
|
+
maxConcurrency?: RetrievalLoopBaseOptions['maxConcurrency'];
|
|
131
|
+
dispatchTimeoutMs?: RetrievalLoopBaseOptions['dispatchTimeoutMs'];
|
|
132
|
+
expectUsage?: RetrievalLoopBaseOptions['expectUsage'];
|
|
133
|
+
tracing?: RetrievalLoopBaseOptions['tracing'];
|
|
134
|
+
storage?: RetrievalLoopBaseOptions['storage'];
|
|
135
|
+
populationSize?: RetrievalLoopBaseOptions['populationSize'];
|
|
136
|
+
maxGenerations?: RetrievalLoopBaseOptions['maxGenerations'];
|
|
137
|
+
promoteTopK?: RetrievalLoopBaseOptions['promoteTopK'];
|
|
138
|
+
maxImprovementShots?: RetrievalLoopBaseOptions['maxImprovementShots'];
|
|
139
|
+
report?: RetrievalLoopBaseOptions['report'];
|
|
140
|
+
findings?: RetrievalLoopBaseOptions['findings'];
|
|
141
|
+
now?: RetrievalLoopBaseOptions['now'];
|
|
142
|
+
}
|
|
143
|
+
interface RunRetrievalImprovementLoopResult extends RunImprovementLoopResult<RetrievalEvalArtifact, RetrievalEvalScenario> {
|
|
144
|
+
baselineConfig: RetrievalConfig;
|
|
145
|
+
winnerConfig: RetrievalConfig;
|
|
146
|
+
trainScenarios: readonly RetrievalEvalScenario[];
|
|
147
|
+
holdoutScenarios: readonly RetrievalEvalScenario[];
|
|
148
|
+
candidates: readonly ParameterCandidate[];
|
|
149
|
+
targetRecall?: number;
|
|
150
|
+
}
|
|
151
|
+
declare function retrievalConfigSurface(config: RetrievalConfig): string;
|
|
152
|
+
declare function retrievalConfigFromSurface(surface: MutableSurface): RetrievalConfig;
|
|
153
|
+
declare function buildRetrievalEvalDispatch(options: BuildRetrievalEvalDispatchOptions): (surface: MutableSurface, scenario: RetrievalEvalScenario, context: DispatchContext) => Promise<RetrievalEvalArtifact>;
|
|
154
|
+
declare function retrievalRecallJudge(options?: RetrievalRecallJudgeOptions): JudgeConfig<RetrievalEvalArtifact, RetrievalEvalScenario>;
|
|
155
|
+
declare function scoreRetrievalArtifact(artifact: RetrievalEvalArtifact, scenario: RetrievalEvalScenario): RetrievalMetricSummary;
|
|
156
|
+
declare function buildRetrievalParameterCandidates(searchSpace: RetrievalParameterSearchSpace, options?: BuildRetrievalParameterCandidatesOptions): ParameterCandidate[];
|
|
157
|
+
declare function retrievalParameterSweepProposer(options: RetrievalParameterSweepProposerOptions): SurfaceProposer;
|
|
158
|
+
declare function runRetrievalImprovementLoop(options: RunRetrievalImprovementLoopOptions): Promise<RunRetrievalImprovementLoopResult>;
|
|
159
|
+
|
|
160
|
+
type AgentMemoryKind = 'message' | 'entity' | 'fact' | 'preference' | 'observation' | 'reasoning-trace';
|
|
161
|
+
interface AgentMemoryScope {
|
|
162
|
+
tenantId?: string;
|
|
163
|
+
userId?: string;
|
|
164
|
+
agentId?: string;
|
|
165
|
+
teamId?: string;
|
|
166
|
+
runId?: string;
|
|
167
|
+
sessionId?: string;
|
|
168
|
+
namespace?: string;
|
|
169
|
+
tags?: Record<string, string>;
|
|
170
|
+
}
|
|
171
|
+
interface AgentMemoryHit {
|
|
172
|
+
id: string;
|
|
173
|
+
uri: string;
|
|
174
|
+
kind: AgentMemoryKind;
|
|
175
|
+
text: string;
|
|
176
|
+
title?: string;
|
|
177
|
+
score?: number;
|
|
178
|
+
normalizedScore?: number;
|
|
179
|
+
confidence?: number;
|
|
180
|
+
createdAt?: string;
|
|
181
|
+
validUntil?: string;
|
|
182
|
+
lastVerifiedAt?: string;
|
|
183
|
+
metadata?: Record<string, unknown>;
|
|
184
|
+
}
|
|
185
|
+
interface AgentMemoryContext {
|
|
186
|
+
query: string;
|
|
187
|
+
text: string;
|
|
188
|
+
hits: AgentMemoryHit[];
|
|
189
|
+
sourceRecords: SourceRecord[];
|
|
190
|
+
metadata?: Record<string, unknown>;
|
|
191
|
+
}
|
|
192
|
+
interface AgentMemorySearchOptions {
|
|
193
|
+
scope?: AgentMemoryScope;
|
|
194
|
+
limit?: number;
|
|
195
|
+
minScore?: number;
|
|
196
|
+
kinds?: AgentMemoryKind[];
|
|
197
|
+
metadata?: Record<string, unknown>;
|
|
198
|
+
/**
|
|
199
|
+
* Opt-in randomized retrieval holdout (epsilon-dropout) for treatment-effect logging.
|
|
200
|
+
* Absent by default; when absent, retrieval behavior is unchanged. See ./holdout.
|
|
201
|
+
*/
|
|
202
|
+
holdout?: RetrievalHoldoutConfig;
|
|
203
|
+
}
|
|
204
|
+
interface AgentMemoryWriteInput {
|
|
205
|
+
kind: AgentMemoryKind;
|
|
206
|
+
text: string;
|
|
207
|
+
id?: string;
|
|
208
|
+
title?: string;
|
|
209
|
+
role?: 'system' | 'user' | 'assistant' | 'tool';
|
|
210
|
+
entityName?: string;
|
|
211
|
+
entityType?: string;
|
|
212
|
+
category?: string;
|
|
213
|
+
predicate?: string;
|
|
214
|
+
subject?: string;
|
|
215
|
+
object?: string;
|
|
216
|
+
confidence?: number;
|
|
217
|
+
scope?: AgentMemoryScope;
|
|
218
|
+
metadata?: Record<string, unknown>;
|
|
219
|
+
}
|
|
220
|
+
interface AgentMemoryWriteResult {
|
|
221
|
+
accepted: boolean;
|
|
222
|
+
id: string;
|
|
223
|
+
uri: string;
|
|
224
|
+
kind: AgentMemoryKind;
|
|
225
|
+
sourceRecord?: SourceRecord;
|
|
226
|
+
metadata?: Record<string, unknown>;
|
|
227
|
+
}
|
|
228
|
+
type AgentMemoryBranchIsolation = {
|
|
229
|
+
mode: 'scoped';
|
|
230
|
+
/** False when writes may outlive the worker process that issued them. */
|
|
231
|
+
processExitSafe?: boolean;
|
|
232
|
+
/** Wait before clearing an abandoned branch so accepted asynchronous writes become visible. */
|
|
233
|
+
recoveryDelayMs?: number;
|
|
234
|
+
} | {
|
|
235
|
+
mode: 'instance';
|
|
236
|
+
branchId: string;
|
|
237
|
+
/** True only when the dedicated instance also enforces every logical scope. */
|
|
238
|
+
supportsLogicalScopes?: boolean;
|
|
239
|
+
} | {
|
|
240
|
+
mode: 'unsupported';
|
|
241
|
+
reason: string;
|
|
242
|
+
};
|
|
243
|
+
interface AgentMemoryAdapter {
|
|
244
|
+
readonly id: string;
|
|
245
|
+
/** How this adapter prevents candidate branches from reading each other's state. */
|
|
246
|
+
readonly branchIsolation?: AgentMemoryBranchIsolation;
|
|
247
|
+
search(query: string, options?: AgentMemorySearchOptions): Promise<AgentMemoryHit[]>;
|
|
248
|
+
getContext(query: string, options?: AgentMemorySearchOptions): Promise<AgentMemoryContext>;
|
|
249
|
+
write(input: AgentMemoryWriteInput): Promise<AgentMemoryWriteResult>;
|
|
250
|
+
/** Delete exactly this scope. Repeated and concurrent calls for the same scope must be safe. */
|
|
251
|
+
clear?(scope?: AgentMemoryScope): Promise<void>;
|
|
252
|
+
flush?(): Promise<void>;
|
|
253
|
+
close?(): Promise<void>;
|
|
254
|
+
}
|
|
255
|
+
interface RetrievalHoldoutConfig {
|
|
256
|
+
/** Per-session probability that one eligible watchlist item is suppressed. 0 logs the full schema without ever dropping. */
|
|
257
|
+
epsilon: number;
|
|
258
|
+
/** Item ids eligible for suppression. Empty or absent means no item can ever be dropped. */
|
|
259
|
+
watchlist?: string[];
|
|
260
|
+
/** Ties every event to the exact epsilon/watchlist in force, for audit and replay. */
|
|
261
|
+
configVersion?: string;
|
|
262
|
+
/** Copied onto every event so multi-adapter logs stay attributable. */
|
|
263
|
+
adapterId?: string;
|
|
264
|
+
/** Corpus/store version stamp; an edited item under the same id is a different treatment. */
|
|
265
|
+
corpusVersion?: string;
|
|
266
|
+
/**
|
|
267
|
+
* Emit plaintext sessionId and scope on events. Default false: events carry only
|
|
268
|
+
* sessionIdHash/scopeHash, so PII-bearing identifiers (tenantId/userId/tags) never reach a
|
|
269
|
+
* consumer-controlled sink unless the consumer explicitly owns that decision. Note that
|
|
270
|
+
* replaying assignment draws from logs alone needs the plaintext sessionId, so
|
|
271
|
+
* privacy-default logs require the consumer's own sessionId mapping for replay audits.
|
|
272
|
+
*/
|
|
273
|
+
includePlaintextIdentifiers?: boolean;
|
|
274
|
+
/**
|
|
275
|
+
* Cap on tracked sessions per experiment config in the sticky wrapper's registry.
|
|
276
|
+
* Exists so tests can exercise eviction; production should keep the default (10,000).
|
|
277
|
+
*/
|
|
278
|
+
maxTrackedSessions?: number;
|
|
279
|
+
/**
|
|
280
|
+
* Uniform-[0,1) generator keyed by a string. Defaults to a sha256-derived deterministic
|
|
281
|
+
* generator so every assignment is replayable from the logged keys alone (design rule D5).
|
|
282
|
+
*/
|
|
283
|
+
rng?: (key: string) => number;
|
|
284
|
+
/** Receives one event per retrieval call, INCLUDING no-drop calls: control-arm membership is half the data. */
|
|
285
|
+
onEvent: (event: RetrievalHoldoutEvent) => void;
|
|
286
|
+
}
|
|
287
|
+
interface RetrievalHoldoutEligibleItem {
|
|
288
|
+
id: string;
|
|
289
|
+
/** 1-based position in the post-filter hit list. */
|
|
290
|
+
rank: number;
|
|
291
|
+
score?: number;
|
|
292
|
+
kind: string;
|
|
293
|
+
/** sha256(hit.text) prefix; effects are estimated per (id, contentHash) pair. */
|
|
294
|
+
contentHash: string;
|
|
295
|
+
}
|
|
296
|
+
interface RetrievalHoldoutEvent {
|
|
297
|
+
v: 1;
|
|
298
|
+
eventId: string;
|
|
299
|
+
ts: string;
|
|
300
|
+
adapterId?: string;
|
|
301
|
+
/** Plaintext session id — emitted ONLY when config.includePlaintextIdentifiers is true. */
|
|
302
|
+
sessionId?: string;
|
|
303
|
+
/** Consumer-supplied experiment/outcome join id (scope.tags.taskId); deliberately plaintext. */
|
|
304
|
+
taskId?: string;
|
|
305
|
+
/** 1-based call counter within the session; 0 when the call is outside session randomization. */
|
|
306
|
+
callIndex: number;
|
|
307
|
+
/**
|
|
308
|
+
* sha256(sessionId) prefix — the default privacy-preserving session join key AND the seed-key
|
|
309
|
+
* reference for the assignment draws (previously named rngKey; identical derivation, deduped).
|
|
310
|
+
*/
|
|
311
|
+
sessionIdHash?: string;
|
|
312
|
+
queryHash?: string;
|
|
313
|
+
/** Verbatim scope — emitted ONLY when config.includePlaintextIdentifiers is true (PII risk). */
|
|
314
|
+
scope?: AgentMemoryScope;
|
|
315
|
+
/** sha256 prefix of the canonical-JSON scope (keys sorted, undefined stripped). */
|
|
316
|
+
scopeHash?: string;
|
|
317
|
+
config: {
|
|
318
|
+
epsilon: number;
|
|
319
|
+
watchlist: string[];
|
|
320
|
+
configVersion?: string;
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Value-hash of the experiment-defining knobs, sha256({epsilon, sorted watchlist}) prefix.
|
|
324
|
+
* The estimator groups events by it; the sticky-session registry is keyed by it.
|
|
325
|
+
*/
|
|
326
|
+
configHash: string;
|
|
327
|
+
/**
|
|
328
|
+
* False when no sessionId is available or the adapter answered without retrieval
|
|
329
|
+
* (see bypassReason), so the fraction-under-experiment denominator stays honest.
|
|
330
|
+
*/
|
|
331
|
+
holdoutEligible: boolean;
|
|
332
|
+
/** Present only on adapter paths that bypassed retrieval, where no suppression could apply. */
|
|
333
|
+
bypassReason?: RetrievalHoldoutBypassReason;
|
|
334
|
+
/** The full post-filter eligibility set E, logged on every call (control arm + interference probes). */
|
|
335
|
+
eligible: RetrievalHoldoutEligibleItem[];
|
|
336
|
+
/** Ids in watchlist ∩ E, in eligibility order. */
|
|
337
|
+
watchlistEligible: string[];
|
|
338
|
+
sessionHoldout: boolean;
|
|
339
|
+
/** The session's sticky drop target once drawn; distinguishes "target absent from E" from "not yet drawn". */
|
|
340
|
+
sessionTargetId: string | null;
|
|
341
|
+
/** The item suppressed in THIS call, or null. */
|
|
342
|
+
droppedId: string | null;
|
|
343
|
+
/** 1/|watchlist ∩ E| recorded at draw time; the exact inverse-propensity weight input. */
|
|
344
|
+
pickPropensity: number | null;
|
|
345
|
+
/** epsilon * pickPropensity, recorded at draw time so analysis never re-derives assignment probabilities. */
|
|
346
|
+
dropPropensity: number | null;
|
|
347
|
+
deliveredIds: string[];
|
|
348
|
+
corpusVersion?: string;
|
|
349
|
+
}
|
|
350
|
+
interface RetrievalHoldoutSessionState {
|
|
351
|
+
sessionId: string;
|
|
352
|
+
/** Calls observed so far in this session. */
|
|
353
|
+
callCount: number;
|
|
354
|
+
sessionHoldout: boolean;
|
|
355
|
+
/** Sticky drop target; drawn once at the first call whose eligibility set intersects the watchlist. */
|
|
356
|
+
targetId: string | null;
|
|
357
|
+
pickPropensity: number | null;
|
|
358
|
+
}
|
|
359
|
+
interface RetrievalHoldoutCallContext {
|
|
360
|
+
sessionId?: string;
|
|
361
|
+
taskId?: string;
|
|
362
|
+
/** Raw query; only its sha256 prefix is logged. */
|
|
363
|
+
query?: string;
|
|
364
|
+
scope?: AgentMemoryScope;
|
|
365
|
+
/** State returned by the previous call of this session; threading it is what makes suppression sticky. */
|
|
366
|
+
session?: RetrievalHoldoutSessionState;
|
|
367
|
+
}
|
|
368
|
+
interface RetrievalHoldoutResult {
|
|
369
|
+
delivered: AgentMemoryHit[];
|
|
370
|
+
event: RetrievalHoldoutEvent;
|
|
371
|
+
session?: RetrievalHoldoutSessionState;
|
|
372
|
+
}
|
|
373
|
+
/** Adapter context paths that answer without retrieval, so no holdout draw can happen. */
|
|
374
|
+
type RetrievalHoldoutBypassReason = 'short-term-context' | 'raw-string-context';
|
|
375
|
+
|
|
376
|
+
interface AgentMemoryRunLease {
|
|
377
|
+
assertOwned(): Promise<void> | void;
|
|
378
|
+
release(): Promise<void> | void;
|
|
379
|
+
}
|
|
380
|
+
type AgentMemoryAcquireRunLease = (input: {
|
|
381
|
+
experimentId: string;
|
|
382
|
+
runDir: string;
|
|
383
|
+
}) => AgentMemoryRunLease | Promise<AgentMemoryRunLease>;
|
|
384
|
+
type AgentMemoryControllerMode = 'process-local';
|
|
385
|
+
interface OwnedAgentMemoryRunLease {
|
|
386
|
+
assertOwned(): Promise<void>;
|
|
387
|
+
release(): Promise<void>;
|
|
388
|
+
}
|
|
389
|
+
declare function acquireAgentMemoryRunLease(input: {
|
|
390
|
+
experimentId: string;
|
|
391
|
+
runDir: string;
|
|
392
|
+
storage: CampaignStorage;
|
|
393
|
+
customStorage: boolean;
|
|
394
|
+
lockFileName: string;
|
|
395
|
+
label: string;
|
|
396
|
+
controllerMode?: AgentMemoryControllerMode;
|
|
397
|
+
acquireRunLease?: AgentMemoryAcquireRunLease;
|
|
398
|
+
}): Promise<OwnedAgentMemoryRunLease>;
|
|
399
|
+
|
|
400
|
+
type KnowledgeBenchmarkTaskKind = 'retrieval' | 'rag-answer' | 'hallucination' | 'kb-improvement' | 'memory-ingest' | 'memory-recall' | 'memory-temporal' | 'memory-update' | 'memory-forgetting' | 'memory-reasoning' | 'memory-summarization' | 'memory-recommendation' | 'memory-multiparty';
|
|
401
|
+
type KnowledgeAnswerBenchmarkTaskKind = 'rag-answer' | 'hallucination' | 'kb-improvement';
|
|
402
|
+
type KnowledgeMemoryBenchmarkTaskKind = Exclude<KnowledgeBenchmarkTaskKind, 'retrieval' | KnowledgeAnswerBenchmarkTaskKind>;
|
|
403
|
+
type KnowledgeBenchmarkFamily = 'beir' | 'mteb-retrieval' | 'msmarco' | 'trec-dl' | 'miracl' | 'lotte' | 'bright' | 'crag' | 'hotpotqa' | 'kilt' | 'ragtruth' | 'faithbench' | 'locomo' | 'longmemeval' | 'longmemeval-v2' | 'memora' | 'memoryagentbench' | 'memorybank' | 'groupmembench' | 'first-party' | 'custom';
|
|
404
|
+
type KnowledgeBenchmarkSplit = 'search' | 'dev' | 'holdout' | string;
|
|
405
|
+
interface KnowledgeBenchmarkSource {
|
|
406
|
+
name?: string;
|
|
407
|
+
url?: string;
|
|
408
|
+
version?: string;
|
|
409
|
+
license?: string;
|
|
410
|
+
citation?: string;
|
|
411
|
+
}
|
|
412
|
+
interface KnowledgeBenchmarkSpec {
|
|
413
|
+
id: string;
|
|
414
|
+
family: KnowledgeBenchmarkFamily;
|
|
415
|
+
taskKind: KnowledgeBenchmarkTaskKind;
|
|
416
|
+
primaryMetrics: readonly string[];
|
|
417
|
+
adapter: string;
|
|
418
|
+
notes: string;
|
|
419
|
+
}
|
|
420
|
+
interface KnowledgeBenchmarkCaseBase {
|
|
421
|
+
id: string;
|
|
422
|
+
family: KnowledgeBenchmarkFamily | string;
|
|
423
|
+
taskKind: KnowledgeBenchmarkTaskKind;
|
|
424
|
+
split?: KnowledgeBenchmarkSplit;
|
|
425
|
+
tags?: readonly string[];
|
|
426
|
+
source?: KnowledgeBenchmarkSource;
|
|
427
|
+
metadata?: Record<string, unknown>;
|
|
428
|
+
}
|
|
429
|
+
interface KnowledgeRetrievalBenchmarkCase extends KnowledgeBenchmarkCaseBase {
|
|
430
|
+
taskKind: 'retrieval';
|
|
431
|
+
query: string;
|
|
432
|
+
expected: RetrievalGoldTarget | readonly RetrievalGoldTarget[];
|
|
433
|
+
k?: number;
|
|
434
|
+
}
|
|
435
|
+
interface KnowledgeClaimMatcher {
|
|
436
|
+
id: string;
|
|
437
|
+
anyOf: readonly string[];
|
|
438
|
+
weight?: number;
|
|
439
|
+
}
|
|
440
|
+
interface KnowledgeMemoryEvent {
|
|
441
|
+
id: string;
|
|
442
|
+
text: string;
|
|
443
|
+
actorId?: string;
|
|
444
|
+
sessionId?: string;
|
|
445
|
+
timestamp?: string;
|
|
446
|
+
metadata?: Record<string, unknown>;
|
|
447
|
+
}
|
|
448
|
+
interface KnowledgeMemoryFactMatcher extends KnowledgeClaimMatcher {
|
|
449
|
+
sourceEventIds?: readonly string[];
|
|
450
|
+
validAt?: string;
|
|
451
|
+
obsolete?: boolean;
|
|
452
|
+
}
|
|
453
|
+
interface KnowledgeAnswerBenchmarkCase extends KnowledgeBenchmarkCaseBase {
|
|
454
|
+
taskKind: KnowledgeAnswerBenchmarkTaskKind;
|
|
455
|
+
prompt: string;
|
|
456
|
+
requiredClaims?: readonly KnowledgeClaimMatcher[];
|
|
457
|
+
forbiddenClaims?: readonly KnowledgeClaimMatcher[];
|
|
458
|
+
expectedSourceIds?: readonly string[];
|
|
459
|
+
referenceAnswer?: string;
|
|
460
|
+
}
|
|
461
|
+
interface KnowledgeMemoryBenchmarkCase extends KnowledgeBenchmarkCaseBase {
|
|
462
|
+
taskKind: KnowledgeMemoryBenchmarkTaskKind;
|
|
463
|
+
events: readonly KnowledgeMemoryEvent[];
|
|
464
|
+
prompt: string;
|
|
465
|
+
requiredFacts?: readonly KnowledgeMemoryFactMatcher[];
|
|
466
|
+
forbiddenFacts?: readonly KnowledgeMemoryFactMatcher[];
|
|
467
|
+
expectedEventIds?: readonly string[];
|
|
468
|
+
expectedActorIds?: readonly string[];
|
|
469
|
+
referenceAnswer?: string;
|
|
470
|
+
}
|
|
471
|
+
type KnowledgeBenchmarkCase = KnowledgeRetrievalBenchmarkCase | KnowledgeAnswerBenchmarkCase | KnowledgeMemoryBenchmarkCase;
|
|
472
|
+
interface KnowledgeBenchmarkArtifact {
|
|
473
|
+
answer?: string;
|
|
474
|
+
text?: string;
|
|
475
|
+
hits?: readonly RetrievedKnowledgeHit[];
|
|
476
|
+
citedSourceIds?: readonly string[];
|
|
477
|
+
rememberedFacts?: readonly string[];
|
|
478
|
+
citedEventIds?: readonly string[];
|
|
479
|
+
usedMemoryIds?: readonly string[];
|
|
480
|
+
actorIds?: readonly string[];
|
|
481
|
+
/** Informational copy. Billable responders account through context.cost.runPaidCall. */
|
|
482
|
+
costUsd?: number;
|
|
483
|
+
durationMs?: number;
|
|
484
|
+
metadata?: Record<string, unknown>;
|
|
485
|
+
}
|
|
486
|
+
interface KnowledgeBenchmarkEvaluation {
|
|
487
|
+
score: number;
|
|
488
|
+
passed: boolean;
|
|
489
|
+
dimensions: Record<string, number>;
|
|
490
|
+
/** Dimensions for which this case declared an actual target. */
|
|
491
|
+
applicableDimensions?: readonly string[];
|
|
492
|
+
notes: string;
|
|
493
|
+
raw: Record<string, unknown>;
|
|
494
|
+
}
|
|
495
|
+
interface KnowledgeBenchmarkScenario extends Scenario {
|
|
496
|
+
kind: 'knowledge-benchmark';
|
|
497
|
+
family: KnowledgeBenchmarkFamily | string;
|
|
498
|
+
taskKind: KnowledgeBenchmarkTaskKind;
|
|
499
|
+
splitTag: KnowledgeBenchmarkSplit;
|
|
500
|
+
case: KnowledgeBenchmarkCase;
|
|
501
|
+
}
|
|
502
|
+
type KnowledgeBenchmarkResponder<TArtifact = KnowledgeBenchmarkArtifact> = (input: {
|
|
503
|
+
case: KnowledgeBenchmarkCase;
|
|
504
|
+
scenario: KnowledgeBenchmarkScenario;
|
|
505
|
+
context: DispatchContext;
|
|
506
|
+
}) => Promise<TArtifact> | TArtifact;
|
|
507
|
+
interface RunKnowledgeBenchmarkSuiteOptions<TArtifact = KnowledgeBenchmarkArtifact> {
|
|
508
|
+
cases: readonly KnowledgeBenchmarkCase[];
|
|
509
|
+
respond: KnowledgeBenchmarkResponder<TArtifact>;
|
|
510
|
+
/** Versioned identity for the model, prompt, retrieval, and runtime behavior. */
|
|
511
|
+
respondRef?: string;
|
|
512
|
+
runDir: string;
|
|
513
|
+
splits?: readonly KnowledgeBenchmarkSplit[];
|
|
514
|
+
repo?: string;
|
|
515
|
+
seed?: number;
|
|
516
|
+
reps?: number;
|
|
517
|
+
resumable?: boolean;
|
|
518
|
+
costCeiling?: number;
|
|
519
|
+
/** Shared across nested benchmark suites when an outer run owns spend. */
|
|
520
|
+
costLedger?: CostLedgerHandle;
|
|
521
|
+
costPhase?: string;
|
|
522
|
+
maxConcurrency?: number;
|
|
523
|
+
dispatchTimeoutMs?: number;
|
|
524
|
+
expectUsage?: 'assert' | 'warn' | 'off';
|
|
525
|
+
storage?: CampaignStorage;
|
|
526
|
+
now?: () => Date;
|
|
527
|
+
}
|
|
528
|
+
interface KnowledgeBenchmarkDistribution {
|
|
529
|
+
n: number;
|
|
530
|
+
min: number;
|
|
531
|
+
mean: number;
|
|
532
|
+
median: number;
|
|
533
|
+
p90: number;
|
|
534
|
+
max: number;
|
|
535
|
+
}
|
|
536
|
+
interface KnowledgeBenchmarkSliceSummary {
|
|
537
|
+
n: number;
|
|
538
|
+
meanScore: number;
|
|
539
|
+
passRate: number;
|
|
540
|
+
score: KnowledgeBenchmarkDistribution;
|
|
541
|
+
}
|
|
542
|
+
interface KnowledgeBenchmarkReport {
|
|
543
|
+
totalCases: number;
|
|
544
|
+
totalCells: number;
|
|
545
|
+
cellsFailed: number;
|
|
546
|
+
cellsCached: number;
|
|
547
|
+
totalCostUsd: number;
|
|
548
|
+
bySplit: Record<string, KnowledgeBenchmarkSliceSummary>;
|
|
549
|
+
byFamily: Record<string, KnowledgeBenchmarkSliceSummary>;
|
|
550
|
+
byTaskKind: Record<string, KnowledgeBenchmarkSliceSummary>;
|
|
551
|
+
dimensions: Record<string, KnowledgeBenchmarkDistribution>;
|
|
552
|
+
score: KnowledgeBenchmarkDistribution;
|
|
553
|
+
}
|
|
554
|
+
interface RunKnowledgeBenchmarkSuiteResult<TArtifact = KnowledgeBenchmarkArtifact> {
|
|
555
|
+
scenarios: readonly KnowledgeBenchmarkScenario[];
|
|
556
|
+
campaign: CampaignResult<TArtifact, KnowledgeBenchmarkScenario>;
|
|
557
|
+
report: KnowledgeBenchmarkReport;
|
|
558
|
+
reportJsonPath: string;
|
|
559
|
+
reportMarkdownPath: string;
|
|
560
|
+
}
|
|
561
|
+
interface MemoryAdapterBenchmarkCandidate {
|
|
562
|
+
id: string;
|
|
563
|
+
/** Versioned adapter and configuration identity used by resumable caches. */
|
|
564
|
+
ref: string;
|
|
565
|
+
/** Expected adapter.id. Defaults to candidate id and permits lazy no-work resume. */
|
|
566
|
+
adapterId?: string;
|
|
567
|
+
label?: string;
|
|
568
|
+
/** Local construction is free; call markExternalCall before billable provisioning or reconnects. */
|
|
569
|
+
createAdapter: (input: {
|
|
570
|
+
purpose: 'execute' | 'recovery';
|
|
571
|
+
signal: AbortSignal;
|
|
572
|
+
markExternalCall(): void;
|
|
573
|
+
}) => AgentMemoryAdapter | Promise<AgentMemoryAdapter>;
|
|
574
|
+
/** Conservative charge for one billable adapter provisioning or reconnect call. */
|
|
575
|
+
adapterCreationCostUsd?: number;
|
|
576
|
+
searchLimit?: number;
|
|
577
|
+
costUsdPerCase?: number;
|
|
578
|
+
/** Conservative extra provider charge for recovering one interrupted case. */
|
|
579
|
+
recoveryCostUsdPerAttempt?: number;
|
|
580
|
+
scope?: AgentMemoryScope;
|
|
581
|
+
}
|
|
582
|
+
interface RunMemoryAdapterBenchmarkOptions {
|
|
583
|
+
cases: readonly KnowledgeMemoryBenchmarkCase[];
|
|
584
|
+
candidates: readonly MemoryAdapterBenchmarkCandidate[];
|
|
585
|
+
/** Retired candidates retained only so interrupted scopes can be cleaned on resume. */
|
|
586
|
+
recoveryCandidates?: readonly MemoryAdapterBenchmarkCandidate[];
|
|
587
|
+
runDir: string;
|
|
588
|
+
storage?: CampaignStorage;
|
|
589
|
+
repo?: string;
|
|
590
|
+
seed?: number;
|
|
591
|
+
reps?: number;
|
|
592
|
+
resumable?: boolean;
|
|
593
|
+
costCeiling?: number;
|
|
594
|
+
/** Shared with nested benchmark suites so the dollar limit applies to the whole comparison. */
|
|
595
|
+
costLedger?: CostLedgerHandle;
|
|
596
|
+
costPhase?: string;
|
|
597
|
+
maxConcurrency?: number;
|
|
598
|
+
dispatchTimeoutMs?: number;
|
|
599
|
+
cleanupTimeoutMs?: number;
|
|
600
|
+
/** Refuse a damaged run with more unfinished attempts than this. Default 1000. */
|
|
601
|
+
maxRecoveryAttempts?: number;
|
|
602
|
+
/** Bound repeated provider cleanup after process crashes. Default 3 per attempt. */
|
|
603
|
+
maxRecoveryRetriesPerAttempt?: number;
|
|
604
|
+
expectUsage?: 'assert' | 'warn' | 'off';
|
|
605
|
+
now?: () => Date;
|
|
606
|
+
/** Required with custom storage when all controllers are confined to one process. */
|
|
607
|
+
controllerMode?: AgentMemoryControllerMode;
|
|
608
|
+
/** Required for distributed controllers that share custom storage. */
|
|
609
|
+
acquireRunLease?: AgentMemoryAcquireRunLease;
|
|
610
|
+
}
|
|
611
|
+
interface MemoryAdapterBenchmarkRankingRow {
|
|
612
|
+
rank: number;
|
|
613
|
+
candidateId: string;
|
|
614
|
+
label: string;
|
|
615
|
+
adapterId: string;
|
|
616
|
+
scoreMean: number;
|
|
617
|
+
passRate: number;
|
|
618
|
+
totalCases: number;
|
|
619
|
+
totalCells: number;
|
|
620
|
+
cellsFailed: number;
|
|
621
|
+
totalCostUsd: number;
|
|
622
|
+
reportJsonPath: string;
|
|
623
|
+
reportMarkdownPath: string;
|
|
624
|
+
report: KnowledgeBenchmarkReport;
|
|
625
|
+
}
|
|
626
|
+
interface RunMemoryAdapterBenchmarkResult {
|
|
627
|
+
rows: readonly MemoryAdapterBenchmarkRankingRow[];
|
|
628
|
+
totalCostUsd: number;
|
|
629
|
+
/** Recovery spend for retired candidates, excluded from ranking rows but included in totalCostUsd. */
|
|
630
|
+
unrankedRecoveryCostUsd: number;
|
|
631
|
+
rankingJsonPath: string;
|
|
632
|
+
rankingMarkdownPath: string;
|
|
633
|
+
attemptLogPath: string;
|
|
634
|
+
recoveryLogPath: string;
|
|
635
|
+
}
|
|
636
|
+
interface KnowledgeRetrievalBenchmarkQuery {
|
|
637
|
+
id: string;
|
|
638
|
+
text: string;
|
|
639
|
+
split?: KnowledgeBenchmarkSplit;
|
|
640
|
+
tags?: readonly string[];
|
|
641
|
+
metadata?: Record<string, unknown>;
|
|
642
|
+
}
|
|
643
|
+
interface KnowledgeRetrievalBenchmarkQrel {
|
|
644
|
+
queryId: string;
|
|
645
|
+
documentId: string;
|
|
646
|
+
score: number;
|
|
647
|
+
}
|
|
648
|
+
interface BuildRetrievalBenchmarkCasesFromQrelsOptions {
|
|
649
|
+
benchmarkId: string;
|
|
650
|
+
family: KnowledgeBenchmarkFamily | string;
|
|
651
|
+
queries: readonly KnowledgeRetrievalBenchmarkQuery[];
|
|
652
|
+
qrels: readonly KnowledgeRetrievalBenchmarkQrel[];
|
|
653
|
+
source?: KnowledgeBenchmarkSource;
|
|
654
|
+
tags?: readonly string[];
|
|
655
|
+
k?: number;
|
|
656
|
+
targetKind?: 'page' | 'page-path' | 'source';
|
|
657
|
+
documentTarget?: (documentId: string, qrel: KnowledgeRetrievalBenchmarkQrel) => RetrievalGoldTarget;
|
|
658
|
+
splitOf?: (queryId: string) => KnowledgeBenchmarkSplit;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
export { type RetrievalHoldoutConfig as $, type AgentMemoryAcquireRunLease as A, type BuildRetrievalBenchmarkCasesFromQrelsOptions as B, type KnowledgeBenchmarkSpec as C, type KnowledgeBenchmarkSplit as D, type KnowledgeBenchmarkTaskKind as E, type KnowledgeClaimMatcher as F, type KnowledgeMemoryBenchmarkCase as G, type KnowledgeMemoryBenchmarkTaskKind as H, type KnowledgeMemoryEvent as I, type KnowledgeMemoryFactMatcher as J, type KnowledgeAnswerBenchmarkCase as K, type KnowledgeRetrievalBenchmarkCase as L, type KnowledgeRetrievalBenchmarkQrel as M, type KnowledgeRetrievalBenchmarkQuery as N, type MemoryAdapterBenchmarkCandidate as O, type MemoryAdapterBenchmarkRankingRow as P, type OwnedAgentMemoryRunLease as Q, type RunRetrievalImprovementLoopResult as R, type RetrievalConfig as S, type RetrievalEvalArtifact as T, type RetrievalEvalRetriever as U, type RetrievalEvalRetrieverInput as V, type RetrievalEvalRetrieverResult as W, type RetrievalEvalScenario as X, type RetrievalGoldTarget as Y, type RetrievalHoldoutBypassReason as Z, type RetrievalHoldoutCallContext as _, type RunRetrievalImprovementLoopOptions as a, type RetrievalHoldoutEligibleItem as a0, type RetrievalHoldoutEvent as a1, type RetrievalHoldoutResult as a2, type RetrievalHoldoutSessionState as a3, type RetrievalMetricSummary as a4, type RetrievalMetricWeights as a5, type RetrievalParameterSearchSpace as a6, type RetrievalParameterSweepProposerOptions as a7, type RetrievalRecallJudgeOptions as a8, type RetrievedKnowledgeHit as a9, type RetrievedSourceSpan as aa, type RunKnowledgeBenchmarkSuiteOptions as ab, type RunKnowledgeBenchmarkSuiteResult as ac, type RunMemoryAdapterBenchmarkOptions as ad, type RunMemoryAdapterBenchmarkResult as ae, acquireAgentMemoryRunLease as af, buildRetrievalEvalDispatch as ag, buildRetrievalParameterCandidates as ah, retrievalConfigFromSurface as ai, retrievalConfigSurface as aj, retrievalParameterSweepProposer as ak, retrievalRecallJudge as al, runRetrievalImprovementLoop as am, scoreRetrievalArtifact as an, type AgentMemoryAdapter as b, type AgentMemoryBranchIsolation as c, type AgentMemoryContext as d, type AgentMemoryControllerMode as e, type AgentMemoryHit as f, type AgentMemoryKind as g, type AgentMemoryRunLease as h, type AgentMemoryScope as i, type AgentMemorySearchOptions as j, type AgentMemoryWriteInput as k, type AgentMemoryWriteResult as l, type BuildRetrievalEvalDispatchOptions as m, type BuildRetrievalParameterCandidatesOptions as n, type KnowledgeAnswerBenchmarkTaskKind as o, type KnowledgeBenchmarkArtifact as p, type KnowledgeBenchmarkCase as q, type KnowledgeBenchmarkCaseBase as r, type KnowledgeBenchmarkDistribution as s, type KnowledgeBenchmarkEvaluation as t, type KnowledgeBenchmarkFamily as u, type KnowledgeBenchmarkReport as v, type KnowledgeBenchmarkResponder as w, type KnowledgeBenchmarkScenario as x, type KnowledgeBenchmarkSliceSummary as y, type KnowledgeBenchmarkSource as z };
|