Add skill governance and runtime routing
This commit is contained in:
1 parent
a900016be4
commit
221e9391e0
71 files changed
+7057
-102
No files matched your search
+123
@@ -480,6 +480,129 @@ async function main(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === "train-prm") {
|
||||
const {
|
||||
getEvalPrmMinLabels,
|
||||
getEvalPrmWeightsPath,
|
||||
} = await import("../config.js");
|
||||
const { getEvalArchiveCollection } = await import("./archive.js");
|
||||
const { queryArchivedReviewLabels } = await import(
|
||||
"./review/label-archive.js"
|
||||
);
|
||||
const {
|
||||
buildPrmTrainingSamples,
|
||||
savePrmModel,
|
||||
trainRidgePrmModel,
|
||||
} = await import("./judges/prm.js");
|
||||
const mongo = await connectMongoForEval();
|
||||
try {
|
||||
const labels = await queryArchivedReviewLabels(mongo.connection, {
|
||||
limit: parsePositiveInteger(getFlagString(flags, "label-limit")),
|
||||
});
|
||||
const minLabels =
|
||||
parsePositiveInteger(getFlagString(flags, "min-labels")) ??
|
||||
getEvalPrmMinLabels();
|
||||
if (labels.length < minLabels && !hasFlag(flags, "force")) {
|
||||
throw new Error(
|
||||
`Not enough review labels for PRM training: ${labels.length}/${minLabels}. Use --force to override.`,
|
||||
);
|
||||
}
|
||||
|
||||
const archiveLimit =
|
||||
parsePositiveInteger(getFlagString(flags, "archive-limit")) ??
|
||||
Math.max(labels.length, minLabels);
|
||||
const archives = await getEvalArchiveCollection(mongo.connection)
|
||||
.find({
|
||||
streamId: {
|
||||
$in: labels.map((label) => label.evalStreamId),
|
||||
},
|
||||
})
|
||||
.sort({ evaluatedAt: -1 })
|
||||
.limit(archiveLimit)
|
||||
.toArray();
|
||||
const samples = buildPrmTrainingSamples(labels, archives);
|
||||
if (samples.length < minLabels && !hasFlag(flags, "force")) {
|
||||
throw new Error(
|
||||
`Not enough joined PRM samples: ${samples.length}/${minLabels}. Use --force to override.`,
|
||||
);
|
||||
}
|
||||
|
||||
const outputPath =
|
||||
getFlagString(flags, "output") ?? getEvalPrmWeightsPath();
|
||||
if (!outputPath) {
|
||||
throw new Error(
|
||||
"Missing PRM output path. Set --output or EVAL_PRM_WEIGHTS_PATH.",
|
||||
);
|
||||
}
|
||||
|
||||
const model = trainRidgePrmModel(samples, {
|
||||
lambda: parsePositiveNumber(getFlagString(flags, "lambda")),
|
||||
});
|
||||
savePrmModel(outputPath, model);
|
||||
console.info(
|
||||
`[eval] prm trained labels=${labels.length} archives=${archives.length} samples=${samples.length} output=${outputPath}`,
|
||||
);
|
||||
} finally {
|
||||
await mongo.close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === "train-router") {
|
||||
const {
|
||||
getAgentRouterWeightsPath,
|
||||
getEvalPrmMinLabels,
|
||||
} = await import("../config.js");
|
||||
const { getEvalArchiveCollection } = await import("./archive.js");
|
||||
const { buildRouterTrainingSamples } = await import("./router-training.js");
|
||||
const {
|
||||
saveLearnedRouterModel,
|
||||
trainLearnedRouterModel,
|
||||
} = await import("@skills/onboarding/runtime/router");
|
||||
const mongo = await connectMongoForEval();
|
||||
try {
|
||||
const archiveLimit =
|
||||
parsePositiveInteger(getFlagString(flags, "archive-limit")) ??
|
||||
parsePositiveInteger(getFlagString(flags, "limit")) ??
|
||||
5_000;
|
||||
const minSamples =
|
||||
parsePositiveInteger(getFlagString(flags, "min-samples")) ??
|
||||
getEvalPrmMinLabels();
|
||||
const archives = await getEvalArchiveCollection(mongo.connection)
|
||||
.find({})
|
||||
.sort({ evaluatedAt: -1 })
|
||||
.limit(archiveLimit)
|
||||
.toArray();
|
||||
const samples = buildRouterTrainingSamples(archives);
|
||||
if (samples.length < minSamples && !hasFlag(flags, "force")) {
|
||||
throw new Error(
|
||||
`Not enough router training samples: ${samples.length}/${minSamples}. Use --force to override.`,
|
||||
);
|
||||
}
|
||||
|
||||
const outputPath =
|
||||
getFlagString(flags, "output") ?? getAgentRouterWeightsPath();
|
||||
if (!outputPath) {
|
||||
throw new Error(
|
||||
"Missing router output path. Set --output or AGENT_ROUTER_WEIGHTS_PATH.",
|
||||
);
|
||||
}
|
||||
|
||||
const model = trainLearnedRouterModel(samples, {
|
||||
epochs: parsePositiveInteger(getFlagString(flags, "epochs")),
|
||||
learningRate: parsePositiveNumber(getFlagString(flags, "learning-rate")),
|
||||
l2: parsePositiveNumber(getFlagString(flags, "l2")),
|
||||
});
|
||||
saveLearnedRouterModel(outputPath, model);
|
||||
console.info(
|
||||
`[eval] router trained archives=${archives.length} samples=${samples.length} output=${outputPath}`,
|
||||
);
|
||||
} finally {
|
||||
await mongo.close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === "propose") {
|
||||
const { createEvalLlmClient } = await import("./runner.js");
|
||||
const {
|
||||
|
||||
Reference in new issue
Block a user