@tangle-network/agent-runtime 0.106.1 → 0.107.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/README.md +2 -2
- package/dist/{activation-CRjVfOiy.js → activation-Ck5ksFWg.js} +5 -4
- package/dist/{activation-CRjVfOiy.js.map → activation-Ck5ksFWg.js.map} +1 -1
- package/dist/agent.d.ts +2 -2
- package/dist/{analyst-loop-DGdtVENg.js → analyst-loop-C8cGThTW.js} +12 -4
- package/dist/{analyst-loop-DGdtVENg.js.map → analyst-loop-C8cGThTW.js.map} +1 -1
- package/dist/analyst-loop.d.ts +1 -1
- package/dist/analyst-loop.js +1 -1
- package/dist/candidate-execution/index.js +4 -4
- package/dist/{candidate-execution-DqMbv1rU.js → candidate-execution-BUpR0mSD.js} +4 -4
- package/dist/{candidate-execution-DqMbv1rU.js.map → candidate-execution-BUpR0mSD.js.map} +1 -1
- package/dist/{improvement-adapter-Cr5TBSji.d.ts → improvement-adapter-BaAdfJKT.d.ts} +2 -2
- package/dist/{improvement-cycle-C095kS_g.js → improvement-cycle-Ulvvbg5p.js} +367 -34
- package/dist/improvement-cycle-Ulvvbg5p.js.map +1 -0
- package/dist/{index-DruSKs3Z.d.ts → index-CeawCSEg.d.ts} +2 -2
- package/dist/{index-BGdxAwfO.d.ts → index-D6MwUzvB.d.ts} +7 -7
- package/dist/{index-CbNM40xG.d.ts → index-jmFVBIHo.d.ts} +2 -2
- package/dist/index.d.ts +6 -6
- package/dist/index.js +7 -7
- package/dist/intelligence.d.ts +145 -66
- package/dist/intelligence.js +5 -5
- package/dist/intelligence.js.map +1 -1
- package/dist/{knowledge-Ku-mPP4f.js → knowledge-Dizh_AtL.js} +4 -4
- package/dist/{knowledge-Ku-mPP4f.js.map → knowledge-Dizh_AtL.js.map} +1 -1
- package/dist/knowledge.d.ts +1 -1
- package/dist/knowledge.js +1 -1
- package/dist/{loop-runner-bin-BXsFEUcf.d.ts → loop-runner-bin-BbYG9CeA.d.ts} +3 -3
- package/dist/{loop-runner-bin-CRagyuNb.js → loop-runner-bin-CvdKZkE4.js} +2 -2
- package/dist/{loop-runner-bin-CRagyuNb.js.map → loop-runner-bin-CvdKZkE4.js.map} +1 -1
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/loops.d.ts +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/{prepare-B53sPV7M.js → prepare-_WTTffkz.js} +25 -8
- package/dist/prepare-_WTTffkz.js.map +1 -0
- package/dist/primeintellect/index.d.ts +1 -1
- package/dist/{protected-model-port-BLPH5VVv.js → protected-model-port-ZUwVuftA.js} +2 -2
- package/dist/{protected-model-port-BLPH5VVv.js.map → protected-model-port-ZUwVuftA.js.map} +1 -1
- package/dist/{redact-kbIOjfjM.d.ts → redact-C5xOm8cu.d.ts} +23 -3
- package/dist/testing.js +222 -194
- package/dist/testing.js.map +1 -1
- package/dist/{types-Cja5OTGh.d.ts → types-CfGKhIuj.d.ts} +10 -2
- package/dist/{workspace-archive-BosQiotA.js → workspace-archive-CIG1VNCj.js} +2 -2
- package/dist/{workspace-archive-BosQiotA.js.map → workspace-archive-CIG1VNCj.js.map} +1 -1
- package/package.json +6 -6
- package/dist/improvement-cycle-C095kS_g.js.map +0 -1
- package/dist/prepare-B53sPV7M.js.map +0 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { i as ConfigError } from "./errors-DEAvWQPy.js";
|
|
2
|
-
import { $ as parseExactAgentProfile, G as agentCandidateProfileAsAgentProfile, J as candidateMaterializerHarness, Q as parseAgentCandidateProfileActivation, Y as createAgentCandidateProfileActivation, Z as omitUndefinedObjectFields, ct as omitTopLevelDigest, d as verifiedResourceTextByDigest, f as verifyAgentCandidateBundle, it as canonicalCandidateDocument, n as executePreparedAgentCandidate, nt as canonicalCandidateBytes, q as assertCandidateProfileBinding, rt as canonicalCandidateDigest$1, st as immutableCandidateValue, t as prepareAgentCandidateExecution, ut as verifyCanonicalCandidateDocument } from "./prepare-
|
|
2
|
+
import { $ as parseExactAgentProfile, G as agentCandidateProfileAsAgentProfile, J as candidateMaterializerHarness, K as applyExactAgentProfileDiff, Q as parseAgentCandidateProfileActivation, Y as createAgentCandidateProfileActivation, Z as omitUndefinedObjectFields, ct as omitTopLevelDigest, d as verifiedResourceTextByDigest, f as verifyAgentCandidateBundle, it as canonicalCandidateDocument, n as executePreparedAgentCandidate, nt as canonicalCandidateBytes, q as assertCandidateProfileBinding, rt as canonicalCandidateDigest$1, st as immutableCandidateValue, t as prepareAgentCandidateExecution, ut as verifyCanonicalCandidateDocument } from "./prepare-_WTTffkz.js";
|
|
3
3
|
import { N as runLocalHarness, T as runSettledCommand, j as harnessInvocation } from "./supervisor-DTKhF-RV.js";
|
|
4
4
|
import { E as optimizerMethod, a as defaultStructuralRolloutPolicy } from "./structural-rollout-IXUEplky.js";
|
|
5
|
-
import { t as runAnalystLoop } from "./analyst-loop-
|
|
6
|
-
import { canonicalJson, makeFinding } from "@tangle-network/agent-eval";
|
|
7
|
-
import {
|
|
8
|
-
import { agentCandidateMaterializationReceiptSchema, agentCandidateRunReceiptSchema, agentImprovementActivationSchema, agentImprovementProposalSchema, agentImprovementReviewSchema, agentProfileDiffSchema, agentProfileImprovementMeasuredComparisonSchema, agentProfileModelHintsSchema, agentProfileSchema, candidateExecutionEvidenceSchema, changedProfileImprovementSurfaces, defineAgentProfileDiff, sha256DigestSchema } from "@tangle-network/agent-interface";
|
|
5
|
+
import { t as runAnalystLoop } from "./analyst-loop-C8cGThTW.js";
|
|
6
|
+
import { CostLedger, canonicalJson, makeFinding } from "@tangle-network/agent-eval";
|
|
7
|
+
import { campaignScenarioIdentity, campaignSplitDigestFromIdentities, compareOptimizationMethods, gitWorktreeAdapter, verifyCodeSurface } from "@tangle-network/agent-eval/campaign";
|
|
8
|
+
import { AGENT_IMPROVEMENT_SOURCE_METADATA_KEY, agentCandidateMaterializationReceiptSchema, agentCandidateRunReceiptSchema, agentImprovementActivationSchema, agentImprovementProposalSchema, agentImprovementReviewSchema, agentImprovementSourceMetadata, agentImprovementSourceSchema, agentProfileDiffSchema, agentProfileImprovementArmSchema, agentProfileImprovementExecutionRefSchema, agentProfileImprovementMeasuredComparisonSchema, agentProfileModelHintsSchema, agentProfileSchema, candidateExecutionEvidenceSchema, changedProfileImprovementSurfaces, defineAgentProfileDiff, numbersApproximatelyEqual, sha256DigestSchema } from "@tangle-network/agent-interface";
|
|
9
9
|
import { createHash, randomUUID } from "node:crypto";
|
|
10
10
|
import { applyWorkspacePlan, materializeCandidateProfile, materializeProfile } from "@tangle-network/agent-profile-materialize";
|
|
11
11
|
import { existsSync, readFileSync, readdirSync, rmSync } from "node:fs";
|
|
12
12
|
import { basename, join, resolve, sep } from "node:path";
|
|
13
13
|
import { spawnSync } from "node:child_process";
|
|
14
|
-
import { measuredComparisonFromCandidateExperiment, runCandidateExperiment, sealCandidateExperiment, selfImprove, verifyCandidateExperiment, verifyCandidateExperimentComparison } from "@tangle-network/agent-eval/contract";
|
|
14
|
+
import { measuredComparisonFromAgentProfileImprovementExperiment, measuredComparisonFromCandidateExperiment, runAgentProfileImprovementExperiment, runCandidateExperiment, sealAgentProfileImprovementExperiment, sealAgentProfileImprovementSuite, sealAgentProfileImprovementTask, sealCandidateExperiment, selfImprove, verifyAgentProfileImprovementExperimentComparison, verifyCandidateExperiment, verifyCandidateExperimentComparison } from "@tangle-network/agent-eval/contract";
|
|
15
15
|
import { assertNoJudgeVerdict } from "@tangle-network/agent-eval/analyst";
|
|
16
16
|
//#region src/improvement/agentic-generator.ts
|
|
17
17
|
/**
|
|
@@ -1667,10 +1667,19 @@ function exceeds(value, limit) {
|
|
|
1667
1667
|
//#region src/improvement/method-identity.ts
|
|
1668
1668
|
function buildMethodEvaluationIdentity(input) {
|
|
1669
1669
|
const optimizationReps = input.optimizationRunOptions?.reps ?? 1;
|
|
1670
|
+
const finalTestReps = input.reps ?? 1;
|
|
1671
|
+
const scenarioPartitions = immutableCandidateValue({
|
|
1672
|
+
train: input.trainScenarios.map(campaignScenarioIdentity),
|
|
1673
|
+
selection: input.selectionScenarios.map(campaignScenarioIdentity),
|
|
1674
|
+
finalTest: input.testScenarios.map(campaignScenarioIdentity),
|
|
1675
|
+
optimizationReps,
|
|
1676
|
+
finalTestReps
|
|
1677
|
+
});
|
|
1670
1678
|
const developmentSplitDigest = canonicalCandidateDigest$1({
|
|
1671
|
-
train:
|
|
1672
|
-
selection:
|
|
1679
|
+
train: campaignSplitDigestFromIdentities(scenarioPartitions.train, optimizationReps),
|
|
1680
|
+
selection: campaignSplitDigestFromIdentities(scenarioPartitions.selection, optimizationReps)
|
|
1673
1681
|
});
|
|
1682
|
+
const finalTestSplitDigest = campaignSplitDigestFromIdentities(scenarioPartitions.finalTest, finalTestReps);
|
|
1674
1683
|
const judgeDescriptors = input.judges.map(judgeDescriptor);
|
|
1675
1684
|
return {
|
|
1676
1685
|
evaluationRef: canonicalCandidateDigest$1({
|
|
@@ -1679,6 +1688,7 @@ function buildMethodEvaluationIdentity(input) {
|
|
|
1679
1688
|
coordinate: profileCoordinate(input.surface, input.baselineSurface, input.skills),
|
|
1680
1689
|
candidateValidation: input.validateCandidate ? Function.prototype.toString.call(input.validateCandidate) : null,
|
|
1681
1690
|
developmentSplitDigest,
|
|
1691
|
+
finalTestSplitDigest,
|
|
1682
1692
|
findings: input.findings,
|
|
1683
1693
|
judges: judgeDescriptors,
|
|
1684
1694
|
run: {
|
|
@@ -1698,6 +1708,8 @@ function buildMethodEvaluationIdentity(input) {
|
|
|
1698
1708
|
}
|
|
1699
1709
|
}),
|
|
1700
1710
|
developmentSplitDigest,
|
|
1711
|
+
finalTestSplitDigest,
|
|
1712
|
+
scenarioPartitions,
|
|
1701
1713
|
judgeDescriptors
|
|
1702
1714
|
};
|
|
1703
1715
|
}
|
|
@@ -1752,13 +1764,14 @@ async function runMethodImprovement(profile, opts) {
|
|
|
1752
1764
|
findings,
|
|
1753
1765
|
trainScenarios: comparisonOptions.trainScenarios,
|
|
1754
1766
|
selectionScenarios: comparisonOptions.selectionScenarios,
|
|
1767
|
+
testScenarios: comparisonOptions.testScenarios,
|
|
1755
1768
|
judges: comparisonOptions.judges,
|
|
1756
1769
|
seed: comparisonOptions.seed,
|
|
1757
1770
|
reps: comparisonOptions.reps,
|
|
1758
1771
|
costCeiling: comparisonOptions.costCeiling,
|
|
1759
1772
|
optimizationRunOptions
|
|
1760
1773
|
});
|
|
1761
|
-
const { evaluationRef, developmentSplitDigest } = identity;
|
|
1774
|
+
const { evaluationRef, developmentSplitDigest, finalTestSplitDigest, scenarioPartitions } = identity;
|
|
1762
1775
|
const dispatchRef = `improve:${evaluationRef}`;
|
|
1763
1776
|
const identifiedJudges = comparisonOptions.judges.map((judge, index) => Object.freeze({
|
|
1764
1777
|
...judge,
|
|
@@ -1852,6 +1865,8 @@ async function runMethodImprovement(profile, opts) {
|
|
|
1852
1865
|
invocationId: runtimeInvocationId,
|
|
1853
1866
|
runId: score.provenance?.runId ?? runtimeInvocationId,
|
|
1854
1867
|
developmentSplitDigest,
|
|
1868
|
+
finalTestSplitDigest,
|
|
1869
|
+
scenarioPartitions,
|
|
1855
1870
|
executionRef,
|
|
1856
1871
|
baselineProfileDigest
|
|
1857
1872
|
}),
|
|
@@ -1895,6 +1910,11 @@ const AGENT_IMPROVEMENT_PROFILE_SURFACES = [
|
|
|
1895
1910
|
"hooks",
|
|
1896
1911
|
"subagents"
|
|
1897
1912
|
];
|
|
1913
|
+
/**
|
|
1914
|
+
* Portable profile surfaces eligible for shared measured comparisons.
|
|
1915
|
+
* Other profile settings can contain credentials or executable configuration.
|
|
1916
|
+
*/
|
|
1917
|
+
const AGENT_PROFILE_MEASURED_SURFACES = ["prompt", "skills"];
|
|
1898
1918
|
function deriveChangedSurfaces(baselineBundle, candidateBundle) {
|
|
1899
1919
|
if (baselineBundle.knowledge || candidateBundle.knowledge) assertKnowledgeCandidatePair(baselineBundle, candidateBundle);
|
|
1900
1920
|
assertCodeCandidatePair(baselineBundle, candidateBundle);
|
|
@@ -1932,7 +1952,7 @@ function agentProfileImprovementStateDigest(experiment, arm) {
|
|
|
1932
1952
|
/** Map Interface's current profile-improvement contract to Runtime-deliverable surfaces. */
|
|
1933
1953
|
function profileImprovementChangedSurfaces(change) {
|
|
1934
1954
|
const surfaces = changedProfileImprovementSurfaces(change);
|
|
1935
|
-
if (surfaces.length === 0 || !surfaces.every((surface) => surface
|
|
1955
|
+
if (surfaces.length === 0 || !surfaces.every((surface) => isAgentProfileMeasuredSurface(surface))) throw new Error("profile improvement experiment does not change a supported surface");
|
|
1936
1956
|
return surfaces;
|
|
1937
1957
|
}
|
|
1938
1958
|
function agentImprovementTargetDigest(experiment, arm, surface) {
|
|
@@ -1971,6 +1991,10 @@ function sameAgentImprovementSurfaceSet(left, right) {
|
|
|
1971
1991
|
function isAgentImprovementProfileSurface(surface) {
|
|
1972
1992
|
return AGENT_IMPROVEMENT_PROFILE_SURFACES.includes(surface);
|
|
1973
1993
|
}
|
|
1994
|
+
/** Return whether a surface is eligible for shared profile measurement. */
|
|
1995
|
+
function isAgentProfileMeasuredSurface(surface) {
|
|
1996
|
+
return AGENT_PROFILE_MEASURED_SURFACES.includes(surface);
|
|
1997
|
+
}
|
|
1974
1998
|
/**
|
|
1975
1999
|
* Return the canonical current-state input for one profile-deliverable improvement target.
|
|
1976
2000
|
* Missing slots become `null`; tools and subagents include both their direct and resource slots.
|
|
@@ -2029,6 +2053,22 @@ function agentImprovementTargetProfileDiffs(target, options) {
|
|
|
2029
2053
|
set
|
|
2030
2054
|
}))];
|
|
2031
2055
|
}
|
|
2056
|
+
/**
|
|
2057
|
+
* Derive the ordered profile patch that changes one executable profile into
|
|
2058
|
+
* another, then prove the patch preserves the complete candidate state.
|
|
2059
|
+
*/
|
|
2060
|
+
function agentImprovementProfileDiffs(baselineInput, candidateInput, options) {
|
|
2061
|
+
const baseline = parseExactAgentProfile(omitUndefinedObjectFields(baselineInput, "profile improvement baseline"), "profile improvement baseline");
|
|
2062
|
+
const candidate = parseExactAgentProfile(omitUndefinedObjectFields(candidateInput, "profile improvement candidate"), "profile improvement candidate");
|
|
2063
|
+
const surfaces = AGENT_PROFILE_MEASURED_SURFACES.filter((surface) => agentImprovementProfileSurfaceDigest(baseline, surface) !== agentImprovementProfileSurfaceDigest(candidate, surface));
|
|
2064
|
+
if (surfaces.length === 0) throw new Error("profile improvement candidate does not change a deliverable profile surface");
|
|
2065
|
+
const changes = surfaces.flatMap((surface) => agentImprovementTargetProfileDiffs({
|
|
2066
|
+
surface,
|
|
2067
|
+
desiredInput: agentImprovementProfileSurfaceInput(candidate, surface)
|
|
2068
|
+
}, options));
|
|
2069
|
+
if (canonicalCandidateDigest$1(changes.reduce((profile, change) => applyExactAgentProfileDiff(profile, change, "profile improvement candidate change"), baseline)) !== canonicalCandidateDigest$1(candidate)) throw new Error("profile improvement candidate changes fields that the measured profile contract cannot apply");
|
|
2070
|
+
return changes;
|
|
2071
|
+
}
|
|
2032
2072
|
function improvementSurfaceReplacement(target) {
|
|
2033
2073
|
const value = target.desiredInput;
|
|
2034
2074
|
switch (target.surface) {
|
|
@@ -2163,6 +2203,8 @@ const optimizationReceiptMetadataKey = "optimizationReceipt";
|
|
|
2163
2203
|
function createOptimizationActivationReceipt(improvement) {
|
|
2164
2204
|
const provenance = improvement.provenance;
|
|
2165
2205
|
if (!provenance) return void 0;
|
|
2206
|
+
const finalTestDataDigest = improvement.lineage.finalTestSplitDigest;
|
|
2207
|
+
if (!finalTestDataDigest) throw new Error("method improvement does not retain its final-test split digest");
|
|
2166
2208
|
const optimizerModel = provenance.optimizerModel;
|
|
2167
2209
|
const candidateModel = improvement.candidate.profile.model;
|
|
2168
2210
|
return canonicalCandidateDocument({
|
|
@@ -2192,7 +2234,9 @@ function createOptimizationActivationReceipt(improvement) {
|
|
|
2192
2234
|
resumed: provenance.resumed,
|
|
2193
2235
|
artifactDir: provenance.artifactDir
|
|
2194
2236
|
},
|
|
2195
|
-
developmentDataDigest: improvement.lineage.developmentSplitDigest
|
|
2237
|
+
developmentDataDigest: improvement.lineage.developmentSplitDigest,
|
|
2238
|
+
finalTestDataDigest,
|
|
2239
|
+
scenarioPartitions: improvement.lineage.scenarioPartitions
|
|
2196
2240
|
}).value;
|
|
2197
2241
|
}
|
|
2198
2242
|
/** Add Runtime-owned optimizer evidence without aliasing caller metadata. */
|
|
@@ -2214,11 +2258,32 @@ function optimizationActivationReceiptFromMetadata(metadata) {
|
|
|
2214
2258
|
}
|
|
2215
2259
|
function parseOptimizationActivationReceipt(value) {
|
|
2216
2260
|
if (!isRecord(value) || value.kind !== "optimization-activation-receipt") throw new Error("optimization receipt must be an optimization-activation-receipt");
|
|
2217
|
-
if (!isNonEmptyString(value.method) || !isPackageSource(value.source) || value.bridge !== void 0 && !isPackageSource(value.bridge) || !isModules(value.modules) || !isPythonRuntime(value.python) || !isModels(value.models) || !isUsage(value.usage) || !isCost(value.cost) || !isInvocation(value.invocation) || !isSha256Digest(value.developmentDataDigest) || !isSha256Digest(value.digest)) throw new Error("optimization receipt contains invalid evidence");
|
|
2261
|
+
if (!isNonEmptyString(value.method) || !isPackageSource(value.source) || value.bridge !== void 0 && !isPackageSource(value.bridge) || !isModules(value.modules) || !isPythonRuntime(value.python) || !isModels(value.models) || !isUsage(value.usage) || !isCost(value.cost) || !isInvocation(value.invocation) || !isSha256Digest(value.developmentDataDigest) || !isSha256Digest(value.finalTestDataDigest) || !isScenarioPartitions(value.scenarioPartitions) || !isSha256Digest(value.digest)) throw new Error("optimization receipt contains invalid evidence");
|
|
2218
2262
|
const receipt = value;
|
|
2263
|
+
if (!hasMatchingScenarioPartitionDigests(receipt)) throw new Error("optimization receipt task identities do not match its split digests");
|
|
2219
2264
|
if (canonicalCandidateDigest$1(omitTopLevelDigest(receipt)) !== receipt.digest) throw new Error("optimization receipt digest does not match its evidence");
|
|
2220
2265
|
return receipt;
|
|
2221
2266
|
}
|
|
2267
|
+
function isScenarioPartitions(value) {
|
|
2268
|
+
if (!isRecord(value)) return false;
|
|
2269
|
+
return isScenarioIdentityList(value.train) && isScenarioIdentityList(value.selection) && isScenarioIdentityList(value.finalTest) && isPositiveSafeInteger(value.optimizationReps) && isPositiveSafeInteger(value.finalTestReps);
|
|
2270
|
+
}
|
|
2271
|
+
function isScenarioIdentityList(value) {
|
|
2272
|
+
return Array.isArray(value) && value.every((scenario) => isRecord(scenario) && isNonEmptyString(scenario.id) && isNonEmptyString(scenario.kind) && isSha256Digest(scenario.scenarioDigest));
|
|
2273
|
+
}
|
|
2274
|
+
function hasMatchingScenarioPartitionDigests(receipt) {
|
|
2275
|
+
try {
|
|
2276
|
+
const { scenarioPartitions } = receipt;
|
|
2277
|
+
const developmentDataDigest = canonicalCandidateDigest$1({
|
|
2278
|
+
train: campaignSplitDigestFromIdentities(scenarioPartitions.train, scenarioPartitions.optimizationReps),
|
|
2279
|
+
selection: campaignSplitDigestFromIdentities(scenarioPartitions.selection, scenarioPartitions.optimizationReps)
|
|
2280
|
+
});
|
|
2281
|
+
const finalTestDataDigest = campaignSplitDigestFromIdentities(scenarioPartitions.finalTest, scenarioPartitions.finalTestReps);
|
|
2282
|
+
return receipt.developmentDataDigest === developmentDataDigest && receipt.finalTestDataDigest === finalTestDataDigest;
|
|
2283
|
+
} catch {
|
|
2284
|
+
return false;
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2222
2287
|
function isPackageSource(value) {
|
|
2223
2288
|
if (!isRecord(value) || value.kind !== "package" || value.evidence !== "observed" && value.evidence !== "declared" || !isNonEmptyString(value.package) || !isNonEmptyString(value.version)) return false;
|
|
2224
2289
|
return isOptionalNonEmptyString(value.sourceUrl) && isOptionalNonEmptyString(value.revision) && (value.sourceSha256 === void 0 || typeof value.sourceSha256 === "string" && /^[0-9a-f]{64}$/.test(value.sourceSha256));
|
|
@@ -2284,6 +2349,9 @@ function isOptionalNonEmptyString(value) {
|
|
|
2284
2349
|
function isNonNegativeInteger(value) {
|
|
2285
2350
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
2286
2351
|
}
|
|
2352
|
+
function isPositiveSafeInteger(value) {
|
|
2353
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
2354
|
+
}
|
|
2287
2355
|
function isOptionalNonNegativeInteger(value) {
|
|
2288
2356
|
return value === void 0 || isNonNegativeInteger(value);
|
|
2289
2357
|
}
|
|
@@ -2309,10 +2377,12 @@ function sealAgentImprovementExperiment(material, improvement) {
|
|
|
2309
2377
|
runIds: [improvement.lineage.runId],
|
|
2310
2378
|
developmentSplitDigest: improvement.lineage.developmentSplitDigest
|
|
2311
2379
|
};
|
|
2312
|
-
|
|
2380
|
+
const experiment = sealCandidateExperiment({
|
|
2313
2381
|
...material,
|
|
2314
2382
|
candidateLineage
|
|
2315
2383
|
});
|
|
2384
|
+
assertCandidateReleaseWorkIsFresh(experiment, improvement);
|
|
2385
|
+
return experiment;
|
|
2316
2386
|
}
|
|
2317
2387
|
function assertRuntimeOwnedExperimentFieldsAbsent(material) {
|
|
2318
2388
|
if (material === null || typeof material !== "object" || Array.isArray(material)) throw new Error("agent improvement experiment material must be an object");
|
|
@@ -2322,9 +2392,18 @@ function assertRuntimeOwnedExperimentFieldsAbsent(material) {
|
|
|
2322
2392
|
/** Execute both arms of one immutable experiment and derive its paired result. */
|
|
2323
2393
|
async function runAgentCandidateExperiment(options) {
|
|
2324
2394
|
const experiment = verifyCandidateExperiment(options.experiment);
|
|
2325
|
-
const
|
|
2395
|
+
const preparation = options.preparation ?? {
|
|
2396
|
+
wallDurationMs: 0,
|
|
2397
|
+
cost: {
|
|
2398
|
+
usd: 0,
|
|
2399
|
+
provenance: "observed"
|
|
2400
|
+
}
|
|
2401
|
+
};
|
|
2402
|
+
const costLedger = options.costLedger ?? (experiment.policy.budgetUsd === void 0 ? void 0 : new CostLedger({ costCeilingUsd: experiment.policy.budgetUsd }));
|
|
2403
|
+
const run = await runCandidateExperiment({
|
|
2326
2404
|
experiment,
|
|
2327
2405
|
...options.maxConcurrency === void 0 ? {} : { maxConcurrency: options.maxConcurrency },
|
|
2406
|
+
...costLedger ? { costLedger } : {},
|
|
2328
2407
|
...options.signal ? { signal: options.signal } : {},
|
|
2329
2408
|
execute: async (input) => {
|
|
2330
2409
|
const placement = await options.placeCell(input);
|
|
@@ -2334,19 +2413,20 @@ async function runAgentCandidateExperiment(options) {
|
|
|
2334
2413
|
});
|
|
2335
2414
|
}
|
|
2336
2415
|
});
|
|
2416
|
+
const evaluation = createAgentImprovementMeasuredComparison({
|
|
2417
|
+
experiment,
|
|
2418
|
+
measurements: run.measurements,
|
|
2419
|
+
preparation,
|
|
2420
|
+
measurement: run.measurement,
|
|
2421
|
+
runId: options.runId,
|
|
2422
|
+
...options.candidate ? { candidate: options.candidate } : {},
|
|
2423
|
+
...options.generationsExplored === void 0 ? {} : { generationsExplored: options.generationsExplored },
|
|
2424
|
+
...options.metadata ? { metadata: options.metadata } : {}
|
|
2425
|
+
});
|
|
2337
2426
|
return {
|
|
2338
2427
|
experiment,
|
|
2339
|
-
measurements,
|
|
2340
|
-
evaluation
|
|
2341
|
-
experiment,
|
|
2342
|
-
measurements,
|
|
2343
|
-
runId: options.runId,
|
|
2344
|
-
...options.candidate ? { candidate: options.candidate } : {},
|
|
2345
|
-
...options.generationsExplored === void 0 ? {} : { generationsExplored: options.generationsExplored },
|
|
2346
|
-
...options.searchDurationMs === void 0 ? {} : { searchDurationMs: options.searchDurationMs },
|
|
2347
|
-
...options.searchCostUsd === void 0 ? {} : { searchCostUsd: options.searchCostUsd },
|
|
2348
|
-
...options.metadata ? { metadata: options.metadata } : {}
|
|
2349
|
-
})
|
|
2428
|
+
measurements: run.measurements,
|
|
2429
|
+
evaluation
|
|
2350
2430
|
};
|
|
2351
2431
|
}
|
|
2352
2432
|
/** Execute one exact arm, task, repetition, seed, and attempt through Runtime. */
|
|
@@ -2397,14 +2477,246 @@ async function executeAgentCandidateExperimentCell(options) {
|
|
|
2397
2477
|
function createAgentImprovementMeasuredComparison(options) {
|
|
2398
2478
|
return verifyCandidateExperimentComparison(measuredComparisonFromCandidateExperiment(options));
|
|
2399
2479
|
}
|
|
2480
|
+
async function analyzeAgentImprovement(runId, options, costLedger, signal) {
|
|
2481
|
+
const rawOptions = options;
|
|
2482
|
+
if (rawOptions.knowledgeProposalSource !== void 0 || rawOptions.improvementProposalSource !== void 0) throw new Error("measured agent improvement analysis must not run proposal sources");
|
|
2483
|
+
if (rawOptions.onEvent !== void 0 || rawOptions.log !== void 0) throw new Error("measured agent improvement analysis must not run callbacks");
|
|
2484
|
+
const analysis = await runAnalystLoop({
|
|
2485
|
+
...options,
|
|
2486
|
+
runId,
|
|
2487
|
+
...costLedger ? {
|
|
2488
|
+
costLedger,
|
|
2489
|
+
costPhase: "profile-improvement-analysis"
|
|
2490
|
+
} : {},
|
|
2491
|
+
...signal ? { signal } : {}
|
|
2492
|
+
});
|
|
2493
|
+
if (costLedger) assertAnalysisCostRecorded(analysis, costLedger);
|
|
2494
|
+
return {
|
|
2495
|
+
analysis,
|
|
2496
|
+
findings: [...assertNoJudgeVerdict(analysis.analystResult.findings, "agent improvement findings")]
|
|
2497
|
+
};
|
|
2498
|
+
}
|
|
2499
|
+
function completeAnalysisAccounting(analysis) {
|
|
2500
|
+
const analysisCost = analysis.analystResult.total_cost_provenance;
|
|
2501
|
+
if (!analysisCost || analysisCost.kind === "uncaptured") throw new Error("agent improvement analysis cost is uncaptured");
|
|
2502
|
+
if (!Number.isFinite(analysis.analystResult.total_cost_usd) || analysis.analystResult.total_cost_usd < 0) throw new Error("agent improvement analysis cost must be finite and non-negative");
|
|
2503
|
+
if (analysisCost.usd !== analysis.analystResult.total_cost_usd) throw new Error("agent improvement analysis cost does not match its provenance");
|
|
2504
|
+
if (!Number.isFinite(analysis.durationMs) || analysis.durationMs < 0) throw new Error("agent improvement analysis duration must be finite and non-negative");
|
|
2505
|
+
return {
|
|
2506
|
+
costUsd: analysis.analystResult.total_cost_usd,
|
|
2507
|
+
durationMs: analysis.durationMs
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
function assertAnalysisCostRecorded(analysis, costLedger) {
|
|
2511
|
+
const reported = completeAnalysisAccounting(analysis);
|
|
2512
|
+
const summary = costLedger.summary();
|
|
2513
|
+
if (!summary.accountingComplete || summary.costProvenance.kind === "uncaptured") throw new Error("agent improvement analysis cost is incomplete in the shared account");
|
|
2514
|
+
const analysisCost = analysis.analystResult.total_cost_provenance;
|
|
2515
|
+
if (!analysisCost || analysisCost.kind === "uncaptured") throw new Error("agent improvement analysis cost is uncaptured");
|
|
2516
|
+
if (!numbersApproximatelyEqual(summary.totalCostUsd, reported.costUsd) || summary.costProvenance.kind !== analysisCost.kind) throw new Error("agent improvement analysis cost does not match the shared account");
|
|
2517
|
+
}
|
|
2518
|
+
function createProfileImprovementCostLedger(budgetUsd) {
|
|
2519
|
+
if (!Number.isFinite(budgetUsd) || budgetUsd < 0) throw new Error("profile improvement budgetUsd must be a non-negative finite number");
|
|
2520
|
+
return new CostLedger({ costCeilingUsd: budgetUsd });
|
|
2521
|
+
}
|
|
2522
|
+
function profilePolicyWithBudget(policy, budgetUsd) {
|
|
2523
|
+
if (policy.budgetUsd !== void 0 && !numbersApproximatelyEqual(policy.budgetUsd, budgetUsd)) throw new Error("profile improvement policy budgetUsd must equal the run budgetUsd");
|
|
2524
|
+
return {
|
|
2525
|
+
...policy,
|
|
2526
|
+
budgetUsd
|
|
2527
|
+
};
|
|
2528
|
+
}
|
|
2529
|
+
function profilePreparationAccounting(costLedger, startedAt) {
|
|
2530
|
+
const summary = costLedger.summary();
|
|
2531
|
+
if (!summary.accountingComplete || summary.costProvenance.kind === "uncaptured") throw new Error("profile improvement preparation cost is incomplete");
|
|
2532
|
+
return {
|
|
2533
|
+
wallDurationMs: Math.max(0, performance.now() - startedAt),
|
|
2534
|
+
cost: {
|
|
2535
|
+
usd: summary.costProvenance.usd,
|
|
2536
|
+
provenance: summary.costProvenance.kind
|
|
2537
|
+
}
|
|
2538
|
+
};
|
|
2539
|
+
}
|
|
2540
|
+
function completeImprovementSearchAccounting(analysis, improvement) {
|
|
2541
|
+
if (!improvement.cost.accountingComplete) throw new Error(`agent improvement optimization cost is incomplete: ${improvement.cost.incompleteReasons.join(", ") || "unspecified"}`);
|
|
2542
|
+
if (!Number.isFinite(improvement.cost.totalCostUsd) || improvement.cost.totalCostUsd < 0) throw new Error("agent improvement optimization cost must be finite and non-negative");
|
|
2543
|
+
if (!Number.isFinite(improvement.durationMs) || improvement.durationMs < 0) throw new Error("agent improvement optimization duration must be finite and non-negative");
|
|
2544
|
+
return {
|
|
2545
|
+
searchCostUsd: analysis.costUsd + improvement.cost.totalCostUsd,
|
|
2546
|
+
searchDurationMs: analysis.durationMs + improvement.durationMs
|
|
2547
|
+
};
|
|
2548
|
+
}
|
|
2549
|
+
function profileStateDigest(stateDigest, identity, profile) {
|
|
2550
|
+
return agentProfileImprovementArmSchema.parse({ stateDigest: stateDigest({
|
|
2551
|
+
identity,
|
|
2552
|
+
profile
|
|
2553
|
+
}) }).stateDigest;
|
|
2554
|
+
}
|
|
2555
|
+
function sealProfileImprovementBenchmark(input) {
|
|
2556
|
+
const tasks = input.tasks.map((task) => sealAgentProfileImprovementTask(task));
|
|
2557
|
+
return sealAgentProfileImprovementSuite({
|
|
2558
|
+
splitDigest: campaignSplitDigestFromIdentities(tasks.map(profileTaskScenarioIdentity), input.reps),
|
|
2559
|
+
tasks,
|
|
2560
|
+
reps: input.reps,
|
|
2561
|
+
seeds: input.seeds
|
|
2562
|
+
});
|
|
2563
|
+
}
|
|
2564
|
+
function profileTaskScenarioIdentity(task) {
|
|
2565
|
+
return {
|
|
2566
|
+
id: task.scenario.id,
|
|
2567
|
+
kind: task.scenario.kind,
|
|
2568
|
+
scenarioDigest: task.scenario.digest
|
|
2569
|
+
};
|
|
2570
|
+
}
|
|
2571
|
+
function assertReleaseSplitIsFresh(heldOutSplitDigest, improvement) {
|
|
2572
|
+
const consumedSplits = [improvement.lineage.developmentSplitDigest];
|
|
2573
|
+
if (improvement.mode === "method") {
|
|
2574
|
+
const finalTestSplitDigest = improvement.lineage.finalTestSplitDigest;
|
|
2575
|
+
if (!finalTestSplitDigest) throw new Error("method improvement does not retain its final-test split digest");
|
|
2576
|
+
consumedSplits.push(finalTestSplitDigest);
|
|
2577
|
+
}
|
|
2578
|
+
if (consumedSplits.includes(heldOutSplitDigest)) throw new Error("release benchmark reuses an optimizer development or final-test split");
|
|
2579
|
+
}
|
|
2580
|
+
function assertReleaseScenariosAreFresh(improvement, heldOutScenarios) {
|
|
2581
|
+
const optimizerScenarios = /* @__PURE__ */ new Map();
|
|
2582
|
+
for (const [partition, scenarios] of [
|
|
2583
|
+
["train", improvement.lineage.scenarioPartitions.train],
|
|
2584
|
+
["selection", improvement.lineage.scenarioPartitions.selection],
|
|
2585
|
+
["final-test", improvement.lineage.scenarioPartitions.finalTest]
|
|
2586
|
+
]) for (const scenario of scenarios) optimizerScenarios.set(canonicalCandidateDigest$1(scenario), partition);
|
|
2587
|
+
const reused = heldOutScenarios.filter((scenario) => optimizerScenarios.has(canonicalCandidateDigest$1(scenario))).map((scenario) => `${scenario.id} (${optimizerScenarios.get(canonicalCandidateDigest$1(scenario))})`);
|
|
2588
|
+
if (reused.length > 0) throw new Error(`release benchmark reuses optimizer scenario(s): [${reused.join(", ")}]`);
|
|
2589
|
+
}
|
|
2590
|
+
function assertCandidateReleaseWorkIsFresh(experiment, improvement) {
|
|
2591
|
+
for (const splitDigest of new Set(experiment.benchmark.tasks.map((task) => task.benchmark.splitDigest))) assertReleaseSplitIsFresh(splitDigest, improvement);
|
|
2592
|
+
if (improvement.mode !== "method") return;
|
|
2593
|
+
assertReleaseScenariosAreFresh(improvement, experiment.benchmark.tasks.map((task) => task.scenario));
|
|
2594
|
+
}
|
|
2595
|
+
function assertProfileReleaseWorkIsFresh(benchmark, improvement) {
|
|
2596
|
+
assertReleaseSplitIsFresh(benchmark.suite.splitDigest, improvement);
|
|
2597
|
+
assertReleaseScenariosAreFresh(improvement, benchmark.tasks.map(profileTaskScenarioIdentity));
|
|
2598
|
+
}
|
|
2599
|
+
function profileImprovementMetadata(metadata, source, optimizationReceipt) {
|
|
2600
|
+
assertNoCallerOptimizationReceipt(metadata);
|
|
2601
|
+
if (metadata && Object.hasOwn(metadata, AGENT_IMPROVEMENT_SOURCE_METADATA_KEY)) throw new Error(`candidate metadata reserves '${AGENT_IMPROVEMENT_SOURCE_METADATA_KEY}' for Runtime`);
|
|
2602
|
+
const sourceMetadata = agentImprovementSourceMetadata(source);
|
|
2603
|
+
const merged = {
|
|
2604
|
+
...metadata ?? {},
|
|
2605
|
+
...sourceMetadata
|
|
2606
|
+
};
|
|
2607
|
+
return optimizationReceipt ? attachOptimizationActivationReceipt(merged, optimizationReceipt) : immutableCandidateValue(merged);
|
|
2608
|
+
}
|
|
2609
|
+
/**
|
|
2610
|
+
* Analyze a product-owned profile, search one profile surface, then run the
|
|
2611
|
+
* exact baseline and candidate through the product executor before proposing.
|
|
2612
|
+
*/
|
|
2613
|
+
async function proposeAgentProfileImprovement(options) {
|
|
2614
|
+
const source = agentImprovementSourceSchema.parse(options.source);
|
|
2615
|
+
if (!isAgentProfileMeasuredSurface(options.improvement.surface ?? "prompt")) throw new Error("measured profile improvement supports prompt or skills; use the sealed-candidate path for this surface");
|
|
2616
|
+
const costLedger = createProfileImprovementCostLedger(options.budgetUsd);
|
|
2617
|
+
const preparationStartedAt = performance.now();
|
|
2618
|
+
const profile = parseExactAgentProfile(options.profile, "profile improvement source");
|
|
2619
|
+
const baselineStateDigest = profileStateDigest(options.stateDigest, source.sourceIdentity, profile);
|
|
2620
|
+
if (baselineStateDigest !== source.sourceDigest) throw new Error("profile improvement source digest does not match the measured profile state");
|
|
2621
|
+
const policy = profilePolicyWithBudget(options.benchmark.policy, options.budgetUsd);
|
|
2622
|
+
if (options.improvement.costCeiling !== void 0 && !numbersApproximatelyEqual(options.improvement.costCeiling, options.budgetUsd)) throw new Error("profile improvement costCeiling must equal the run budgetUsd");
|
|
2623
|
+
const { analysis, findings } = await analyzeAgentImprovement(options.runId, options.analysis, costLedger, options.signal);
|
|
2624
|
+
const improvement = await improve(profile, {
|
|
2625
|
+
...options.improvement,
|
|
2626
|
+
executionRef: options.executor.executionRef.digest,
|
|
2627
|
+
agent: options.executor.optimize,
|
|
2628
|
+
costLedger,
|
|
2629
|
+
costCeiling: options.budgetUsd,
|
|
2630
|
+
findings: [...options.improvement.findings ?? [], ...findings]
|
|
2631
|
+
});
|
|
2632
|
+
try {
|
|
2633
|
+
if (improvement.decision !== "ship") throw new Error("agent profile improvement search did not produce a promotable candidate");
|
|
2634
|
+
const candidateProfile = parseExactAgentProfile(improvement.candidate.profile, "profile improvement candidate");
|
|
2635
|
+
const candidateStateDigest = profileStateDigest(options.stateDigest, source.sourceIdentity, candidateProfile);
|
|
2636
|
+
if (candidateStateDigest === baselineStateDigest) throw new Error("profile improvement candidate state digest matches the baseline");
|
|
2637
|
+
const change = agentImprovementProfileDiffs(profile, candidateProfile, {
|
|
2638
|
+
id: `profile-improvement:${candidateStateDigest}`,
|
|
2639
|
+
metadata: {
|
|
2640
|
+
sourceIdentity: source.sourceIdentity,
|
|
2641
|
+
sourceRevision: source.sourceRevision
|
|
2642
|
+
}
|
|
2643
|
+
});
|
|
2644
|
+
const profileDiffIds = change.map((step) => {
|
|
2645
|
+
if (!step.id) throw new Error("profile improvement change requires an exact diff id");
|
|
2646
|
+
return step.id;
|
|
2647
|
+
});
|
|
2648
|
+
const benchmark = sealProfileImprovementBenchmark({
|
|
2649
|
+
...options.benchmark,
|
|
2650
|
+
policy
|
|
2651
|
+
});
|
|
2652
|
+
assertProfileReleaseWorkIsFresh(benchmark, improvement);
|
|
2653
|
+
const experiment = sealAgentProfileImprovementExperiment({
|
|
2654
|
+
kind: "agent-profile-improvement-experiment",
|
|
2655
|
+
digestAlgorithm: "rfc8785-sha256",
|
|
2656
|
+
source,
|
|
2657
|
+
executionRef: options.executor.executionRef,
|
|
2658
|
+
baseline: { stateDigest: baselineStateDigest },
|
|
2659
|
+
candidate: { stateDigest: candidateStateDigest },
|
|
2660
|
+
change,
|
|
2661
|
+
candidateLineage: {
|
|
2662
|
+
source: "optimizer",
|
|
2663
|
+
parentDigests: [source.sourceDigest],
|
|
2664
|
+
runIds: [improvement.lineage.runId],
|
|
2665
|
+
profileDiffIds,
|
|
2666
|
+
developmentSplitDigest: improvement.lineage.developmentSplitDigest
|
|
2667
|
+
},
|
|
2668
|
+
benchmark,
|
|
2669
|
+
policy
|
|
2670
|
+
});
|
|
2671
|
+
const profilesByStateDigest = /* @__PURE__ */ new Map([[baselineStateDigest, profile], [candidateStateDigest, candidateProfile]]);
|
|
2672
|
+
const preparation = profilePreparationAccounting(costLedger, preparationStartedAt);
|
|
2673
|
+
const run = await runAgentProfileImprovementExperiment({
|
|
2674
|
+
experiment,
|
|
2675
|
+
...options.maxConcurrency === void 0 ? {} : { maxConcurrency: options.maxConcurrency },
|
|
2676
|
+
costLedger,
|
|
2677
|
+
...options.signal ? { signal: options.signal } : {},
|
|
2678
|
+
execute: async (input) => {
|
|
2679
|
+
const measuredProfile = profilesByStateDigest.get(input.stateDigest);
|
|
2680
|
+
if (!measuredProfile) throw new Error("profile improvement execution requested an unknown profile state");
|
|
2681
|
+
return options.executor.measure({
|
|
2682
|
+
...input,
|
|
2683
|
+
profile: measuredProfile
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
2686
|
+
});
|
|
2687
|
+
const optimizationReceipt = createOptimizationActivationReceipt(improvement);
|
|
2688
|
+
const evaluation = verifyAgentProfileImprovementExperimentComparison(measuredComparisonFromAgentProfileImprovementExperiment({
|
|
2689
|
+
experiment,
|
|
2690
|
+
measurements: run.measurements,
|
|
2691
|
+
runId: options.runId,
|
|
2692
|
+
...options.candidate ? { candidate: options.candidate } : {},
|
|
2693
|
+
generationsExplored: improvement.generationsExplored ?? 0,
|
|
2694
|
+
preparation,
|
|
2695
|
+
measurement: run.measurement,
|
|
2696
|
+
metadata: profileImprovementMetadata(options.metadata, source, optimizationReceipt)
|
|
2697
|
+
}));
|
|
2698
|
+
const proposal = createAgentImprovementProposal({
|
|
2699
|
+
runId: options.runId,
|
|
2700
|
+
findings,
|
|
2701
|
+
evaluation,
|
|
2702
|
+
...options.now ? { now: options.now } : {}
|
|
2703
|
+
});
|
|
2704
|
+
return {
|
|
2705
|
+
analysis,
|
|
2706
|
+
improvement,
|
|
2707
|
+
experiment,
|
|
2708
|
+
measurements: run.measurements,
|
|
2709
|
+
proposal
|
|
2710
|
+
};
|
|
2711
|
+
} catch (cause) {
|
|
2712
|
+
return rethrowAfterCleanup(cause, () => improvement.dispose(), "proposeAgentProfileImprovement failed");
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2400
2715
|
/** Analyze, search, then remeasure the resulting exact candidate before proposing it. */
|
|
2401
2716
|
async function proposeAgentImprovement(options) {
|
|
2402
2717
|
assertNoCallerOptimizationReceipt(options.metadata);
|
|
2403
|
-
const analysis = await
|
|
2404
|
-
|
|
2405
|
-
runId: options.runId
|
|
2406
|
-
});
|
|
2407
|
-
const findings = assertNoJudgeVerdict(analysis.analystResult.findings, "proposeAgentImprovement findings");
|
|
2718
|
+
const { analysis, findings } = await analyzeAgentImprovement(options.runId, options.analysis);
|
|
2719
|
+
const analysisAccounting = completeAnalysisAccounting(analysis);
|
|
2408
2720
|
const improvementInput = {
|
|
2409
2721
|
...options.improvement,
|
|
2410
2722
|
findings: [...options.improvement.findings ?? [], ...findings]
|
|
@@ -2412,6 +2724,14 @@ async function proposeAgentImprovement(options) {
|
|
|
2412
2724
|
const improvement = improvementInput.surface === "code" ? await improve(improvementInput) : await improve(options.profile, improvementInput);
|
|
2413
2725
|
try {
|
|
2414
2726
|
if (improvement.decision !== "ship") throw new Error("agent improvement search did not produce a promotable candidate");
|
|
2727
|
+
const searchAccounting = completeImprovementSearchAccounting(analysisAccounting, improvement);
|
|
2728
|
+
const preparation = {
|
|
2729
|
+
wallDurationMs: searchAccounting.searchDurationMs,
|
|
2730
|
+
cost: {
|
|
2731
|
+
usd: searchAccounting.searchCostUsd,
|
|
2732
|
+
provenance: "estimated"
|
|
2733
|
+
}
|
|
2734
|
+
};
|
|
2415
2735
|
const optimizationReceipt = improvement.mode === "method" ? createOptimizationActivationReceipt(improvement) : void 0;
|
|
2416
2736
|
const experiment = sealAgentImprovementExperiment(await options.buildExperiment({
|
|
2417
2737
|
analysis,
|
|
@@ -2428,8 +2748,7 @@ async function proposeAgentImprovement(options) {
|
|
|
2428
2748
|
...options.candidate ? { candidate: options.candidate } : {},
|
|
2429
2749
|
...optimizationReceipt ? { metadata: attachOptimizationActivationReceipt(options.metadata, optimizationReceipt) } : options.metadata ? { metadata: options.metadata } : {},
|
|
2430
2750
|
...improvement.generationsExplored === void 0 ? {} : { generationsExplored: improvement.generationsExplored },
|
|
2431
|
-
|
|
2432
|
-
searchCostUsd: improvement.cost.totalCostUsd
|
|
2751
|
+
preparation
|
|
2433
2752
|
});
|
|
2434
2753
|
const proposal = createAgentImprovementProposal({
|
|
2435
2754
|
runId: options.runId,
|
|
@@ -2504,12 +2823,14 @@ function createAgentImprovementActivation(inputProposal, inputReview, options) {
|
|
|
2504
2823
|
const authorizedAt = (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
|
|
2505
2824
|
if (Date.parse(authorizedAt) < Date.parse(review.reviewedAt)) throw new Error("candidate activation cannot predate its approval");
|
|
2506
2825
|
const targets = buildAgentImprovementActivationTargets(proposal.changedSurfaces, experiment, options.intent, options.targets);
|
|
2826
|
+
const executionRef = profileActivationExecutionRef(experiment, targets, options.executionRef);
|
|
2507
2827
|
return agentImprovementActivationSchema.parse(canonicalCandidateDocument({
|
|
2508
2828
|
kind: "agent-improvement-activation",
|
|
2509
2829
|
proposalDigest: proposal.digest,
|
|
2510
2830
|
reviewDigest: review.digest,
|
|
2511
2831
|
experimentDigest: experiment.digest,
|
|
2512
2832
|
candidateDigest: measuredCandidateDigest(proposal),
|
|
2833
|
+
...executionRef ? { executionRef } : {},
|
|
2513
2834
|
intent: options.intent,
|
|
2514
2835
|
targets,
|
|
2515
2836
|
fundingOwner: options.fundingOwner,
|
|
@@ -2534,6 +2855,17 @@ function requireSealedCandidateExperiment(proposal) {
|
|
|
2534
2855
|
function measuredCandidateDigest(proposal) {
|
|
2535
2856
|
return proposal.evaluation.kind === "agent-profile-improvement-measured-comparison" ? proposal.evaluation.experiment.candidate.stateDigest : proposal.evaluation.experiment.candidate.digest;
|
|
2536
2857
|
}
|
|
2858
|
+
function profileActivationExecutionRef(experiment, targets, executionRef) {
|
|
2859
|
+
if (!targets.some((target) => target.surface === "agent-profile")) {
|
|
2860
|
+
if (executionRef !== void 0) throw new Error("profile activation executionRef is valid only for agent-profile targets");
|
|
2861
|
+
return;
|
|
2862
|
+
}
|
|
2863
|
+
if (experiment.kind !== "agent-profile-improvement-experiment") throw new Error("agent-profile activation requires a measured profile experiment");
|
|
2864
|
+
if (executionRef === void 0) throw new Error("profile improvement activation requires the measured executor");
|
|
2865
|
+
const parsed = agentProfileImprovementExecutionRefSchema.parse(executionRef);
|
|
2866
|
+
if (canonicalCandidateDigest$1(parsed) !== canonicalCandidateDigest$1(experiment.executionRef)) throw new Error("profile improvement activation executor does not match the measurement");
|
|
2867
|
+
return parsed;
|
|
2868
|
+
}
|
|
2537
2869
|
function validateShippableAgentImprovementEvaluation(input, runId, subject) {
|
|
2538
2870
|
const evaluation = verifyAgentImprovementEvaluation(input);
|
|
2539
2871
|
if (evaluation.decision.outcome !== "ship") throw new Error(`${subject} requires a passing experiment`);
|
|
@@ -2565,6 +2897,7 @@ function verifyAgentImprovementActivation(input) {
|
|
|
2565
2897
|
const activation = verifyCanonicalCandidateDocument(agentImprovementActivationSchema.parse(input.activation), "agent improvement activation");
|
|
2566
2898
|
const experiment = proposal.evaluation.experiment;
|
|
2567
2899
|
if (review.decision !== "approve" || review.proposalDigest !== proposal.digest || activation.proposalDigest !== proposal.digest || activation.reviewDigest !== review.digest || activation.experimentDigest !== experiment.digest || activation.candidateDigest !== measuredCandidateDigest(proposal) || Date.parse(review.reviewedAt) < Date.parse(proposal.proposedAt) || Date.parse(activation.authorizedAt) < Date.parse(review.reviewedAt)) throw new Error("candidate activation does not bind the measured and approved candidate");
|
|
2900
|
+
if (activation.targets.some((target) => target.surface === "agent-profile") && (proposal.evaluation.kind !== "agent-profile-improvement-measured-comparison" || activation.executionRef === void 0 || canonicalCandidateDigest$1(activation.executionRef) !== canonicalCandidateDigest$1(proposal.evaluation.experiment.executionRef))) throw new Error("profile activation does not bind the measured executor");
|
|
2568
2901
|
assertAgentImprovementActivationTargets(proposal.changedSurfaces, experiment, activation.intent, activation.targets);
|
|
2569
2902
|
return activation;
|
|
2570
2903
|
}
|
|
@@ -2619,6 +2952,6 @@ function assertNoJudgeDerivedProposalFindings(findings) {
|
|
|
2619
2952
|
throw new Error(`agent improvement proposal findings: judge-derived findings cannot steer an improvement: [${identifiers.join(", ")}]`);
|
|
2620
2953
|
}
|
|
2621
2954
|
//#endregion
|
|
2622
|
-
export {
|
|
2955
|
+
export { improve as A, isAnalystFinding as B, agentImprovementTargetInput as C, buildAgentImprovementActivationTargets as D, assertProfileImprovementTargetsShareIdentity as E, normalizeRolloutPolicy as F, defaultBuildPrompt as G, AGENTIC_PROFILE_RESOURCE_ROOT as H, parseRolloutPolicy as I, summarizeFindings as J, rawTraceEvidenceProblem as K, serializeRolloutPolicy as L, rawTraceDistiller as M, ROLLOUT_POLICY_EXTENSION as N, isAgentImprovementProfileSurface as O, applyRolloutPolicyToProfile as P, structuralRolloutPolicyFromProfile as R, agentImprovementTargetDigest as S, agentProfileImprovementStateDigest as T, agenticGenerator as U, toAnalystFindings as V, commandVerifier as W, worktreeChangedPaths as Y, AGENT_IMPROVEMENT_PROFILE_SURFACES as _, executeAgentCandidateExperimentCell as a, agentImprovementProfileSurfaceDigest as b, requireSealedCandidateExperiment as c, verifyAgentImprovementActivation as d, verifyAgentImprovementProposal as f, optimizationActivationReceiptFromMetadata as g, createOptimizationActivationReceipt as h, createAgentImprovementProposal as i, withMethodRuntimeControls as j, isAgentProfileMeasuredSurface as k, reviewAgentImprovementProposal as l, verifyCandidateExecutionEvidence as m, createAgentImprovementActivation as n, proposeAgentImprovement as o, verifyAgentImprovementReview as p, requiresRawTraceEvidence as q, createAgentImprovementMeasuredComparison as r, proposeAgentProfileImprovement as s, AgentCandidateExperimentCellExecutionError as t, runAgentCandidateExperiment as u, AGENT_PROFILE_MEASURED_SURFACES as v, agentImprovementTargetProfileDiffs as w, agentImprovementProfileSurfaceInput as x, agentImprovementProfileDiffs as y, LIFTED_FINDING_ANALYST_ID as z };
|
|
2623
2956
|
|
|
2624
|
-
//# sourceMappingURL=improvement-cycle-
|
|
2957
|
+
//# sourceMappingURL=improvement-cycle-Ulvvbg5p.js.map
|