@tangle-network/agent-eval 0.130.0 → 0.131.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +1 -0
- package/dist/analyst/index.js +1 -1
- package/dist/benchmarks/index.d.ts +1 -1
- package/dist/benchmarks/index.js +1 -1
- package/dist/{benchmarks-DviOvUNr.js → benchmarks-SRt_Rwuc.js} +3 -3
- package/dist/{benchmarks-DviOvUNr.js.map → benchmarks-SRt_Rwuc.js.map} +1 -1
- package/dist/campaign/index.d.ts +2 -2
- package/dist/campaign/index.js +2 -2
- package/dist/{campaign-CBKZvQ1H.js → campaign-1WfDhAl4.js} +4 -3
- package/dist/{campaign-CBKZvQ1H.js.map → campaign-1WfDhAl4.js.map} +1 -1
- package/dist/concurrency-MUjT7VjM.js +109 -0
- package/dist/concurrency-MUjT7VjM.js.map +1 -0
- package/dist/contract/index.d.ts +57 -3
- package/dist/contract/index.d.ts.map +1 -1
- package/dist/contract/index.js +293 -47
- package/dist/contract/index.js.map +1 -1
- package/dist/{index-DE5fb3EC.d.ts → index-CD_WZ_Xr.d.ts} +8 -2
- package/dist/{index-DE5fb3EC.d.ts.map → index-CD_WZ_Xr.d.ts.map} +1 -1
- package/dist/{index-CAPUUKaM.d.ts → index-Em67JBjs.d.ts} +3 -3
- package/dist/{index-CAPUUKaM.d.ts.map → index-Em67JBjs.d.ts.map} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/ledger-core/index.js +1 -1
- package/dist/{ledger-core-DtZz1RG0.js → ledger-core-eqaI3PCD.js} +2 -2
- package/dist/{ledger-core-DtZz1RG0.js.map → ledger-core-eqaI3PCD.js.map} +1 -1
- package/dist/openapi.json +1 -1
- package/dist/{semantic-concept-judge-B6cWNJ2K.js → semantic-concept-judge-b5m3irbR.js} +2 -2
- package/dist/{semantic-concept-judge-B6cWNJ2K.js.map → semantic-concept-judge-b5m3irbR.js.map} +1 -1
- package/dist/{skillopt-optimization-method-B7wX7XkF.d.ts → skillopt-optimization-method-CWKVTnks.d.ts} +2 -1
- package/dist/{skillopt-optimization-method-B7wX7XkF.d.ts.map → skillopt-optimization-method-CWKVTnks.d.ts.map} +1 -1
- package/dist/{skillopt-optimization-method-D4ODwFVV.js → skillopt-optimization-method-Dd6b38Ud.js} +9 -3
- package/dist/skillopt-optimization-method-Dd6b38Ud.js.map +1 -0
- package/docs/campaign-proposers.md +1 -0
- package/docs/concepts.md +11 -0
- package/package.json +1 -1
- package/dist/concurrency-DIxRZF_J.js +0 -85
- package/dist/concurrency-DIxRZF_J.js.map +0 -1
- package/dist/skillopt-optimization-method-D4ODwFVV.js.map +0 -1
package/dist/contract/index.js
CHANGED
|
@@ -3,7 +3,8 @@ import { i as parseRunRecordSafe, r as modelHasSnapshot } from "../run-record-Bu
|
|
|
3
3
|
import { L as createChatClient, t as buildDefaultAnalystRegistry } from "../default-registry-C-vFCSEc.js";
|
|
4
4
|
import { LLM_MODEL_ATTR_KEYS, SPAN_KIND_ATTR_KEYS } from "../trace-attributes.js";
|
|
5
5
|
import { b as classifyOtlpSpanRole, x as isOtlpModelCall } from "../tools-BmuN627J.js";
|
|
6
|
-
import {
|
|
6
|
+
import { r as mapConcurrentRange } from "../concurrency-MUjT7VjM.js";
|
|
7
|
+
import { B as surfaceContentHash, Ct as llmJudge, M as compareOptimizationMethods, O as composeGate, Q as inMemoryCampaignStorage, S as defaultProductionGate, T as heldoutSignificance, V as surfaceHash, X as createRunCostLedger, Y as runCampaign, Z as fsCampaignStorage, _ as buildEvidenceVector, a as emitLoopProvenance, b as powerPreflight, ct as campaignSplitDigest, d as runImprovementLoop, dt as REFERENCE_EQUIVALENCE_INPUT_LIMITS, ft as REFERENCE_EQUIVALENCE_JUDGE_VERSION, g as gepaOptimizationMethod, j as assertOptimizationResult, k as externalTextOptimizationMethod, mt as runReferenceEquivalenceJudge, o as loopProvenanceArgsFromResult, p as runEval, pt as createReferenceEquivalenceJudge, rt as resolveRunDir, t as skillOptOptimizationMethod, v as paretoPolicy, x as heldOutGate, y as paretoSignificanceGate } from "../skillopt-optimization-method-Dd6b38Ud.js";
|
|
7
8
|
import { v as pairedBootstrap } from "../statistics-CnnxdpOg.js";
|
|
8
9
|
import { i as summarizeTraceErrors, n as recordAggregateMeasurements, r as summarizeExecutionMeasurements, t as readTaskFailureLabels } from "../task-failure-attributes-CQZlB3et.js";
|
|
9
10
|
import { n as summarizeExecution, t as analyzeRuns } from "../analyze-runs-C1CavBMk.js";
|
|
@@ -13,7 +14,7 @@ import { a as fromPiSession, c as observeCodeAgentSession, i as fromOpenCodeSess
|
|
|
13
14
|
import { t as createHostedClient } from "../client-CYzbdJOZ.js";
|
|
14
15
|
import { dirname, join } from "node:path";
|
|
15
16
|
import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
16
|
-
import { agentCandidateBenchmarkSuiteSchema, agentCandidateBenchmarkTaskSchema, agentCandidateBundleSchema, agentCandidateEvaluationPolicySchema, agentCandidateExperimentSchema, agentImprovementMeasuredComparisonSchema, candidateExecutionEvidenceSchema, canonicalCandidateDigest, omitTopLevelDigest } from "@tangle-network/agent-interface";
|
|
17
|
+
import { agentCandidateBenchmarkSuiteSchema, agentCandidateBenchmarkTaskSchema, agentCandidateBundleSchema, agentCandidateEvaluationPolicySchema, agentCandidateExperimentSchema, agentImprovementMeasuredComparisonSchema, agentProfileImprovementExperimentSchema, agentProfileImprovementMeasuredComparisonSchema, agentProfileImprovementRunCellSchema, agentProfileImprovementRunReceiptSchema, agentProfileImprovementSuiteInputsSchema, agentProfileImprovementSuiteSchema, agentProfileImprovementTaskSchema, candidateExecutionEvidenceSchema, canonicalCandidateDigest, canonicalCandidateJson, omitTopLevelDigest } from "@tangle-network/agent-interface";
|
|
17
18
|
//#region src/contract/self-improve.ts
|
|
18
19
|
/**
|
|
19
20
|
* Run one complete improvement job.
|
|
@@ -545,6 +546,28 @@ function requirePositiveInteger(value, field) {
|
|
|
545
546
|
return value;
|
|
546
547
|
}
|
|
547
548
|
//#endregion
|
|
549
|
+
//#region src/contract/concurrent-map.ts
|
|
550
|
+
/** Map both arms while bounding the actual executions, not the number of pairs. */
|
|
551
|
+
async function mapPairedConcurrent(options) {
|
|
552
|
+
if (!Number.isSafeInteger(options.count) || options.count < 0) throw new Error(`${options.label} pair count must be a non-negative integer`);
|
|
553
|
+
if (options.count > Math.floor(Number.MAX_SAFE_INTEGER / 2)) throw new Error(`${options.label} pair count is too large to schedule both arms`);
|
|
554
|
+
const executions = await mapConcurrentRange({
|
|
555
|
+
count: options.count * 2,
|
|
556
|
+
maxConcurrency: options.maxConcurrency,
|
|
557
|
+
label: options.label,
|
|
558
|
+
...options.signal ? { signal: options.signal } : {},
|
|
559
|
+
map(flatIndex, signal) {
|
|
560
|
+
const index = Math.floor(flatIndex / 2);
|
|
561
|
+
const arm = flatIndex % 2 === 0 ? "baseline" : "candidate";
|
|
562
|
+
return options.map(index, arm, signal);
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
return Array.from({ length: options.count }, (_, index) => ({
|
|
566
|
+
baseline: executions[index * 2],
|
|
567
|
+
candidate: executions[index * 2 + 1]
|
|
568
|
+
}));
|
|
569
|
+
}
|
|
570
|
+
//#endregion
|
|
548
571
|
//#region src/contract/measured-comparison.ts
|
|
549
572
|
/** Content-address one task before any measured execution can see it. */
|
|
550
573
|
function sealCandidateBenchmarkTask(material) {
|
|
@@ -591,16 +614,12 @@ function verifyCandidateExperiment(input) {
|
|
|
591
614
|
async function runCandidateExperiment(options) {
|
|
592
615
|
const experiment = verifyCandidateExperiment(options.experiment);
|
|
593
616
|
const { suite, tasks } = experiment.benchmark;
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
if (options.signal?.aborted) throw abortError(options.signal);
|
|
601
|
-
const index = nextIndex;
|
|
602
|
-
nextIndex += 1;
|
|
603
|
-
if (index >= measurements.length) return;
|
|
617
|
+
return (await mapPairedConcurrent({
|
|
618
|
+
count: suite.taskDigests.length * suite.reps,
|
|
619
|
+
maxConcurrency: options.maxConcurrency ?? 2,
|
|
620
|
+
label: "candidate experiment",
|
|
621
|
+
...options.signal ? { signal: options.signal } : {},
|
|
622
|
+
async map(index, arm, signal) {
|
|
604
623
|
const taskIndex = Math.floor(index / suite.reps);
|
|
605
624
|
const repetition = index % suite.reps;
|
|
606
625
|
const task = tasks[taskIndex];
|
|
@@ -611,33 +630,17 @@ async function runCandidateExperiment(options) {
|
|
|
611
630
|
taskIndex,
|
|
612
631
|
repetition
|
|
613
632
|
};
|
|
614
|
-
|
|
633
|
+
return options.execute({
|
|
615
634
|
experiment,
|
|
616
|
-
arm
|
|
617
|
-
bundle: experiment
|
|
635
|
+
arm,
|
|
636
|
+
bundle: experiment[arm],
|
|
618
637
|
task,
|
|
619
638
|
benchmarkCell,
|
|
620
639
|
seed,
|
|
621
|
-
|
|
622
|
-
})
|
|
623
|
-
experiment,
|
|
624
|
-
arm: "candidate",
|
|
625
|
-
bundle: experiment.candidate,
|
|
626
|
-
task,
|
|
627
|
-
benchmarkCell,
|
|
628
|
-
seed,
|
|
629
|
-
...options.signal ? { signal: options.signal } : {}
|
|
630
|
-
})]);
|
|
631
|
-
const measurement = {
|
|
632
|
-
baseline,
|
|
633
|
-
candidate
|
|
634
|
-
};
|
|
635
|
-
verifyMeasurement(experiment, measurement, index);
|
|
636
|
-
measurements[index] = measurement;
|
|
640
|
+
signal
|
|
641
|
+
});
|
|
637
642
|
}
|
|
638
|
-
});
|
|
639
|
-
await Promise.all(lanes);
|
|
640
|
-
return measurements;
|
|
643
|
+
})).map((measurement, index) => verifyMeasurement(experiment, measurement, index));
|
|
641
644
|
}
|
|
642
645
|
/**
|
|
643
646
|
* Calculate the shared paired decision from any complete receipt shape.
|
|
@@ -721,14 +724,17 @@ function evaluatePairedMeasurements(options) {
|
|
|
721
724
|
availability: "measured",
|
|
722
725
|
...latency
|
|
723
726
|
});
|
|
724
|
-
const power =
|
|
725
|
-
|
|
726
|
-
|
|
727
|
+
const power = observedPairedPrecision({
|
|
728
|
+
baselineScores,
|
|
729
|
+
candidateScores,
|
|
730
|
+
delta: overall.delta,
|
|
731
|
+
lowerBound: overall.confidenceInterval.lower,
|
|
727
732
|
deltaThreshold,
|
|
733
|
+
minProductiveRuns,
|
|
728
734
|
confidence,
|
|
729
735
|
sharedScorerChannel: options.sharedScorerChannel
|
|
730
|
-
})
|
|
731
|
-
const powerSufficient =
|
|
736
|
+
});
|
|
737
|
+
const powerSufficient = power.sufficient;
|
|
732
738
|
const guardedDimensions = new Set(criticalDimensions);
|
|
733
739
|
const missingCriticalDimensions = criticalDimensions.filter((dimension) => !dimensions.includes(dimension));
|
|
734
740
|
const regressions = objectives.filter((objective) => objective.kind === "dimension" && guardedDimensions.has(objective.name) && objective.availability === "measured" && objective.confidenceInterval.lower < -regressionTolerance);
|
|
@@ -744,7 +750,7 @@ function evaluatePairedMeasurements(options) {
|
|
|
744
750
|
passed: significance.significant
|
|
745
751
|
},
|
|
746
752
|
{
|
|
747
|
-
name: "
|
|
753
|
+
name: "paired-precision",
|
|
748
754
|
passed: powerSufficient
|
|
749
755
|
},
|
|
750
756
|
{
|
|
@@ -767,7 +773,7 @@ function evaluatePairedMeasurements(options) {
|
|
|
767
773
|
const shipped = checks.every((check) => check.passed);
|
|
768
774
|
const reasons = [
|
|
769
775
|
...significance.significant ? [] : [significance.fewRuns ? `only ${significance.n} paired runs; ${minProductiveRuns} required` : `paired interval lower bound ${significance.bootstrap.low} did not clear ${deltaThreshold}`],
|
|
770
|
-
...powerSufficient ? [] : [power
|
|
776
|
+
...powerSufficient || significance.fewRuns ? [] : [power.reason],
|
|
771
777
|
...regressions.length === 0 ? [] : [`critical dimensions regressed: ${regressions.map((entry) => entry.name).join(", ")}`],
|
|
772
778
|
...missingCriticalDimensions.length === 0 ? [] : [`critical dimensions missing: ${missingCriticalDimensions.join(", ")}`],
|
|
773
779
|
...incompleteRuns.length === 0 ? [] : [`${incompleteRuns.length} benchmark executions did not exit successfully`],
|
|
@@ -790,11 +796,11 @@ function evaluatePairedMeasurements(options) {
|
|
|
790
796
|
power: {
|
|
791
797
|
sufficient: powerSufficient,
|
|
792
798
|
n: baselineScores.length,
|
|
793
|
-
minimumDetectableDelta: power
|
|
799
|
+
minimumDetectableDelta: power.minimumDetectableDelta,
|
|
794
800
|
confidenceLevel: confidence,
|
|
795
|
-
scaleAssumed: power
|
|
801
|
+
scaleAssumed: power.scaleAssumed,
|
|
796
802
|
sharedScorerChannel: options.sharedScorerChannel,
|
|
797
|
-
reason: power
|
|
803
|
+
reason: power.reason
|
|
798
804
|
},
|
|
799
805
|
executionCostUsd,
|
|
800
806
|
totalCostUsd,
|
|
@@ -1102,6 +1108,35 @@ function measuredEstimate(baseline, candidate, options) {
|
|
|
1102
1108
|
n: bootstrap.n
|
|
1103
1109
|
};
|
|
1104
1110
|
}
|
|
1111
|
+
function observedPairedPrecision(options) {
|
|
1112
|
+
const n = options.baselineScores.length;
|
|
1113
|
+
const lowerMargin = Math.max(0, options.delta - options.lowerBound);
|
|
1114
|
+
const minimumDetectableDelta = options.deltaThreshold + lowerMargin;
|
|
1115
|
+
const scaleAssumed = [...options.baselineScores, ...options.candidateScores].every((score) => score >= -.001 && score <= 1.001);
|
|
1116
|
+
const headroom = Math.max(0, 1 - mean(options.baselineScores));
|
|
1117
|
+
const enoughRuns = n >= options.minProductiveRuns;
|
|
1118
|
+
const attainable = !scaleAssumed || minimumDetectableDelta <= headroom;
|
|
1119
|
+
const sufficient = enoughRuns && attainable;
|
|
1120
|
+
const scorerNote = options.sharedScorerChannel ? " The same scorer evaluated both arms, so scorer bias is not measured." : "";
|
|
1121
|
+
if (!enoughRuns) return {
|
|
1122
|
+
sufficient,
|
|
1123
|
+
minimumDetectableDelta,
|
|
1124
|
+
scaleAssumed,
|
|
1125
|
+
reason: `only ${n} paired runs; ${options.minProductiveRuns} required.${scorerNote}`
|
|
1126
|
+
};
|
|
1127
|
+
if (!attainable) return {
|
|
1128
|
+
sufficient,
|
|
1129
|
+
minimumDetectableDelta,
|
|
1130
|
+
scaleAssumed,
|
|
1131
|
+
reason: `observed paired uncertainty gives a minimum detectable delta of ${minimumDetectableDelta.toFixed(3)}, above the remaining score headroom ${headroom.toFixed(3)}.${scorerNote}`
|
|
1132
|
+
};
|
|
1133
|
+
return {
|
|
1134
|
+
sufficient,
|
|
1135
|
+
minimumDetectableDelta,
|
|
1136
|
+
scaleAssumed,
|
|
1137
|
+
reason: `observed paired uncertainty gives a minimum detectable delta of ${minimumDetectableDelta.toFixed(3)} at ${options.confidence.toFixed(2)} confidence from ${n} runs.${scorerNote}`
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1105
1140
|
function finiteMeasurement(value, label) {
|
|
1106
1141
|
if (!Number.isFinite(value)) throw new Error(`${label} must be finite`);
|
|
1107
1142
|
return value;
|
|
@@ -1148,8 +1183,219 @@ function mean(values) {
|
|
|
1148
1183
|
if (values.length === 0) throw new Error("candidate experiment requires measured values");
|
|
1149
1184
|
return values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
1150
1185
|
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1186
|
+
//#endregion
|
|
1187
|
+
//#region src/contract/profile-measured-comparison.ts
|
|
1188
|
+
/** Content-address one held-out profile task before either state can execute it. */
|
|
1189
|
+
function sealAgentProfileImprovementTask(material) {
|
|
1190
|
+
return agentProfileImprovementTaskSchema.parse({
|
|
1191
|
+
...material,
|
|
1192
|
+
digest: canonicalCandidateDigest(material)
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
/** Freeze profile task order, repetitions, seeds, and the held-out split. */
|
|
1196
|
+
function sealAgentProfileImprovementSuite(options) {
|
|
1197
|
+
for (const task of options.tasks) verifyAgentProfileImprovementTask(task);
|
|
1198
|
+
const material = {
|
|
1199
|
+
kind: "agent-profile-improvement-suite",
|
|
1200
|
+
digestAlgorithm: "rfc8785-sha256",
|
|
1201
|
+
splitDigest: options.splitDigest,
|
|
1202
|
+
taskDigests: options.tasks.map((task) => task.digest),
|
|
1203
|
+
reps: options.reps,
|
|
1204
|
+
seeds: options.seeds
|
|
1205
|
+
};
|
|
1206
|
+
const suite = agentProfileImprovementSuiteSchema.parse({
|
|
1207
|
+
...material,
|
|
1208
|
+
digest: canonicalCandidateDigest(material)
|
|
1209
|
+
});
|
|
1210
|
+
return agentProfileImprovementSuiteInputsSchema.parse({
|
|
1211
|
+
suite,
|
|
1212
|
+
tasks: options.tasks
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
/** Freeze the two host-owned profile states and their exact held-out work. */
|
|
1216
|
+
function sealAgentProfileImprovementExperiment(material) {
|
|
1217
|
+
return verifyAgentProfileImprovementExperiment({
|
|
1218
|
+
...material,
|
|
1219
|
+
digest: canonicalCandidateDigest(material)
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
function verifyAgentProfileImprovementTask(input) {
|
|
1223
|
+
return agentProfileImprovementTaskSchema.parse(input);
|
|
1224
|
+
}
|
|
1225
|
+
function verifyAgentProfileImprovementSuiteInputs(input) {
|
|
1226
|
+
return agentProfileImprovementSuiteInputsSchema.parse(input);
|
|
1227
|
+
}
|
|
1228
|
+
function verifyAgentProfileImprovementExperiment(input) {
|
|
1229
|
+
return agentProfileImprovementExperimentSchema.parse(input);
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Execute each signed profile cell through the host's one exact-state executor.
|
|
1233
|
+
* Eval owns only the cell schedule and receipt checks; the host resolves each
|
|
1234
|
+
* state digest and captures its own run, billing, trace, and grader evidence.
|
|
1235
|
+
*/
|
|
1236
|
+
async function runAgentProfileImprovementExperiment(options) {
|
|
1237
|
+
const experiment = verifyAgentProfileImprovementExperiment(options.experiment);
|
|
1238
|
+
return (await mapPairedConcurrent({
|
|
1239
|
+
count: experiment.benchmark.suite.taskDigests.length * experiment.benchmark.suite.reps,
|
|
1240
|
+
maxConcurrency: options.maxConcurrency ?? 2,
|
|
1241
|
+
label: "profile improvement experiment",
|
|
1242
|
+
...options.signal ? { signal: options.signal } : {},
|
|
1243
|
+
map(index, arm, signal) {
|
|
1244
|
+
return options.execute(profileExecutionInput(experiment, arm, index, signal));
|
|
1245
|
+
}
|
|
1246
|
+
})).map((measurement, index) => verifyProfileMeasurement(experiment, measurement, index));
|
|
1247
|
+
}
|
|
1248
|
+
/** Build the only publishable profile comparison from complete host receipts. */
|
|
1249
|
+
function measuredComparisonFromAgentProfileImprovementExperiment(options) {
|
|
1250
|
+
const experiment = verifyAgentProfileImprovementExperiment(options.experiment);
|
|
1251
|
+
const measurements = options.measurements.map((measurement, index) => verifyProfileMeasurement(experiment, measurement, index));
|
|
1252
|
+
const expectedCount = experiment.benchmark.suite.taskDigests.length * experiment.benchmark.suite.reps;
|
|
1253
|
+
if (measurements.length !== expectedCount) throw new Error(`profile improvement experiment is incomplete (${measurements.length}/${expectedCount} paired cells)`);
|
|
1254
|
+
if (!options.runId.trim()) throw new Error("profile improvement experiment runId is required");
|
|
1255
|
+
const searchCostUsd = nonNegative(options.searchCostUsd ?? 0, "searchCostUsd");
|
|
1256
|
+
const searchDurationMs = nonNegative(options.searchDurationMs ?? 0, "searchDurationMs");
|
|
1257
|
+
const evaluation = evaluatePairedMeasurements({
|
|
1258
|
+
measurements: measurements.map((measurement, index) => ({
|
|
1259
|
+
cellId: profileCellId(experiment, index),
|
|
1260
|
+
...measurement
|
|
1261
|
+
})),
|
|
1262
|
+
policy: experiment.policy,
|
|
1263
|
+
adapter: profileReceiptAdapter,
|
|
1264
|
+
sharedScorerChannel: true,
|
|
1265
|
+
additionalCostUsd: searchCostUsd
|
|
1266
|
+
});
|
|
1267
|
+
const provisional = agentProfileImprovementMeasuredComparisonSchema.parse({
|
|
1268
|
+
kind: "agent-profile-improvement-measured-comparison",
|
|
1269
|
+
experiment,
|
|
1270
|
+
measurements,
|
|
1271
|
+
overall: evaluation.overall,
|
|
1272
|
+
objectives: evaluation.objectives,
|
|
1273
|
+
...options.candidate ? { candidate: options.candidate } : {},
|
|
1274
|
+
decision: evaluation.decision,
|
|
1275
|
+
power: evaluation.power,
|
|
1276
|
+
provenance: {
|
|
1277
|
+
kind: "agent-eval-loop",
|
|
1278
|
+
schema: "agent-profile-improvement-experiment",
|
|
1279
|
+
runId: options.runId,
|
|
1280
|
+
recordDigest: canonicalCandidateDigest({}),
|
|
1281
|
+
baselineContentHash: experiment.baseline.stateDigest,
|
|
1282
|
+
candidateContentHash: experiment.candidate.stateDigest
|
|
1283
|
+
},
|
|
1284
|
+
diff: canonicalCandidateJson(experiment.change),
|
|
1285
|
+
evaluation: {
|
|
1286
|
+
generationsExplored: options.generationsExplored ?? 0,
|
|
1287
|
+
searchDurationMs,
|
|
1288
|
+
executionDurationMs: evaluation.executionDurationMs,
|
|
1289
|
+
durationMs: evaluation.executionDurationMs + searchDurationMs,
|
|
1290
|
+
searchCostUsd,
|
|
1291
|
+
executionCostUsd: evaluation.executionCostUsd,
|
|
1292
|
+
totalCostUsd: evaluation.totalCostUsd
|
|
1293
|
+
},
|
|
1294
|
+
...options.metadata ? { metadata: options.metadata } : {}
|
|
1295
|
+
});
|
|
1296
|
+
const { recordDigest: _recordDigest, ...provenance } = provisional.provenance;
|
|
1297
|
+
return agentProfileImprovementMeasuredComparisonSchema.parse({
|
|
1298
|
+
...provisional,
|
|
1299
|
+
provenance: {
|
|
1300
|
+
...provenance,
|
|
1301
|
+
recordDigest: canonicalCandidateDigest({
|
|
1302
|
+
...provisional,
|
|
1303
|
+
provenance
|
|
1304
|
+
})
|
|
1305
|
+
}
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
/** Recompute a profile comparison from the exact sealed experiment and receipts. */
|
|
1309
|
+
function verifyAgentProfileImprovementExperimentComparison(input) {
|
|
1310
|
+
const comparison = agentProfileImprovementMeasuredComparisonSchema.parse(input);
|
|
1311
|
+
if (canonicalCandidateDigest(measuredComparisonFromAgentProfileImprovementExperiment({
|
|
1312
|
+
experiment: comparison.experiment,
|
|
1313
|
+
measurements: comparison.measurements,
|
|
1314
|
+
runId: comparison.provenance.runId,
|
|
1315
|
+
...comparison.candidate ? { candidate: comparison.candidate } : {},
|
|
1316
|
+
generationsExplored: comparison.evaluation.generationsExplored,
|
|
1317
|
+
searchDurationMs: comparison.evaluation.searchDurationMs,
|
|
1318
|
+
searchCostUsd: comparison.evaluation.searchCostUsd,
|
|
1319
|
+
...comparison.metadata ? { metadata: comparison.metadata } : {}
|
|
1320
|
+
})) !== canonicalCandidateDigest(comparison)) throw new Error("profile improvement comparison does not match its Runtime receipts");
|
|
1321
|
+
return comparison;
|
|
1322
|
+
}
|
|
1323
|
+
function profileExecutionInput(experiment, arm, index, signal) {
|
|
1324
|
+
const { task, taskIndex, repetition, seed } = profileCell(experiment, index);
|
|
1325
|
+
const stateDigest = experiment[arm].stateDigest;
|
|
1326
|
+
const runCellMaterial = {
|
|
1327
|
+
kind: "agent-profile-improvement-run-cell",
|
|
1328
|
+
experimentDigest: experiment.digest,
|
|
1329
|
+
arm,
|
|
1330
|
+
stateDigest,
|
|
1331
|
+
suiteDigest: experiment.benchmark.suite.digest,
|
|
1332
|
+
taskDigest: task.digest,
|
|
1333
|
+
taskIndex,
|
|
1334
|
+
repetition,
|
|
1335
|
+
seed,
|
|
1336
|
+
attempt: 1
|
|
1337
|
+
};
|
|
1338
|
+
return {
|
|
1339
|
+
experiment,
|
|
1340
|
+
arm,
|
|
1341
|
+
stateDigest,
|
|
1342
|
+
task,
|
|
1343
|
+
runCell: agentProfileImprovementRunCellSchema.parse({
|
|
1344
|
+
...runCellMaterial,
|
|
1345
|
+
digest: canonicalCandidateDigest(runCellMaterial)
|
|
1346
|
+
}),
|
|
1347
|
+
seed,
|
|
1348
|
+
...signal ? { signal } : {}
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
function verifyProfileMeasurement(experiment, input, index) {
|
|
1352
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) throw new Error(`profile improvement measurement ${index} must be an object`);
|
|
1353
|
+
const material = input;
|
|
1354
|
+
const expectedBaseline = profileExecutionInput(experiment, "baseline", index, void 0);
|
|
1355
|
+
const expectedCandidate = profileExecutionInput(experiment, "candidate", index, void 0);
|
|
1356
|
+
const baseline = agentProfileImprovementRunReceiptSchema.parse(material.baseline);
|
|
1357
|
+
const candidate = agentProfileImprovementRunReceiptSchema.parse(material.candidate);
|
|
1358
|
+
if (baseline.runCell.digest !== expectedBaseline.runCell.digest || candidate.runCell.digest !== expectedCandidate.runCell.digest) throw new Error(`profile improvement measurement ${index} substituted a measured arm`);
|
|
1359
|
+
verifyProfileReceiptTaskContract(baseline, expectedBaseline, index);
|
|
1360
|
+
verifyProfileReceiptTaskContract(candidate, expectedCandidate, index);
|
|
1361
|
+
if (baseline.executionId === candidate.executionId || baseline.digest === candidate.digest) throw new Error(`profile improvement measurement ${index} reused one execution across arms`);
|
|
1362
|
+
return {
|
|
1363
|
+
baseline,
|
|
1364
|
+
candidate
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
function verifyProfileReceiptTaskContract(receipt, expected, index) {
|
|
1368
|
+
const task = expected.task;
|
|
1369
|
+
if (canonicalCandidateDigest(receipt.resolvedModel) !== canonicalCandidateDigest(task.model) || canonicalCandidateDigest(receipt.limits) !== canonicalCandidateDigest(task.limits) || canonicalCandidateDigest(receipt.grading.grader) !== canonicalCandidateDigest(task.grader)) throw new Error(`profile improvement measurement ${index} substituted its ${expected.arm} task contract`);
|
|
1370
|
+
}
|
|
1371
|
+
function profileCell(experiment, index) {
|
|
1372
|
+
const { suite, tasks } = experiment.benchmark;
|
|
1373
|
+
const taskIndex = Math.floor(index / suite.reps);
|
|
1374
|
+
const repetition = index % suite.reps;
|
|
1375
|
+
const task = tasks[taskIndex];
|
|
1376
|
+
const seed = suite.seeds[index];
|
|
1377
|
+
if (!task || seed === void 0) throw new Error(`profile improvement experiment cell ${index} is outside the signed suite`);
|
|
1378
|
+
return {
|
|
1379
|
+
task,
|
|
1380
|
+
taskIndex,
|
|
1381
|
+
repetition,
|
|
1382
|
+
seed
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
function profileCellId(experiment, index) {
|
|
1386
|
+
return `${experiment.benchmark.suite.digest}:${index}`;
|
|
1387
|
+
}
|
|
1388
|
+
const profileReceiptAdapter = {
|
|
1389
|
+
score: (receipt) => receipt.grading.score,
|
|
1390
|
+
dimensions: (receipt) => receipt.grading.dimensions,
|
|
1391
|
+
costUsd: (receipt) => (receipt.usage.costUsdNanos + receipt.grading.usage.costUsdNanos) / 1e9,
|
|
1392
|
+
latencyMs: (receipt) => receipt.timing.durationMs + receipt.grading.timing.durationMs,
|
|
1393
|
+
completed: (receipt) => receipt.outcome.status === "succeeded",
|
|
1394
|
+
passed: (receipt) => receipt.grading.passed
|
|
1395
|
+
};
|
|
1396
|
+
function nonNegative(value, label) {
|
|
1397
|
+
if (!Number.isFinite(value) || value < 0) throw new Error(`${label} must be a non-negative number`);
|
|
1398
|
+
return value;
|
|
1153
1399
|
}
|
|
1154
1400
|
//#endregion
|
|
1155
1401
|
//#region src/contract/intake/run-record-dir.ts
|
|
@@ -1885,6 +2131,6 @@ function collectNumericAttrs(spans) {
|
|
|
1885
2131
|
return raw;
|
|
1886
2132
|
}
|
|
1887
2133
|
//#endregion
|
|
1888
|
-
export { FileSystemOutcomeStore, InMemoryOutcomeStore, REFERENCE_EQUIVALENCE_INPUT_LIMITS, REFERENCE_EQUIVALENCE_JUDGE_VERSION, SelfImproveRunError, analyzeRuns, buildDefaultAnalystRegistry, buildEvidenceVector, campaignSplitDigest, compareOptimizationMethods, composeGate, createChatClient, createReferenceEquivalenceJudge, defaultProductionGate, defineAgentEval, diffGenerations, diffRunBaselineToWinner, diffRuns, evalReportingSuite, evaluatePairedMeasurements, externalTextOptimizationMethod, fromClaudeCodeSession, fromCodexSession, fromFeedbackTable, fromKimiCodeSession, fromOpenCodeSession, fromOtelSpans, fromPiSession, fromPigraphSession, fromRunRecordDir, fsCampaignStorage, gepaOptimizationMethod, heldOutGate, inMemoryCampaignStorage, llmJudge, measuredComparisonFromCandidateExperiment, observeCodeAgentSession, paretoPolicy, paretoSignificanceGate, parseAgentTrace, parseCodeAgentJsonl, partitionRunsByAuthoringModel, runCampaign, runCandidateExperiment, runEval, runImprovementLoop, runReferenceEquivalenceJudge, sealCandidateBenchmarkSuite, sealCandidateBenchmarkTask, sealCandidateExperiment, selfImprove, skillOptOptimizationMethod, summarizeExecution, verifyCandidateBenchmarkSuite, verifyCandidateBenchmarkSuiteInputs, verifyCandidateBenchmarkTask, verifyCandidateExperiment, verifyCandidateExperimentComparison };
|
|
2134
|
+
export { FileSystemOutcomeStore, InMemoryOutcomeStore, REFERENCE_EQUIVALENCE_INPUT_LIMITS, REFERENCE_EQUIVALENCE_JUDGE_VERSION, SelfImproveRunError, analyzeRuns, buildDefaultAnalystRegistry, buildEvidenceVector, campaignSplitDigest, compareOptimizationMethods, composeGate, createChatClient, createReferenceEquivalenceJudge, defaultProductionGate, defineAgentEval, diffGenerations, diffRunBaselineToWinner, diffRuns, evalReportingSuite, evaluatePairedMeasurements, externalTextOptimizationMethod, fromClaudeCodeSession, fromCodexSession, fromFeedbackTable, fromKimiCodeSession, fromOpenCodeSession, fromOtelSpans, fromPiSession, fromPigraphSession, fromRunRecordDir, fsCampaignStorage, gepaOptimizationMethod, heldOutGate, inMemoryCampaignStorage, llmJudge, measuredComparisonFromAgentProfileImprovementExperiment, measuredComparisonFromCandidateExperiment, observeCodeAgentSession, paretoPolicy, paretoSignificanceGate, parseAgentTrace, parseCodeAgentJsonl, partitionRunsByAuthoringModel, runAgentProfileImprovementExperiment, runCampaign, runCandidateExperiment, runEval, runImprovementLoop, runReferenceEquivalenceJudge, sealAgentProfileImprovementExperiment, sealAgentProfileImprovementSuite, sealAgentProfileImprovementTask, sealCandidateBenchmarkSuite, sealCandidateBenchmarkTask, sealCandidateExperiment, selfImprove, skillOptOptimizationMethod, summarizeExecution, verifyAgentProfileImprovementExperiment, verifyAgentProfileImprovementExperimentComparison, verifyAgentProfileImprovementSuiteInputs, verifyAgentProfileImprovementTask, verifyCandidateBenchmarkSuite, verifyCandidateBenchmarkSuiteInputs, verifyCandidateBenchmarkTask, verifyCandidateExperiment, verifyCandidateExperimentComparison };
|
|
1889
2135
|
|
|
1890
2136
|
//# sourceMappingURL=index.js.map
|