Planner Autonomy: ранжировать catalog chain templates

This commit is contained in:
2026-05-01 14:02:55 +03:00
parent ccfa9283e9
commit 4dcffef7d6
8 changed files with 190 additions and 2 deletions
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.ASSISTANT_MCP_CATALOG_PLAN_REVIEW_SCHEMA_VERSION = exports.ASSISTANT_MCP_CATALOG_INDEX_SCHEMA_VERSION = void 0;
exports.searchAssistantMcpCatalogPrimitivesByDecompositionCandidates = searchAssistantMcpCatalogPrimitivesByDecompositionCandidates;
exports.searchAssistantMcpCatalogPrimitivesByFactAxis = searchAssistantMcpCatalogPrimitivesByFactAxis;
exports.searchAssistantMcpCatalogChainTemplatesByFactAxis = searchAssistantMcpCatalogChainTemplatesByFactAxis;
exports.searchAssistantMcpCatalogPrimitivesByMetadataSurface = searchAssistantMcpCatalogPrimitivesByMetadataSurface;
exports.buildAssistantMcpCatalogIndex = buildAssistantMcpCatalogIndex;
exports.getAssistantMcpCatalogPrimitive = getAssistantMcpCatalogPrimitive;
@@ -700,6 +701,53 @@ function searchAssistantMcpCatalogPrimitivesByFactAxis(input) {
.sort((left, right) => right.score - left.score)
.map((item) => item.primitive);
}
function searchAssistantMcpCatalogChainTemplatesByFactAxis(input) {
const requiredAxisSet = toStringSet(input.required_axes ?? []);
const desiredTags = tagSetFromFactAxisInput({
business_fact_family: input.business_fact_family,
action_family: input.action_family,
required_axes: input.required_axes,
comparison_need: input.comparison_need,
ranking_need: input.ranking_need,
aggregation_need: input.aggregation_need
});
const scored = [];
for (const template of CHAIN_TEMPLATES) {
const factMatch = matchesPlanningToken(input.business_fact_family, template.supported_fact_families);
const actionMatch = matchesPlanningToken(input.action_family, template.supported_action_families);
const tagMatches = template.planning_tags.filter((tag) => desiredTags.has(normalizePlanningToken(tag)));
const axisOverlap = template.base_required_axes.filter((axis) => requiredAxisSet.has(axis)).length;
let score = 0;
if (factMatch) {
score += 8;
}
if (actionMatch) {
score += 5;
}
score += tagMatches.length * 2;
score += axisOverlap;
if (input.comparison_need && template.planning_tags.some((tag) => normalizePlanningToken(tag) === "comparison")) {
score += 6;
}
if (input.ranking_need && template.planning_tags.some((tag) => normalizePlanningToken(tag) === "ranking")) {
score += 6;
}
if (input.aggregation_need === "by_month" &&
template.planning_tags.some((tag) => normalizePlanningToken(tag) === "monthly_aggregation")) {
score += 4;
}
if (score <= 0) {
continue;
}
scored.push({
chainId: template.chain_id,
score
});
}
return scored
.sort((left, right) => right.score - left.score)
.map((item) => item.chainId);
}
function searchAssistantMcpCatalogPrimitivesByMetadataSurface(input) {
const allowAggregateByAxis = input.allow_aggregate_by_axis !== false;
const requiredAxisSet = toStringSet(input.required_axes ?? []);
@@ -278,6 +278,20 @@ function selectPrimitivesFromGraphAndCatalog(input) {
if (factAxisPrimitives.length > 0) {
reasonCodes.push("planner_selected_catalog_primitives_from_fact_axis_search");
}
const chainTemplateMatches = input.dataNeedGraph
? (0, assistantMcpCatalogIndex_1.searchAssistantMcpCatalogChainTemplatesByFactAxis)({
business_fact_family: input.dataNeedGraph.business_fact_family,
action_family: input.actionFamily ?? input.dataNeedGraph.action_family,
required_axes: input.requiredAxes,
comparison_need: input.dataNeedGraph.comparison_need,
ranking_need: input.dataNeedGraph.ranking_need,
aggregation_need: input.dataNeedGraph.aggregation_need
})
: [];
if (chainTemplateMatches.length > 0) {
reasonCodes.push("planner_scored_catalog_chain_templates_from_fact_axis");
reasonCodes.push(`planner_catalog_chain_template_search_top_${chainTemplateMatches[0]}`);
}
const combinedCatalogPrimitives = [];
for (const primitive of decompositionPrimitives) {
if (!combinedCatalogPrimitives.includes(primitive)) {