Planner Autonomy: добавить verdict выравнивания catalog chain

This commit is contained in:
2026-05-01 14:43:05 +03:00
parent ea96df9ca1
commit 417b51096e
11 changed files with 92 additions and 4 deletions
@@ -8,6 +8,8 @@ export interface AssistantMcpDiscoveryDebugAttachmentFields {
mcp_discovery_bridge_status: string | null;
mcp_discovery_selected_chain_id: string | null;
mcp_discovery_catalog_chain_template_matches: string[];
mcp_discovery_catalog_chain_top_match: string | null;
mcp_discovery_catalog_chain_selected_matches_top: boolean;
mcp_discovery_answer_mode: string | null;
mcp_discovery_business_fact_answer_allowed: boolean;
mcp_discovery_user_facing_response_allowed: boolean;
@@ -73,6 +75,7 @@ export function buildAssistantMcpDiscoveryDebugAttachmentFields(
const entryPoint = resolveEntryPoint(input);
const bridge = toRecordObject(entryPoint?.bridge);
const planner = toRecordObject(bridge?.planner);
const chainAlignment = toRecordObject(planner?.catalog_chain_template_alignment);
const answerDraft = toRecordObject(bridge?.answer_draft);
return {
@@ -83,6 +86,8 @@ export function buildAssistantMcpDiscoveryDebugAttachmentFields(
mcp_discovery_bridge_status: toNonEmptyString(bridge?.bridge_status),
mcp_discovery_selected_chain_id: toNonEmptyString(planner?.selected_chain_id),
mcp_discovery_catalog_chain_template_matches: toStringArray(planner?.catalog_chain_template_matches),
mcp_discovery_catalog_chain_top_match: toNonEmptyString(chainAlignment?.top_chain_template_match),
mcp_discovery_catalog_chain_selected_matches_top: chainAlignment?.selected_chain_matches_top === true,
mcp_discovery_answer_mode: toNonEmptyString(answerDraft?.answer_mode),
mcp_discovery_business_fact_answer_allowed: bridge?.business_fact_answer_allowed === true,
mcp_discovery_user_facing_response_allowed: bridge?.user_facing_response_allowed === true,
@@ -38,6 +38,14 @@ export interface AssistantMcpDiscoveryMetadataSurfaceRef {
ambiguity_entity_sets: string[];
}
export interface AssistantMcpDiscoveryCatalogChainTemplateAlignment {
top_chain_template_match: AssistantMcpCatalogChainTemplateId | null;
selected_chain_template_rank: number | null;
selected_chain_is_catalog_template: boolean;
selected_chain_in_catalog_matches: boolean;
selected_chain_matches_top: boolean;
}
export type AssistantMcpDiscoveryChainId =
| "metadata_inspection"
| "catalog_drilldown"
@@ -71,6 +79,7 @@ export interface AssistantMcpDiscoveryPlannerContract {
selected_chain_id: AssistantMcpDiscoveryChainId;
selected_chain_summary: string;
catalog_chain_template_matches: AssistantMcpCatalogChainTemplateId[];
catalog_chain_template_alignment: AssistantMcpDiscoveryCatalogChainTemplateAlignment;
proposed_primitives: AssistantMcpDiscoveryPrimitive[];
required_axes: string[];
discovery_plan: AssistantMcpDiscoveryPlanContract;
@@ -555,6 +564,21 @@ function catalogChainTemplateMatchesForContract(
});
}
function catalogChainTemplateAlignmentForContract(
recipe: PlannerRecipe,
matches: AssistantMcpCatalogChainTemplateId[]
): AssistantMcpDiscoveryCatalogChainTemplateAlignment {
const selectedChainIsCatalogTemplate = recipe.chainId !== "metadata_lane_clarification";
const selectedIndex = matches.indexOf(recipe.chainId as AssistantMcpCatalogChainTemplateId);
return {
top_chain_template_match: matches[0] ?? null,
selected_chain_template_rank: selectedIndex >= 0 ? selectedIndex + 1 : null,
selected_chain_is_catalog_template: selectedChainIsCatalogTemplate,
selected_chain_in_catalog_matches: selectedIndex >= 0,
selected_chain_matches_top: selectedIndex === 0
};
}
function routeFamilyFromThinMetadataSurfaceInput(
input: AssistantMcpDiscoveryPlannerInput
): AssistantMcpDiscoveryMetadataRouteFamily | null {
@@ -1216,6 +1240,7 @@ export function planAssistantMcpDiscovery(
const dataNeedGraph = input.dataNeedGraph ?? null;
const metadataSurface = input.metadataSurface ?? null;
const catalogChainTemplateMatches = catalogChainTemplateMatchesForContract(input, recipe);
const catalogChainTemplateAlignment = catalogChainTemplateAlignmentForContract(recipe, catalogChainTemplateMatches);
const reasonCodes: string[] = [];
pushReason(reasonCodes, recipe.reason);
for (const reason of recipe.extraReasons ?? []) {
@@ -1283,6 +1308,7 @@ export function planAssistantMcpDiscovery(
selected_chain_id: recipe.chainId,
selected_chain_summary: recipe.chainSummary,
catalog_chain_template_matches: catalogChainTemplateMatches,
catalog_chain_template_alignment: catalogChainTemplateAlignment,
proposed_primitives: recipe.primitives,
required_axes: recipe.axes,
discovery_plan: plan,
@@ -46,6 +46,7 @@ export interface AssistantMcpDiscoveryLoopStateContract {
loop_status: AssistantMcpDiscoveryLoopStatus;
selected_chain_id: AssistantMcpDiscoveryChainId;
catalog_chain_template_matches: AssistantMcpDiscoveryPlannerContract["catalog_chain_template_matches"];
catalog_chain_template_alignment: AssistantMcpDiscoveryPlannerContract["catalog_chain_template_alignment"];
pilot_scope: AssistantMcpDiscoveryPilotExecutionContract["pilot_scope"];
asked_domain_family: string | null;
asked_action_family: string | null;
@@ -179,6 +180,7 @@ function buildLoopState(
loop_status: loopStatusFor(bridgeStatus),
selected_chain_id: planner.selected_chain_id,
catalog_chain_template_matches: [...planner.catalog_chain_template_matches],
catalog_chain_template_alignment: planner.catalog_chain_template_alignment,
pilot_scope: pilot.pilot_scope,
asked_domain_family: planner.discovery_plan.turn_meaning_ref?.asked_domain_family ?? null,
asked_action_family: planner.discovery_plan.turn_meaning_ref?.asked_action_family ?? null,