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