Planner Autonomy: ранжировать catalog chain templates
This commit is contained in:
@@ -622,6 +622,15 @@ export interface AssistantMcpCatalogFactAxisSearchInput {
|
||||
allow_aggregate_by_axis?: boolean;
|
||||
}
|
||||
|
||||
export interface AssistantMcpCatalogChainTemplateSearchInput {
|
||||
business_fact_family?: string | null;
|
||||
action_family?: string | null;
|
||||
required_axes?: string[];
|
||||
comparison_need?: string | null;
|
||||
ranking_need?: string | null;
|
||||
aggregation_need?: string | null;
|
||||
}
|
||||
|
||||
export interface AssistantMcpCatalogPrimitiveSearchInput {
|
||||
decomposition_candidates: string[];
|
||||
allow_aggregate_by_axis?: boolean;
|
||||
@@ -847,6 +856,62 @@ export function searchAssistantMcpCatalogPrimitivesByFactAxis(
|
||||
.map((item) => item.primitive);
|
||||
}
|
||||
|
||||
export function searchAssistantMcpCatalogChainTemplatesByFactAxis(
|
||||
input: AssistantMcpCatalogChainTemplateSearchInput
|
||||
): AssistantMcpCatalogChainTemplateId[] {
|
||||
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: Array<{ chainId: AssistantMcpCatalogChainTemplateId; score: number }> = [];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
export function searchAssistantMcpCatalogPrimitivesByMetadataSurface(
|
||||
input: AssistantMcpCatalogMetadataSurfaceSearchInput
|
||||
): AssistantMcpDiscoveryPrimitive[] {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
} from "./assistantMcpDiscoveryPolicy";
|
||||
import {
|
||||
getAssistantMcpCatalogChainTemplate,
|
||||
searchAssistantMcpCatalogChainTemplatesByFactAxis,
|
||||
searchAssistantMcpCatalogPrimitivesByDecompositionCandidates,
|
||||
searchAssistantMcpCatalogPrimitivesByFactAxis,
|
||||
searchAssistantMcpCatalogPrimitivesByMetadataSurface,
|
||||
@@ -457,6 +458,21 @@ function selectPrimitivesFromGraphAndCatalog(input: {
|
||||
reasonCodes.push("planner_selected_catalog_primitives_from_fact_axis_search");
|
||||
}
|
||||
|
||||
const chainTemplateMatches = input.dataNeedGraph
|
||||
? 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: AssistantMcpDiscoveryPrimitive[] = [];
|
||||
for (const primitive of decompositionPrimitives) {
|
||||
if (!combinedCatalogPrimitives.includes(primitive)) {
|
||||
|
||||
Reference in New Issue
Block a user