Архитектура: вынести exact-route protection arbitration в assistantRoutePolicy и защитить address lane от ложного deep fallback
This commit is contained in:
@@ -112,6 +112,74 @@ function resolveAddressFallbackToDeepArbitration(input) {
|
||||
deepSessionContinuationFallbackToDeep
|
||||
};
|
||||
}
|
||||
function resolveAddressLaneProtectionArbitration(input) {
|
||||
const {
|
||||
resolvedIntent,
|
||||
llmContractIntent,
|
||||
llmContractMode,
|
||||
strictDeepInvestigationCueDetected,
|
||||
strictDeepInvestigationBypassAllowed,
|
||||
openContractsAddressSignal,
|
||||
keepAddressLaneByIntent,
|
||||
baseToolGateRunAddressLane,
|
||||
baseToolGateReason,
|
||||
semanticExtractionContract,
|
||||
followupContext,
|
||||
rootContextOnlyFollowup,
|
||||
semanticApplyCanonicalRecommended,
|
||||
deepAnalysisPreferenceDetected
|
||||
} = input;
|
||||
const supportedAddressIntentDetected = (!strictDeepInvestigationCueDetected || strictDeepInvestigationBypassAllowed) &&
|
||||
Boolean((resolvedIntent && ADDRESS_INTENTS_KEEP_ADDRESS_LANE.has(resolvedIntent)) ||
|
||||
(llmContractIntent && ADDRESS_INTENTS_KEEP_ADDRESS_LANE.has(llmContractIntent)) ||
|
||||
openContractsAddressSignal);
|
||||
const supportedAddressRouteCandidateDetected = Boolean(supportedAddressIntentDetected ||
|
||||
keepAddressLaneByIntent ||
|
||||
(baseToolGateRunAddressLane &&
|
||||
llmContractMode !== "deep_analysis" &&
|
||||
!strictDeepInvestigationCueDetected &&
|
||||
["address_intent_resolver_detected", "address_mode_classifier_detected", "address_signal_detected", "llm_canonical_data_signal_detected"].includes(String(baseToolGateReason ?? ""))));
|
||||
const semanticGuardHints = semanticExtractionContract?.guard_hints &&
|
||||
typeof semanticExtractionContract.guard_hints === "object"
|
||||
? semanticExtractionContract.guard_hints
|
||||
: null;
|
||||
const semanticExtraction = semanticExtractionContract?.extraction &&
|
||||
typeof semanticExtractionContract.extraction === "object"
|
||||
? semanticExtractionContract.extraction
|
||||
: null;
|
||||
const semanticDeepInvestigationHintDetected = semanticGuardHints?.deep_investigation_signal_detected === true;
|
||||
const semanticAggregateShapeDetected = semanticExtraction?.query_shape === "AGGREGATE_LOOKUP" ||
|
||||
semanticExtraction?.aggregation_profile === "management_profile";
|
||||
const followupSemanticOverrideToDeepAllowed = Boolean(followupContext &&
|
||||
!supportedAddressIntentDetected &&
|
||||
(rootContextOnlyFollowup ||
|
||||
llmContractMode === "unsupported" ||
|
||||
semanticAggregateShapeDetected ||
|
||||
semanticDeepInvestigationHintDetected ||
|
||||
!semanticApplyCanonicalRecommended));
|
||||
const exactAddressIntentProtectedFromSemanticDeepHint = Boolean(supportedAddressRouteCandidateDetected &&
|
||||
llmContractMode === "address_query" &&
|
||||
llmContractIntent &&
|
||||
ADDRESS_INTENTS_KEEP_ADDRESS_LANE.has(llmContractIntent) &&
|
||||
semanticApplyCanonicalRecommended &&
|
||||
!deepAnalysisPreferenceDetected &&
|
||||
!strictDeepInvestigationCueDetected &&
|
||||
!semanticAggregateShapeDetected);
|
||||
const protectAddressLaneFromFallback = Boolean(supportedAddressRouteCandidateDetected &&
|
||||
!deepAnalysisPreferenceDetected &&
|
||||
(exactAddressIntentProtectedFromSemanticDeepHint ||
|
||||
!semanticDeepInvestigationHintDetected ||
|
||||
strictDeepInvestigationBypassAllowed));
|
||||
return {
|
||||
supportedAddressIntentDetected,
|
||||
supportedAddressRouteCandidateDetected,
|
||||
semanticDeepInvestigationHintDetected,
|
||||
semanticAggregateShapeDetected,
|
||||
followupSemanticOverrideToDeepAllowed,
|
||||
exactAddressIntentProtectedFromSemanticDeepHint,
|
||||
protectAddressLaneFromFallback
|
||||
};
|
||||
}
|
||||
export function createAssistantRoutePolicy(deps) {
|
||||
const {
|
||||
repairAddressMojibake,
|
||||
@@ -852,39 +920,6 @@ export function createAssistantRoutePolicy(deps) {
|
||||
hasShortDebtMirrorFollowupSignal(repairedRawUserMessage) ||
|
||||
hasShortDebtMirrorFollowupSignal(repairedEffectiveAddressUserMessage) ||
|
||||
inventoryRootRestatementFollowupDetected);
|
||||
const supportedAddressIntentDetected = (!strictDeepInvestigationCueDetected || strictDeepInvestigationBypassAllowed) &&
|
||||
Boolean((resolvedIntentResolution.intent && ADDRESS_INTENTS_KEEP_ADDRESS_LANE.has(resolvedIntentResolution.intent)) ||
|
||||
(llmContractIntent && ADDRESS_INTENTS_KEEP_ADDRESS_LANE.has(llmContractIntent)) ||
|
||||
openContractsAddressSignal);
|
||||
const supportedAddressRouteCandidateDetected = Boolean(supportedAddressIntentDetected ||
|
||||
keepAddressLaneByIntent ||
|
||||
(baseToolGate?.runAddressLane &&
|
||||
llmContractMode !== "deep_analysis" &&
|
||||
!strictDeepInvestigationCueDetected &&
|
||||
["address_intent_resolver_detected", "address_mode_classifier_detected", "address_signal_detected", "llm_canonical_data_signal_detected"].includes(String(baseToolGate?.reason ?? ""))));
|
||||
const semanticGuardHints = semanticExtractionContract?.guard_hints &&
|
||||
typeof semanticExtractionContract.guard_hints === "object"
|
||||
? semanticExtractionContract.guard_hints
|
||||
: null;
|
||||
const semanticExtraction = semanticExtractionContract?.extraction &&
|
||||
typeof semanticExtractionContract.extraction === "object"
|
||||
? semanticExtractionContract.extraction
|
||||
: null;
|
||||
const semanticDeepInvestigationHintDetected = semanticGuardHints?.deep_investigation_signal_detected === true;
|
||||
const semanticAggregateShapeDetected = semanticExtraction?.query_shape === "AGGREGATE_LOOKUP" ||
|
||||
semanticExtraction?.aggregation_profile === "management_profile";
|
||||
const followupSemanticOverrideToDeepAllowed = Boolean(followupContext &&
|
||||
!supportedAddressIntentDetected &&
|
||||
(rootContextOnlyFollowup ||
|
||||
llmContractMode === "unsupported" ||
|
||||
semanticAggregateShapeDetected ||
|
||||
semanticDeepInvestigationHintDetected ||
|
||||
!semanticApplyCanonicalRecommended));
|
||||
const unsupportedIntentOrMode = (resolvedModeDetection.mode !== "address_query" && resolvedIntentResolution.intent === "unknown") ||
|
||||
llmContractMode === "unsupported" ||
|
||||
(rootContextOnlyFollowup &&
|
||||
resolvedIntentResolution.intent === "unknown" &&
|
||||
(!llmContractIntent || llmContractIntent === "unknown"));
|
||||
const deepAnalysisPreferenceDetected = Boolean(hasDeepAnalysisPreferenceSignal(rawUserMessage) ||
|
||||
hasDeepAnalysisPreferenceSignal(repairedRawUserMessage) ||
|
||||
hasDeepAnalysisPreferenceSignal(effectiveAddressUserMessage) ||
|
||||
@@ -893,19 +928,34 @@ export function createAssistantRoutePolicy(deps) {
|
||||
hasDirectDeepAnalysisSignal(repairedRawUserMessage) ||
|
||||
hasDirectDeepAnalysisSignal(effectiveAddressUserMessage) ||
|
||||
hasDirectDeepAnalysisSignal(repairedEffectiveAddressUserMessage));
|
||||
const exactAddressIntentProtectedFromSemanticDeepHint = Boolean(supportedAddressRouteCandidateDetected &&
|
||||
llmContractMode === "address_query" &&
|
||||
llmContractIntent &&
|
||||
ADDRESS_INTENTS_KEEP_ADDRESS_LANE.has(llmContractIntent) &&
|
||||
semanticApplyCanonicalRecommended &&
|
||||
!deepAnalysisPreferenceDetected &&
|
||||
!strictDeepInvestigationCueDetected &&
|
||||
!semanticAggregateShapeDetected);
|
||||
const protectAddressLaneFromFallback = Boolean(supportedAddressRouteCandidateDetected &&
|
||||
!deepAnalysisPreferenceDetected &&
|
||||
(exactAddressIntentProtectedFromSemanticDeepHint ||
|
||||
!semanticDeepInvestigationHintDetected ||
|
||||
strictDeepInvestigationBypassAllowed));
|
||||
const laneProtectionArbitration = resolveAddressLaneProtectionArbitration({
|
||||
resolvedIntent: resolvedIntentResolution.intent,
|
||||
llmContractIntent,
|
||||
llmContractMode,
|
||||
strictDeepInvestigationCueDetected,
|
||||
strictDeepInvestigationBypassAllowed,
|
||||
openContractsAddressSignal,
|
||||
keepAddressLaneByIntent,
|
||||
baseToolGateRunAddressLane: Boolean(baseToolGate?.runAddressLane),
|
||||
baseToolGateReason: baseToolGate?.reason,
|
||||
semanticExtractionContract,
|
||||
followupContext,
|
||||
rootContextOnlyFollowup,
|
||||
semanticApplyCanonicalRecommended,
|
||||
deepAnalysisPreferenceDetected
|
||||
});
|
||||
const supportedAddressIntentDetected = laneProtectionArbitration.supportedAddressIntentDetected;
|
||||
const supportedAddressRouteCandidateDetected = laneProtectionArbitration.supportedAddressRouteCandidateDetected;
|
||||
const semanticDeepInvestigationHintDetected = laneProtectionArbitration.semanticDeepInvestigationHintDetected;
|
||||
const semanticAggregateShapeDetected = laneProtectionArbitration.semanticAggregateShapeDetected;
|
||||
const followupSemanticOverrideToDeepAllowed = laneProtectionArbitration.followupSemanticOverrideToDeepAllowed;
|
||||
const unsupportedIntentOrMode = (resolvedModeDetection.mode !== "address_query" && resolvedIntentResolution.intent === "unknown") ||
|
||||
llmContractMode === "unsupported" ||
|
||||
(rootContextOnlyFollowup &&
|
||||
resolvedIntentResolution.intent === "unknown" &&
|
||||
(!llmContractIntent || llmContractIntent === "unknown"));
|
||||
const exactAddressIntentProtectedFromSemanticDeepHint = laneProtectionArbitration.exactAddressIntentProtectedFromSemanticDeepHint;
|
||||
const protectAddressLaneFromFallback = laneProtectionArbitration.protectAddressLaneFromFallback;
|
||||
const vatExplainFollowupSignal = Boolean(followupContext &&
|
||||
toNonEmptyString(followupContext.previous_intent) === "vat_payable_forecast" &&
|
||||
/(?:\u043f\u043e\u0447\u0435\u043c\u0443|why).*(?:\u043f\u0440\u043e\u0433\u043d\u043e\u0437|forecast).*(?:\u0443\u043f\u043b\u0430\u0442|payable|\b0\b)/iu.test(compactWhitespace(`${repairedRawUserMessage} ${repairedEffectiveAddressUserMessage}`)));
|
||||
|
||||
Reference in New Issue
Block a user