@tangle-network/agent-runtime 0.94.12 → 0.95.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/dist/agent.d.ts +2 -25
- package/dist/agent.js +9 -12
- package/dist/agent.js.map +1 -1
- package/dist/{agentic-generator-DDMM45kZ.d.ts → agentic-generator-hCaQRAes.d.ts} +0 -1
- package/dist/analyst-loop.d.ts +1 -1
- package/dist/candidate-execution/index.d.ts +43 -16
- package/dist/candidate-execution/index.js +18 -8
- package/dist/{chunk-VYA2YEKA.js → chunk-2KGAN2HM.js} +83 -14
- package/dist/chunk-2KGAN2HM.js.map +1 -0
- package/dist/{chunk-FTXM7Q7P.js → chunk-6YBA64Z2.js} +120 -724
- package/dist/chunk-6YBA64Z2.js.map +1 -0
- package/dist/{chunk-HGRW27YY.js → chunk-AP7CPGMZ.js} +139 -19
- package/dist/chunk-AP7CPGMZ.js.map +1 -0
- package/dist/{chunk-XP5KDM3R.js → chunk-BPGXIKK7.js} +3 -3
- package/dist/{chunk-D3H7F6L2.js → chunk-DHCHL6OG.js} +2 -3
- package/dist/chunk-DHCHL6OG.js.map +1 -0
- package/dist/{chunk-PCURO3DL.js → chunk-G55QE4IQ.js} +512 -36
- package/dist/chunk-G55QE4IQ.js.map +1 -0
- package/dist/{chunk-C3UKLQ54.js → chunk-IADLKE7I.js} +14 -4
- package/dist/chunk-IADLKE7I.js.map +1 -0
- package/dist/{chunk-WIPGQ4GT.js → chunk-IMSNJSXH.js} +1 -1
- package/dist/{chunk-WIPGQ4GT.js.map → chunk-IMSNJSXH.js.map} +1 -1
- package/dist/{chunk-VSWBYWFK.js → chunk-M6MD6JBS.js} +20 -27
- package/dist/chunk-M6MD6JBS.js.map +1 -0
- package/dist/chunk-MKGRLDWB.js +684 -0
- package/dist/chunk-MKGRLDWB.js.map +1 -0
- package/dist/{chunk-AEG3NGJ2.js → chunk-Q2JSAVQ3.js} +34 -2
- package/dist/chunk-Q2JSAVQ3.js.map +1 -0
- package/dist/{chunk-37V4KQDC.js → chunk-WTZ37EQY.js} +1021 -514
- package/dist/chunk-WTZ37EQY.js.map +1 -0
- package/dist/{chunk-U33YZ7B2.js → chunk-YLUOTX6U.js} +4 -4
- package/dist/{chunk-33OG2NN3.js → chunk-Z5I642SY.js} +2 -2
- package/dist/{completion-gate-D1gX1-hg.d.ts → completion-gate-C80jiRfN.d.ts} +1 -1
- package/dist/conversation.d.ts +12 -1
- package/dist/conversation.js +2 -2
- package/dist/{coordination-Dr_axlAf.d.ts → coordination-BFE3Den7.d.ts} +10 -11
- package/dist/environment-provider.d.ts +2 -2
- package/dist/environment-provider.js +1 -1
- package/dist/{improve-BN3HyXIO.d.ts → improve-B-UYaEH5.d.ts} +3 -3
- package/dist/index.d.ts +22 -25
- package/dist/index.js +45 -50
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +177 -119
- package/dist/intelligence.js +501 -342
- package/dist/intelligence.js.map +1 -1
- package/dist/knowledge.d.ts +22 -11
- package/dist/knowledge.js +9 -4
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.js +1 -1
- package/dist/{loop-runner-bin-BRQSQdHa.d.ts → loop-runner-bin-BIQldFS8.d.ts} +2 -2
- package/dist/loop-runner-bin.d.ts +5 -5
- package/dist/loop-runner-bin.js +6 -6
- package/dist/loops.d.ts +12 -12
- package/dist/loops.js +5 -5
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +6 -6
- package/dist/mcp/index.js +6 -6
- package/dist/{mcp-serve-verifier-DQQDbuyz.d.ts → mcp-serve-verifier-Bs_n0xPc.d.ts} +1 -1
- package/dist/primeintellect/index.js +1 -1
- package/dist/profile-DbfaMTdk.d.ts +233 -0
- package/dist/profiles.d.ts +1 -1
- package/dist/{supervise-DmYOug5f.d.ts → supervise-BLPI50-w.d.ts} +3 -3
- package/dist/{types-ByAYqlVb.d.ts → types-B3vAW0Oq.d.ts} +1 -1
- package/dist/types-CWqfCO8s.d.ts +491 -0
- package/dist/{types-1d5QGK3t.d.ts → types-CmnA2iL3.d.ts} +3 -3
- package/dist/{worktree-fanout-CPprU-qI.d.ts → worktree-fanout-DCA3G4bO.d.ts} +3 -3
- package/package.json +13 -10
- package/dist/chunk-37V4KQDC.js.map +0 -1
- package/dist/chunk-AEG3NGJ2.js.map +0 -1
- package/dist/chunk-C3UKLQ54.js.map +0 -1
- package/dist/chunk-D3H7F6L2.js.map +0 -1
- package/dist/chunk-FTXM7Q7P.js.map +0 -1
- package/dist/chunk-HGRW27YY.js.map +0 -1
- package/dist/chunk-PCURO3DL.js.map +0 -1
- package/dist/chunk-VSWBYWFK.js.map +0 -1
- package/dist/chunk-VYA2YEKA.js.map +0 -1
- package/dist/prepare-DIeVgQG3.d.ts +0 -718
- /package/dist/{chunk-XP5KDM3R.js.map → chunk-BPGXIKK7.js.map} +0 -0
- /package/dist/{chunk-U33YZ7B2.js.map → chunk-YLUOTX6U.js.map} +0 -0
- /package/dist/{chunk-33OG2NN3.js.map → chunk-Z5I642SY.js.map} +0 -0
|
@@ -1,9 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
agentCandidateProfileAsAgentProfile,
|
|
3
|
+
candidateMaterializerHarness,
|
|
4
|
+
canonicalCandidateBytes,
|
|
5
|
+
canonicalCandidateDigest,
|
|
6
|
+
canonicalCandidateDocument,
|
|
7
|
+
createAgentCandidateProfileActivation,
|
|
8
|
+
executePreparedAgentCandidate,
|
|
9
|
+
immutableCandidateValue,
|
|
10
|
+
omitTopLevelDigest,
|
|
11
|
+
parseAgentCandidateProfileActivation,
|
|
12
|
+
prepareAgentCandidateExecution,
|
|
13
|
+
verifiedResourceTextByDigest,
|
|
14
|
+
verifyAgentCandidateBundle,
|
|
15
|
+
verifyCanonicalCandidateDocument
|
|
16
|
+
} from "./chunk-WTZ37EQY.js";
|
|
1
17
|
import {
|
|
2
18
|
assertModelAllowed
|
|
3
19
|
} from "./chunk-ISTDY47H.js";
|
|
20
|
+
import {
|
|
21
|
+
runAnalystLoop
|
|
22
|
+
} from "./chunk-QDSOD7RC.js";
|
|
4
23
|
import {
|
|
5
24
|
agenticGenerator
|
|
6
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-DHCHL6OG.js";
|
|
7
26
|
import {
|
|
8
27
|
ConfigError
|
|
9
28
|
} from "./chunk-YEJR7IXO.js";
|
|
@@ -13,6 +32,24 @@ import { spawnSync } from "child_process";
|
|
|
13
32
|
import {
|
|
14
33
|
verifyCodeSurface
|
|
15
34
|
} from "@tangle-network/agent-eval/campaign";
|
|
35
|
+
|
|
36
|
+
// src/improvement/cleanup.ts
|
|
37
|
+
async function rethrowAfterCleanup(cause, cleanup, context) {
|
|
38
|
+
const cleanupErrors = [];
|
|
39
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
40
|
+
try {
|
|
41
|
+
await cleanup();
|
|
42
|
+
} catch (cleanupCause) {
|
|
43
|
+
cleanupErrors.push(cleanupCause);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (cleanupErrors.length === 0) throw cause;
|
|
47
|
+
throw new AggregateError([cause, ...cleanupErrors], `${context}; cleanup retry succeeded`);
|
|
48
|
+
}
|
|
49
|
+
throw new AggregateError([cause, ...cleanupErrors], `${context}; cleanup failed`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/improvement/improvement-driver.ts
|
|
16
53
|
function improvementDriver(opts) {
|
|
17
54
|
const baseRef = opts.baseRef ?? "main";
|
|
18
55
|
const owned = /* @__PURE__ */ new Map();
|
|
@@ -57,22 +94,14 @@ function improvementDriver(opts) {
|
|
|
57
94
|
owned.delete(wt.path);
|
|
58
95
|
owned.set(surface.worktreeRef, wt);
|
|
59
96
|
} catch (err) {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
97
|
+
const failure = err instanceof Error ? err.message : String(err);
|
|
98
|
+
return rethrowAfterCleanup(
|
|
99
|
+
err,
|
|
100
|
+
async () => {
|
|
63
101
|
await opts.worktree.discard(wt);
|
|
64
102
|
owned.delete(wt.path);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
cleanupErrors.push(cause);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (cleanupErrors.length === 0) throw err;
|
|
71
|
-
const failure = err instanceof Error ? err.message : String(err);
|
|
72
|
-
const cleanupSucceeded = !owned.has(wt.path);
|
|
73
|
-
throw new AggregateError(
|
|
74
|
-
[err, ...cleanupErrors],
|
|
75
|
-
cleanupSucceeded ? `improvementDriver: ${failure}; candidate cleanup retry succeeded` : `improvementDriver: ${failure}; candidate worktree could not be cleaned`
|
|
103
|
+
},
|
|
104
|
+
`improvementDriver: ${failure}`
|
|
76
105
|
);
|
|
77
106
|
}
|
|
78
107
|
}
|
|
@@ -365,6 +394,8 @@ function baselineSurfaceFor(profile, surface, skills, memory) {
|
|
|
365
394
|
);
|
|
366
395
|
}
|
|
367
396
|
}
|
|
397
|
+
var DISTILLED_NOTES_MAX_CHARS = 1500;
|
|
398
|
+
var DISTILLED_ERROR_MAX_CHARS = 500;
|
|
368
399
|
function generationFailureDistiller(staticFindings) {
|
|
369
400
|
const CAP = 12;
|
|
370
401
|
return async (input) => {
|
|
@@ -379,14 +410,14 @@ function generationFailureDistiller(staticFindings) {
|
|
|
379
410
|
) : [];
|
|
380
411
|
const composite = judgeScores.length === 0 ? 0 : judgeScores.reduce((sum, j) => sum + (j.composite ?? 0), 0) / judgeScores.length;
|
|
381
412
|
if (!error && composite >= 0.999) continue;
|
|
382
|
-
const notes = judgeScores.map((j) => j.notes).filter((n) => typeof n === "string" && n.length > 0).join("; ").slice(0,
|
|
383
|
-
const claim = notes || (error ? `Scenario ${scenario} failed: ${error.slice(0,
|
|
413
|
+
const notes = judgeScores.map((j) => j.notes).filter((n) => typeof n === "string" && n.length > 0).join("; ").slice(0, DISTILLED_NOTES_MAX_CHARS);
|
|
414
|
+
const claim = notes || (error ? `Scenario ${scenario} failed: ${error.slice(0, DISTILLED_ERROR_MAX_CHARS)}` : "");
|
|
384
415
|
failures.push({
|
|
385
416
|
scenario,
|
|
386
417
|
composite: Number(composite.toFixed(3)),
|
|
387
418
|
notes,
|
|
388
419
|
...claim ? { claim } : {},
|
|
389
|
-
...error ? { error: error.slice(0,
|
|
420
|
+
...error ? { error: error.slice(0, DISTILLED_ERROR_MAX_CHARS) } : {}
|
|
390
421
|
});
|
|
391
422
|
}
|
|
392
423
|
}
|
|
@@ -402,25 +433,11 @@ function memoryGenerationDistiller(staticFindings) {
|
|
|
402
433
|
return fresh === staticFindings ? staticFindings : [...staticFindings, ...fresh];
|
|
403
434
|
};
|
|
404
435
|
}
|
|
405
|
-
async function rethrowAfterCleanup(cause, cleanup, message) {
|
|
406
|
-
const cleanupErrors = [];
|
|
407
|
-
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
408
|
-
try {
|
|
409
|
-
await cleanup();
|
|
410
|
-
} catch (cleanupCause) {
|
|
411
|
-
cleanupErrors.push(cleanupCause);
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
if (cleanupErrors.length === 0) throw cause;
|
|
415
|
-
throw new AggregateError([cause, ...cleanupErrors], `${message}; the cleanup retry succeeded`);
|
|
416
|
-
}
|
|
417
|
-
throw new AggregateError([cause, ...cleanupErrors], message);
|
|
418
|
-
}
|
|
419
436
|
async function discardPreparedBaseline(worktree, baselineWorktree, cause) {
|
|
420
437
|
return rethrowAfterCleanup(
|
|
421
438
|
cause,
|
|
422
439
|
() => worktree.discard(baselineWorktree),
|
|
423
|
-
"improve(): code preparation failed
|
|
440
|
+
"improve(): code preparation failed"
|
|
424
441
|
);
|
|
425
442
|
}
|
|
426
443
|
function isCodeSurface(surface) {
|
|
@@ -608,7 +625,7 @@ async function improve(profile, findings, opts) {
|
|
|
608
625
|
return rethrowAfterCleanup(
|
|
609
626
|
cause,
|
|
610
627
|
() => preparedCode.cleanup(),
|
|
611
|
-
"improve(): code improvement failed
|
|
628
|
+
"improve(): code improvement failed"
|
|
612
629
|
);
|
|
613
630
|
}
|
|
614
631
|
const shipped = raw.gateDecision === "ship";
|
|
@@ -652,10 +669,469 @@ async function improve(profile, findings, opts) {
|
|
|
652
669
|
};
|
|
653
670
|
}
|
|
654
671
|
|
|
672
|
+
// src/intelligence/improvement-cycle.ts
|
|
673
|
+
import { assertNoJudgeVerdict } from "@tangle-network/agent-eval/analyst";
|
|
674
|
+
import {
|
|
675
|
+
measuredComparisonFromCandidateExperiment,
|
|
676
|
+
runCandidateExperiment,
|
|
677
|
+
verifyCandidateExperiment,
|
|
678
|
+
verifyCandidateExperimentComparison
|
|
679
|
+
} from "@tangle-network/agent-eval/contract";
|
|
680
|
+
import {
|
|
681
|
+
agentCandidateMaterializationReceiptSchema,
|
|
682
|
+
agentCandidateRunReceiptSchema,
|
|
683
|
+
agentImprovementActivationSchema,
|
|
684
|
+
agentImprovementProposalSchema,
|
|
685
|
+
agentImprovementReviewSchema,
|
|
686
|
+
candidateExecutionEvidenceSchema
|
|
687
|
+
} from "@tangle-network/agent-interface";
|
|
688
|
+
import { materializeCandidateProfile } from "@tangle-network/agent-profile-materialize";
|
|
689
|
+
var AgentCandidateExperimentCellExecutionError = class extends Error {
|
|
690
|
+
finalization;
|
|
691
|
+
constructor(finalization) {
|
|
692
|
+
super(`candidate experiment cell failed: ${finalization.reason}`);
|
|
693
|
+
this.name = "AgentCandidateExperimentCellExecutionError";
|
|
694
|
+
this.finalization = finalization;
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
async function runAgentCandidateExperiment(options) {
|
|
698
|
+
const experiment = verifyCandidateExperiment(options.experiment);
|
|
699
|
+
const measurements = await runCandidateExperiment({
|
|
700
|
+
experiment,
|
|
701
|
+
...options.maxConcurrency === void 0 ? {} : { maxConcurrency: options.maxConcurrency },
|
|
702
|
+
...options.signal ? { signal: options.signal } : {},
|
|
703
|
+
execute: async (input) => {
|
|
704
|
+
const placement = await options.placeCell(input);
|
|
705
|
+
return await executeAgentCandidateExperimentCell({ ...input, ...placement });
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
const evaluation = createAgentImprovementMeasuredComparison({
|
|
709
|
+
experiment,
|
|
710
|
+
measurements,
|
|
711
|
+
runId: options.runId,
|
|
712
|
+
...options.candidate ? { candidate: options.candidate } : {},
|
|
713
|
+
...options.generationsExplored === void 0 ? {} : { generationsExplored: options.generationsExplored },
|
|
714
|
+
...options.searchDurationMs === void 0 ? {} : { searchDurationMs: options.searchDurationMs },
|
|
715
|
+
...options.searchCostUsd === void 0 ? {} : { searchCostUsd: options.searchCostUsd },
|
|
716
|
+
...options.metadata ? { metadata: options.metadata } : {}
|
|
717
|
+
});
|
|
718
|
+
return { experiment, measurements, evaluation };
|
|
719
|
+
}
|
|
720
|
+
async function executeAgentCandidateExperimentCell(options) {
|
|
721
|
+
const experiment = verifyCandidateExperiment(options.experiment);
|
|
722
|
+
const bundle = experiment[options.arm];
|
|
723
|
+
assertExactExperimentInput(options, experiment, bundle);
|
|
724
|
+
const attempt = options.attempt ?? 1;
|
|
725
|
+
if (attempt > options.task.attempt.maxAttempts) {
|
|
726
|
+
throw new Error("candidate experiment attempt exceeds the signed task policy");
|
|
727
|
+
}
|
|
728
|
+
const runCell = canonicalCandidateDocument({
|
|
729
|
+
kind: "agent-candidate-run-cell",
|
|
730
|
+
experimentDigest: experiment.digest,
|
|
731
|
+
arm: options.arm,
|
|
732
|
+
bundleDigest: bundle.digest,
|
|
733
|
+
suiteDigest: options.benchmarkCell.suiteDigest,
|
|
734
|
+
taskDigest: options.task.digest,
|
|
735
|
+
taskIndex: options.benchmarkCell.taskIndex,
|
|
736
|
+
repetition: options.benchmarkCell.repetition,
|
|
737
|
+
seed: options.seed,
|
|
738
|
+
attempt
|
|
739
|
+
}).value;
|
|
740
|
+
const verified = await verifyAgentCandidateBundle(bundle, options.ports);
|
|
741
|
+
const prepared = await prepareAgentCandidateExecution(
|
|
742
|
+
verified,
|
|
743
|
+
{
|
|
744
|
+
executionId: options.executionId,
|
|
745
|
+
runCell,
|
|
746
|
+
benchmarkSuite: experiment.benchmark.suite,
|
|
747
|
+
task: options.task,
|
|
748
|
+
executionRoots: options.executionRoots,
|
|
749
|
+
stagingRoots: options.stagingRoots
|
|
750
|
+
},
|
|
751
|
+
options.ports,
|
|
752
|
+
options.preparation
|
|
753
|
+
);
|
|
754
|
+
const finalization = await executePreparedAgentCandidate(prepared, options.execution);
|
|
755
|
+
if (!finalization.succeeded) {
|
|
756
|
+
throw new AgentCandidateExperimentCellExecutionError(finalization);
|
|
757
|
+
}
|
|
758
|
+
const evidence = canonicalCandidateDocument({
|
|
759
|
+
kind: "agent-candidate-execution-evidence",
|
|
760
|
+
materializationReceipt: prepared.materializationReceipt.value,
|
|
761
|
+
receipt: finalization.receipt.value
|
|
762
|
+
}).value;
|
|
763
|
+
return verifyCandidateExecutionEvidence(evidence, {
|
|
764
|
+
experiment,
|
|
765
|
+
arm: options.arm,
|
|
766
|
+
benchmarkCell: options.benchmarkCell,
|
|
767
|
+
seed: options.seed,
|
|
768
|
+
attempt,
|
|
769
|
+
resolvedResources: verifiedResourceTextByDigest(verified)
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
function createAgentImprovementMeasuredComparison(options) {
|
|
773
|
+
return verifyCandidateExperimentComparison(measuredComparisonFromCandidateExperiment(options));
|
|
774
|
+
}
|
|
775
|
+
async function proposeAgentImprovement(options) {
|
|
776
|
+
const writeBackSurface = options.improvement.skills?.writeBack ? "skill" : options.improvement.memory?.writeBack ? "memory" : null;
|
|
777
|
+
if (writeBackSurface) {
|
|
778
|
+
throw new Error(`proposeAgentImprovement cannot write ${writeBackSurface} before approval`);
|
|
779
|
+
}
|
|
780
|
+
const analysis = await runAnalystLoop({ ...options.analysis, runId: options.runId });
|
|
781
|
+
const findings = assertNoJudgeVerdict(
|
|
782
|
+
analysis.analystResult.findings,
|
|
783
|
+
"proposeAgentImprovement findings"
|
|
784
|
+
);
|
|
785
|
+
const improvement = await improve(options.profile, [...findings], options.improvement);
|
|
786
|
+
try {
|
|
787
|
+
if (!improvement.shipped) {
|
|
788
|
+
throw new Error("agent improvement search did not produce a promotable candidate");
|
|
789
|
+
}
|
|
790
|
+
const experiment = verifyCandidateExperiment(
|
|
791
|
+
await options.buildExperiment({ analysis, improvement })
|
|
792
|
+
);
|
|
793
|
+
if (canonicalCandidateDigest(experiment.baseline.profile) !== canonicalCandidateDigest(options.profile)) {
|
|
794
|
+
throw new Error("candidate experiment baseline does not match the analyzed agent profile");
|
|
795
|
+
}
|
|
796
|
+
const measured = await runAgentCandidateExperiment({
|
|
797
|
+
experiment,
|
|
798
|
+
runId: options.runId,
|
|
799
|
+
placeCell: options.placeCell,
|
|
800
|
+
...options.maxConcurrency === void 0 ? {} : { maxConcurrency: options.maxConcurrency },
|
|
801
|
+
...options.signal ? { signal: options.signal } : {},
|
|
802
|
+
...options.candidate ? { candidate: options.candidate } : {},
|
|
803
|
+
...options.metadata ? { metadata: options.metadata } : {},
|
|
804
|
+
generationsExplored: improvement.raw.generationsExplored,
|
|
805
|
+
searchDurationMs: improvement.raw.durationMs,
|
|
806
|
+
searchCostUsd: improvement.raw.totalCostUsd
|
|
807
|
+
});
|
|
808
|
+
const proposal = createAgentImprovementProposal({
|
|
809
|
+
runId: options.runId,
|
|
810
|
+
findings,
|
|
811
|
+
evaluation: measured.evaluation,
|
|
812
|
+
...options.now ? { now: options.now } : {}
|
|
813
|
+
});
|
|
814
|
+
return {
|
|
815
|
+
analysis,
|
|
816
|
+
improvement,
|
|
817
|
+
experiment,
|
|
818
|
+
measurements: measured.measurements,
|
|
819
|
+
proposal
|
|
820
|
+
};
|
|
821
|
+
} catch (cause) {
|
|
822
|
+
return rethrowAfterCleanup(cause, () => improvement.dispose(), "proposeAgentImprovement failed");
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
function createAgentImprovementProposal(options) {
|
|
826
|
+
const findings = assertNoJudgeVerdict(
|
|
827
|
+
[...options.findings],
|
|
828
|
+
"createAgentImprovementProposal findings"
|
|
829
|
+
);
|
|
830
|
+
const evaluation = verifyCandidateExperimentComparison(options.evaluation);
|
|
831
|
+
if (evaluation.decision.outcome !== "ship") {
|
|
832
|
+
throw new Error("agent improvement proposal requires a passing experiment");
|
|
833
|
+
}
|
|
834
|
+
if (options.runId !== evaluation.provenance.runId) {
|
|
835
|
+
throw new Error("proposal runId does not match its measured experiment");
|
|
836
|
+
}
|
|
837
|
+
const changedSurfaces = deriveChangedSurfaces(
|
|
838
|
+
evaluation.experiment.baseline,
|
|
839
|
+
evaluation.experiment.candidate
|
|
840
|
+
);
|
|
841
|
+
return agentImprovementProposalSchema.parse(
|
|
842
|
+
canonicalCandidateDocument({
|
|
843
|
+
kind: "agent-improvement-proposal",
|
|
844
|
+
runId: options.runId,
|
|
845
|
+
changedSurfaces,
|
|
846
|
+
proposedAt: (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
847
|
+
findings: [...findings],
|
|
848
|
+
evaluation
|
|
849
|
+
}).value
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
function reviewAgentImprovementProposal(inputProposal, input) {
|
|
853
|
+
const proposal = verifyAgentImprovementProposal(inputProposal);
|
|
854
|
+
if (!input.reviewedBy.trim()) throw new Error("candidate review requires reviewedBy");
|
|
855
|
+
if (!input.reason.trim()) throw new Error("candidate review requires a reason");
|
|
856
|
+
if (input.decision === "approve" && proposal.evaluation.decision.outcome !== "ship") {
|
|
857
|
+
throw new Error("candidate cannot be approved without a passing experiment");
|
|
858
|
+
}
|
|
859
|
+
return agentImprovementReviewSchema.parse(
|
|
860
|
+
canonicalCandidateDocument({
|
|
861
|
+
kind: "agent-improvement-review",
|
|
862
|
+
proposalDigest: proposal.digest,
|
|
863
|
+
decision: input.decision,
|
|
864
|
+
reviewedBy: input.reviewedBy,
|
|
865
|
+
reviewedAt: (input.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
866
|
+
reason: input.reason,
|
|
867
|
+
...input.feedback === void 0 ? {} : { feedback: input.feedback }
|
|
868
|
+
}).value
|
|
869
|
+
);
|
|
870
|
+
}
|
|
871
|
+
function createAgentImprovementActivation(inputProposal, inputReview, options) {
|
|
872
|
+
const proposal = verifyAgentImprovementProposal(inputProposal);
|
|
873
|
+
const review = verifyAgentImprovementReview(inputReview);
|
|
874
|
+
if (review.decision !== "approve" || review.proposalDigest !== proposal.digest) {
|
|
875
|
+
throw new Error("candidate activation requires an approval for the exact proposal");
|
|
876
|
+
}
|
|
877
|
+
if (!options.fundingOwner.trim() || !options.authorizedBy.trim()) {
|
|
878
|
+
throw new Error("candidate activation authority must be non-empty");
|
|
879
|
+
}
|
|
880
|
+
const experiment = proposal.evaluation.experiment;
|
|
881
|
+
assertActivationTargets(proposal.changedSurfaces, experiment, options.targets);
|
|
882
|
+
return agentImprovementActivationSchema.parse(
|
|
883
|
+
canonicalCandidateDocument({
|
|
884
|
+
kind: "agent-improvement-activation",
|
|
885
|
+
proposalDigest: proposal.digest,
|
|
886
|
+
reviewDigest: review.digest,
|
|
887
|
+
experimentDigest: experiment.digest,
|
|
888
|
+
candidateBundleDigest: experiment.candidate.digest,
|
|
889
|
+
targets: options.targets,
|
|
890
|
+
fundingOwner: options.fundingOwner,
|
|
891
|
+
authorizedBy: options.authorizedBy,
|
|
892
|
+
authorizedAt: (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString()
|
|
893
|
+
}).value
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
function verifyAgentImprovementProposal(input) {
|
|
897
|
+
const proposal = verifyCanonicalCandidateDocument(
|
|
898
|
+
agentImprovementProposalSchema.parse(input),
|
|
899
|
+
"agent improvement proposal"
|
|
900
|
+
);
|
|
901
|
+
const evaluation = verifyCandidateExperimentComparison(proposal.evaluation);
|
|
902
|
+
if (evaluation.decision.outcome !== "ship") {
|
|
903
|
+
throw new Error("agent improvement proposal does not contain a passing experiment");
|
|
904
|
+
}
|
|
905
|
+
if (proposal.runId !== evaluation.provenance.runId) {
|
|
906
|
+
throw new Error("proposal runId does not match its measured experiment");
|
|
907
|
+
}
|
|
908
|
+
const changedSurfaces = deriveChangedSurfaces(
|
|
909
|
+
evaluation.experiment.baseline,
|
|
910
|
+
evaluation.experiment.candidate
|
|
911
|
+
);
|
|
912
|
+
if (!sameOrderedValues(proposal.changedSurfaces, changedSurfaces)) {
|
|
913
|
+
throw new Error("proposal changed surfaces do not match its exact experiment");
|
|
914
|
+
}
|
|
915
|
+
assertNoJudgeDerivedProposalFindings(proposal.findings);
|
|
916
|
+
return proposal;
|
|
917
|
+
}
|
|
918
|
+
function verifyAgentImprovementReview(input) {
|
|
919
|
+
return verifyCanonicalCandidateDocument(
|
|
920
|
+
agentImprovementReviewSchema.parse(input),
|
|
921
|
+
"agent improvement review"
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
function verifyAgentImprovementActivation(input) {
|
|
925
|
+
const proposal = verifyAgentImprovementProposal(input.proposal);
|
|
926
|
+
const review = verifyAgentImprovementReview(input.review);
|
|
927
|
+
const activation = verifyCanonicalCandidateDocument(
|
|
928
|
+
agentImprovementActivationSchema.parse(input.activation),
|
|
929
|
+
"agent improvement activation"
|
|
930
|
+
);
|
|
931
|
+
const experiment = proposal.evaluation.experiment;
|
|
932
|
+
if (review.decision !== "approve" || review.proposalDigest !== proposal.digest || activation.proposalDigest !== proposal.digest || activation.reviewDigest !== review.digest || activation.experimentDigest !== experiment.digest || activation.candidateBundleDigest !== experiment.candidate.digest) {
|
|
933
|
+
throw new Error("candidate activation does not bind the measured and approved candidate");
|
|
934
|
+
}
|
|
935
|
+
assertActivationTargets(proposal.changedSurfaces, experiment, activation.targets);
|
|
936
|
+
return activation;
|
|
937
|
+
}
|
|
938
|
+
function verifyCandidateExecutionEvidence(input, options) {
|
|
939
|
+
const experiment = verifyCandidateExperiment(options.experiment);
|
|
940
|
+
const bundle = experiment[options.arm];
|
|
941
|
+
const task = experiment.benchmark.tasks[options.benchmarkCell.taskIndex];
|
|
942
|
+
const index = options.benchmarkCell.taskIndex * experiment.benchmark.suite.reps + options.benchmarkCell.repetition;
|
|
943
|
+
if (!task || options.benchmarkCell.suiteDigest !== experiment.benchmark.suite.digest || options.seed !== experiment.benchmark.suite.seeds[index]) {
|
|
944
|
+
throw new Error("candidate execution evidence points outside its signed experiment");
|
|
945
|
+
}
|
|
946
|
+
const evidence = verifyCanonicalCandidateDocument(
|
|
947
|
+
candidateExecutionEvidenceSchema.parse(input),
|
|
948
|
+
"candidate execution evidence"
|
|
949
|
+
);
|
|
950
|
+
const materialization = verifyCanonicalCandidateDocument(
|
|
951
|
+
agentCandidateMaterializationReceiptSchema.parse(evidence.materializationReceipt),
|
|
952
|
+
"candidate materialization receipt"
|
|
953
|
+
);
|
|
954
|
+
const receipt = verifyCanonicalCandidateDocument(
|
|
955
|
+
agentCandidateRunReceiptSchema.parse(evidence.receipt),
|
|
956
|
+
"candidate run receipt"
|
|
957
|
+
);
|
|
958
|
+
const plan = materialization.executionPlan;
|
|
959
|
+
const cell = plan.material.runCell;
|
|
960
|
+
const attempt = options.attempt ?? 1;
|
|
961
|
+
if (cell.experimentDigest !== experiment.digest || cell.arm !== options.arm || cell.bundleDigest !== bundle.digest || cell.suiteDigest !== experiment.benchmark.suite.digest || cell.taskDigest !== task.digest || cell.taskIndex !== options.benchmarkCell.taskIndex || cell.repetition !== options.benchmarkCell.repetition || cell.seed !== options.seed || cell.attempt !== attempt || canonicalCandidateDigest(omitTopLevelDigest(cell)) !== cell.digest) {
|
|
962
|
+
throw new Error("candidate execution receipt substituted its signed experiment cell");
|
|
963
|
+
}
|
|
964
|
+
assertCapturedInput(
|
|
965
|
+
materialization.benchmark.suite,
|
|
966
|
+
experiment.benchmark.suite,
|
|
967
|
+
"benchmark suite"
|
|
968
|
+
);
|
|
969
|
+
assertCapturedInput(materialization.benchmark.task, task, "benchmark task");
|
|
970
|
+
assertEvidenceMaterialDigest(plan, "candidate execution plan");
|
|
971
|
+
assertEvidenceMaterialDigest(
|
|
972
|
+
materialization.profileActivation.profilePlan,
|
|
973
|
+
"candidate profile plan"
|
|
974
|
+
);
|
|
975
|
+
const expectedProfilePlan = materializeCandidateProfile(
|
|
976
|
+
bundle.profile,
|
|
977
|
+
candidateMaterializerHarness(materialization.harness),
|
|
978
|
+
{ resolvedResources: options.resolvedResources }
|
|
979
|
+
);
|
|
980
|
+
const activation = parseAgentCandidateProfileActivation(
|
|
981
|
+
materialization.profileActivation,
|
|
982
|
+
materialization.profileActivation.profilePlan.digest
|
|
983
|
+
);
|
|
984
|
+
const regeneratedActivation = createAgentCandidateProfileActivation(
|
|
985
|
+
expectedProfilePlan,
|
|
986
|
+
materialization.profileActivation.profilePlan
|
|
987
|
+
);
|
|
988
|
+
if (activation.digest !== regeneratedActivation.digest) {
|
|
989
|
+
throw new Error("candidate profile activation does not match the experiment bundle");
|
|
990
|
+
}
|
|
991
|
+
if (materialization.bundleDigest !== bundle.digest || receipt.bundleDigest !== bundle.digest || receipt.runCellDigest !== cell.digest || receipt.materializationReceiptDigest !== materialization.digest || receipt.executionPlanDigest !== plan.digest) {
|
|
992
|
+
throw new Error("candidate execution evidence does not bind one exact Runtime run");
|
|
993
|
+
}
|
|
994
|
+
assertEvidenceMaterialDigest(receipt.modelSettlement, "candidate model settlement");
|
|
995
|
+
assertEvidenceMaterialDigest(receipt.taskOutcome, "candidate task outcome");
|
|
996
|
+
assertEvidenceMaterialDigest(receipt.benchmarkResult, "candidate benchmark result");
|
|
997
|
+
return immutableCandidateValue(evidence);
|
|
998
|
+
}
|
|
999
|
+
function assertExactExperimentInput(input, experiment, bundle) {
|
|
1000
|
+
const task = experiment.benchmark.tasks[input.benchmarkCell.taskIndex];
|
|
1001
|
+
const index = input.benchmarkCell.taskIndex * experiment.benchmark.suite.reps + input.benchmarkCell.repetition;
|
|
1002
|
+
if (input.experiment.digest !== experiment.digest || input.bundle.digest !== bundle.digest || !task || input.task.digest !== task.digest || input.benchmarkCell.suiteDigest !== experiment.benchmark.suite.digest || input.seed !== experiment.benchmark.suite.seeds[index]) {
|
|
1003
|
+
throw new Error("Runtime received a substituted candidate experiment cell");
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
function assertCapturedInput(captured, expected, label) {
|
|
1007
|
+
const bytes = canonicalCandidateBytes(omitTopLevelDigest(expected));
|
|
1008
|
+
if (captured.digest !== expected.digest || captured.material.sha256 !== expected.digest || captured.material.byteLength !== bytes.byteLength) {
|
|
1009
|
+
throw new Error(`candidate materialization substituted its ${label}`);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
function assertEvidenceMaterialDigest(evidence, label) {
|
|
1013
|
+
const bytes = canonicalCandidateBytes(evidence.material);
|
|
1014
|
+
if (canonicalCandidateDigest(evidence.material) !== evidence.digest || evidence.artifact.sha256 !== evidence.digest || evidence.artifact.byteLength !== bytes.byteLength) {
|
|
1015
|
+
throw new Error(`${label} digest does not match its canonical material`);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
var CHANGED_SURFACE_ORDER = [
|
|
1019
|
+
"prompt",
|
|
1020
|
+
"skills",
|
|
1021
|
+
"tools",
|
|
1022
|
+
"mcp",
|
|
1023
|
+
"hooks",
|
|
1024
|
+
"subagents",
|
|
1025
|
+
"agent-profile",
|
|
1026
|
+
"memory",
|
|
1027
|
+
"code",
|
|
1028
|
+
"knowledge"
|
|
1029
|
+
];
|
|
1030
|
+
function deriveChangedSurfaces(baselineBundle, candidateBundle) {
|
|
1031
|
+
const baseline = improvementSurfaceValues(baselineBundle);
|
|
1032
|
+
const candidate = improvementSurfaceValues(candidateBundle);
|
|
1033
|
+
const changed = /* @__PURE__ */ new Set();
|
|
1034
|
+
for (const surface of CHANGED_SURFACE_ORDER) {
|
|
1035
|
+
if (canonicalCandidateDigest(baseline[surface]) !== canonicalCandidateDigest(candidate[surface])) {
|
|
1036
|
+
changed.add(surface);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
const ordered = CHANGED_SURFACE_ORDER.filter((surface) => changed.has(surface));
|
|
1040
|
+
if (ordered.length === 0) throw new Error("candidate experiment does not change an agent surface");
|
|
1041
|
+
return ordered;
|
|
1042
|
+
}
|
|
1043
|
+
function improvementSurfaceValues(bundle) {
|
|
1044
|
+
const profile = agentCandidateProfileAsAgentProfile(bundle.profile);
|
|
1045
|
+
return {
|
|
1046
|
+
prompt: {
|
|
1047
|
+
prompt: profile.prompt ?? null,
|
|
1048
|
+
instructions: profile.resources?.instructions ?? null
|
|
1049
|
+
},
|
|
1050
|
+
skills: profile.resources?.skills ?? null,
|
|
1051
|
+
tools: {
|
|
1052
|
+
tools: profile.tools ?? null,
|
|
1053
|
+
resources: profile.resources?.tools ?? null
|
|
1054
|
+
},
|
|
1055
|
+
mcp: profile.mcp ?? null,
|
|
1056
|
+
hooks: profile.hooks ?? null,
|
|
1057
|
+
subagents: {
|
|
1058
|
+
subagents: profile.subagents ?? null,
|
|
1059
|
+
resources: profile.resources?.agents ?? null
|
|
1060
|
+
},
|
|
1061
|
+
"agent-profile": { profile: opaqueProfileSlice(profile), execution: bundle.execution },
|
|
1062
|
+
memory: bundle.memory,
|
|
1063
|
+
code: bundle.code,
|
|
1064
|
+
knowledge: bundle.knowledge ?? null
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
function opaqueProfileSlice(profile) {
|
|
1068
|
+
const {
|
|
1069
|
+
prompt: _prompt,
|
|
1070
|
+
tools: _tools,
|
|
1071
|
+
mcp: _mcp,
|
|
1072
|
+
hooks: _hooks,
|
|
1073
|
+
subagents: _subagents,
|
|
1074
|
+
resources,
|
|
1075
|
+
...opaqueProfile
|
|
1076
|
+
} = profile;
|
|
1077
|
+
const {
|
|
1078
|
+
instructions: _instructions,
|
|
1079
|
+
skills: _skills,
|
|
1080
|
+
tools: _resourceTools,
|
|
1081
|
+
agents: _agents,
|
|
1082
|
+
...opaqueResources
|
|
1083
|
+
} = resources ?? {};
|
|
1084
|
+
return {
|
|
1085
|
+
...opaqueProfile,
|
|
1086
|
+
...Object.keys(opaqueResources).length > 0 ? { resources: opaqueResources } : {}
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
function assertActivationTargets(surfaces, experiment, targets) {
|
|
1090
|
+
const expected = new Set(surfaces);
|
|
1091
|
+
const actual = new Set(targets.map((target) => target.surface));
|
|
1092
|
+
const baselineValues = improvementSurfaceValues(experiment.baseline);
|
|
1093
|
+
if (targets.some((target) => !target.identity.trim()) || targets.some(
|
|
1094
|
+
(target) => target.expectedBaseDigest !== expectedActivationBaseDigest(experiment, target.surface, baselineValues)
|
|
1095
|
+
) || expected.size !== actual.size || [...expected].some((surface) => !actual.has(surface))) {
|
|
1096
|
+
throw new Error("candidate activation targets must cover exactly the changed surfaces");
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
function expectedActivationBaseDigest(experiment, surface, baselineValues) {
|
|
1100
|
+
if (surface === "knowledge" && experiment.candidate.knowledge) {
|
|
1101
|
+
return experiment.candidate.knowledge.candidate.baseHash;
|
|
1102
|
+
}
|
|
1103
|
+
return canonicalCandidateDigest(baselineValues[surface]);
|
|
1104
|
+
}
|
|
1105
|
+
function sameOrderedValues(left, right) {
|
|
1106
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
1107
|
+
}
|
|
1108
|
+
function assertNoJudgeDerivedProposalFindings(findings) {
|
|
1109
|
+
const leaked = findings.filter((finding) => finding.derived_from_judge === true);
|
|
1110
|
+
if (leaked.length === 0) return;
|
|
1111
|
+
const identifiers = leaked.map(
|
|
1112
|
+
(finding) => typeof finding.finding_id === "string" ? finding.finding_id : "<unknown>"
|
|
1113
|
+
);
|
|
1114
|
+
throw new Error(
|
|
1115
|
+
`agent improvement proposal findings: judge-derived findings cannot steer an improvement: [${identifiers.join(", ")}]`
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
|
|
655
1119
|
export {
|
|
656
1120
|
improvementDriver,
|
|
657
1121
|
rawTraceDistiller,
|
|
658
1122
|
applyImprovementWinnerToProfile,
|
|
659
|
-
improve
|
|
1123
|
+
improve,
|
|
1124
|
+
AgentCandidateExperimentCellExecutionError,
|
|
1125
|
+
runAgentCandidateExperiment,
|
|
1126
|
+
executeAgentCandidateExperimentCell,
|
|
1127
|
+
createAgentImprovementMeasuredComparison,
|
|
1128
|
+
proposeAgentImprovement,
|
|
1129
|
+
createAgentImprovementProposal,
|
|
1130
|
+
reviewAgentImprovementProposal,
|
|
1131
|
+
createAgentImprovementActivation,
|
|
1132
|
+
verifyAgentImprovementProposal,
|
|
1133
|
+
verifyAgentImprovementReview,
|
|
1134
|
+
verifyAgentImprovementActivation,
|
|
1135
|
+
verifyCandidateExecutionEvidence
|
|
660
1136
|
};
|
|
661
|
-
//# sourceMappingURL=chunk-
|
|
1137
|
+
//# sourceMappingURL=chunk-G55QE4IQ.js.map
|