АРЧ АП11 - Архитектура после ге :
This commit is contained in:
@@ -138,10 +138,16 @@ export function createAssistantRoutePolicy(deps) {
|
||||
hasDataRetrievalRequestSignal(repairedRawUserMessage) ||
|
||||
hasDataRetrievalRequestSignal(effectiveAddressUserMessage) ||
|
||||
hasDataRetrievalRequestSignal(repairedEffectiveAddressUserMessage);
|
||||
const analyticsSample = compactWhitespace(`${repairedRawUserMessage} ${repairedEffectiveAddressUserMessage}`.toLowerCase());
|
||||
const colloquialCustomerValueSignal = /(?:\u043a\u0442\u043e|\u043a\u043e\u043c\u0443|customer|client|counterparty)/iu.test(analyticsSample) &&
|
||||
/(?:(?:\u043f\u0440\u0438\u043d\u0435\u0441|\u043f\u0440\u0438\u043d\u0451\u0441|\u0437\u0430\u043d\u0435\u0441|\u0437\u0430\u043d\u0451\u0441).*(?:\u0434\u0435\u043d\u0435\u0433|\u0434\u0435\u043d\u044c\u0433)|(?:\u0434\u0435\u043d\u0435\u0433|\u0434\u0435\u043d\u044c\u0433).*(?:\u043f\u0440\u0438\u043d\u0435\u0441|\u043f\u0440\u0438\u043d\u0451\u0441|\u0437\u0430\u043d\u0435\u0441|\u0437\u0430\u043d\u0451\u0441)|(?:\u0431\u043e\u043b\u044c\u0448\u0435(?:\s+\u0432\u0441\u0435\u0433\u043e)?).*(?:\u0434\u0435\u043d\u0435\u0433|\u0434\u0435\u043d\u044c\u0433))/iu.test(analyticsSample);
|
||||
const turnoverAggregateSignal = /(?:\u043e\u0431\u043e\u0440\u043e\u0442(?:\u044b)?|\u0432\u044b\u0440\u0443\u0447\u043a|\u0434\u043e\u0445\u043e\u0434|turnover|revenue).*(?:\u0437\u0430\s+\d{4}\s+\u0433\u043e\u0434|\u043f\u0435\u0440\u0438\u043e\u0434|\u0433\u043e\u0434|year|month|quarter)/iu.test(analyticsSample);
|
||||
const aggregateBusinessAnalyticsBridgeDetected = colloquialCustomerValueSignal || turnoverAggregateSignal;
|
||||
const aggregateBusinessAnalyticsSignal = hasAggregateBusinessAnalyticsSignal(rawUserMessage) ||
|
||||
hasAggregateBusinessAnalyticsSignal(repairedRawUserMessage) ||
|
||||
hasAggregateBusinessAnalyticsSignal(effectiveAddressUserMessage) ||
|
||||
hasAggregateBusinessAnalyticsSignal(repairedEffectiveAddressUserMessage);
|
||||
hasAggregateBusinessAnalyticsSignal(repairedEffectiveAddressUserMessage) ||
|
||||
aggregateBusinessAnalyticsBridgeDetected;
|
||||
const standaloneAddressTopicSignal = hasStandaloneAddressTopicSignal(rawUserMessage) ||
|
||||
hasStandaloneAddressTopicSignal(repairedRawUserMessage) ||
|
||||
hasStandaloneAddressTopicSignal(effectiveAddressUserMessage) ||
|
||||
@@ -231,33 +237,39 @@ export function createAssistantRoutePolicy(deps) {
|
||||
!capabilityMetaQuery &&
|
||||
!dataRetrievalSignal);
|
||||
const effectiveAddressFollowupSignal = explicitAddressFollowupSignal && !dangerOrCoercionSignal;
|
||||
const baseToolGate = resolveAddressToolGateDecision(effectiveAddressUserMessage, followupContext, llmPreDecomposeMeta, rawUserMessage);
|
||||
const deterministicNonDomainGuard = Boolean(!dataScopeMetaQuery &&
|
||||
!capabilityMetaQuery &&
|
||||
!dataRetrievalSignal &&
|
||||
!aggregateBusinessAnalyticsSignal &&
|
||||
!effectiveAddressFollowupSignal &&
|
||||
resolvedModeDetection.mode === "unsupported" &&
|
||||
resolvedIntentResolution.intent === "unknown");
|
||||
const baseToolGatePreservesAddressLane = Boolean(baseToolGate?.runAddressLane &&
|
||||
["address_intent_resolver_detected", "address_mode_classifier_detected", "address_signal_detected", "llm_canonical_data_signal_detected"].includes(String(baseToolGate?.reason ?? "")));
|
||||
const nonDomainQueryIndexed = Boolean(!llmFirstAddressCandidate &&
|
||||
deterministicNonDomainGuard &&
|
||||
(llmFirstUnsupportedCandidate || llmContractMode === null) &&
|
||||
!baseToolGatePreservesAddressLane &&
|
||||
!protectedInventoryShortFollowup &&
|
||||
!organizationClarificationContinuationDetected);
|
||||
const lastAddressAssistantDebug = sessionItems
|
||||
? findLastAddressAssistantItem(sessionItems)?.debug ?? null
|
||||
: null;
|
||||
const memorySignals = resolveRouteMemorySignals({
|
||||
rawUserMessage,
|
||||
repairedRawUserMessage,
|
||||
effectiveAddressUserMessage,
|
||||
repairedEffectiveAddressUserMessage,
|
||||
const memorySignals = resolveRouteMemorySignals({
|
||||
rawUserMessage,
|
||||
repairedRawUserMessage,
|
||||
effectiveAddressUserMessage,
|
||||
repairedEffectiveAddressUserMessage,
|
||||
dataScopeMetaQuery,
|
||||
capabilityMetaQuery,
|
||||
dataRetrievalSignal,
|
||||
strongDataSignal,
|
||||
aggregateBusinessAnalyticsSignal,
|
||||
lastGroundedAddressDebug,
|
||||
hasPriorAddressDebug: Boolean(lastGroundedAddressDebug || lastAddressAssistantDebug)
|
||||
});
|
||||
strongDataSignal,
|
||||
aggregateBusinessAnalyticsSignal,
|
||||
lastGroundedAddressDebug,
|
||||
hasPriorAddressDebug: Boolean(lastGroundedAddressDebug || lastAddressAssistantDebug),
|
||||
sessionItems
|
||||
});
|
||||
const contextualHistoricalCapabilityFollowupDetected = memorySignals.contextualHistoricalCapabilityFollowupDetected;
|
||||
const contextualMemoryRecapFollowupDetected = memorySignals.contextualMemoryRecapFollowupDetected;
|
||||
const organizationFactLookupDetected = hasOrganizationFactLookupSignal(rawUserMessage) ||
|
||||
@@ -428,6 +440,143 @@ export function createAssistantRoutePolicy(deps) {
|
||||
}
|
||||
};
|
||||
}
|
||||
const supportedExactInvestigativeAddressBypass = Boolean(llmContractMode === "deep_analysis" &&
|
||||
semanticApplyCanonicalRecommended &&
|
||||
strictDeepInvestigationBypassAllowed &&
|
||||
llmContractIntent &&
|
||||
ADDRESS_INTENTS_KEEP_ADDRESS_LANE.has(llmContractIntent));
|
||||
if (supportedExactInvestigativeAddressBypass) {
|
||||
return {
|
||||
runAddressLane: true,
|
||||
toolGateDecision: "run_address_lane",
|
||||
toolGateReason: "address_signal_detected",
|
||||
livingMode: "address_data",
|
||||
livingReason: "address_lane_triggered",
|
||||
orchestrationContract: {
|
||||
schema_version: "assistant_orchestration_contract_v1",
|
||||
hard_meta_mode: null,
|
||||
provider_execution: providerExecution,
|
||||
address_mode: resolvedModeDetection.mode,
|
||||
address_mode_confidence: resolvedModeDetection.confidence,
|
||||
address_intent: resolvedIntentResolution.intent,
|
||||
address_intent_confidence: resolvedIntentResolution.confidence,
|
||||
strong_data_signal_detected: strongDataSignal,
|
||||
data_retrieval_signal_detected: dataRetrievalSignal,
|
||||
semantic_contract_valid: semanticContractValid,
|
||||
semantic_apply_canonical_recommended: semanticApplyCanonicalRecommended,
|
||||
semantic_reason_codes: semanticReasonCodes,
|
||||
semantic_route_arbitration: {
|
||||
supported_address_intent_detected: true,
|
||||
strict_deep_investigation_bypass_allowed: true,
|
||||
semantic_deep_investigation_hint_detected: semanticExtractionContract?.guard_hints?.deep_investigation_signal_detected === true,
|
||||
semantic_aggregate_shape_detected: false,
|
||||
followup_semantic_override_to_deep_allowed: false
|
||||
},
|
||||
followup_context_detected: Boolean(followupContext),
|
||||
unsupported_address_intent_fallback_to_deep: false,
|
||||
deep_analysis_signal_fallback_to_deep: false,
|
||||
aggregate_analytics_signal_fallback_to_deep: false,
|
||||
deep_session_continuation_fallback_to_deep: false,
|
||||
final_decision: {
|
||||
run_address_lane: true,
|
||||
tool_gate_decision: "run_address_lane",
|
||||
tool_gate_reason: "address_signal_detected",
|
||||
living_mode: "address_data",
|
||||
living_reason: "address_lane_triggered"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
if (colloquialCustomerValueSignal) {
|
||||
return {
|
||||
runAddressLane: true,
|
||||
toolGateDecision: "run_address_lane",
|
||||
toolGateReason: "address_signal_detected",
|
||||
livingMode: "address_data",
|
||||
livingReason: "address_lane_triggered",
|
||||
orchestrationContract: {
|
||||
schema_version: "assistant_orchestration_contract_v1",
|
||||
hard_meta_mode: null,
|
||||
provider_execution: providerExecution,
|
||||
address_mode: resolvedModeDetection.mode,
|
||||
address_mode_confidence: resolvedModeDetection.confidence,
|
||||
address_intent: resolvedIntentResolution.intent,
|
||||
address_intent_confidence: resolvedIntentResolution.confidence,
|
||||
strong_data_signal_detected: true,
|
||||
data_retrieval_signal_detected: dataRetrievalSignal,
|
||||
semantic_contract_valid: semanticContractValid,
|
||||
semantic_apply_canonical_recommended: semanticApplyCanonicalRecommended,
|
||||
semantic_reason_codes: semanticReasonCodes,
|
||||
semantic_route_arbitration: {
|
||||
supported_address_intent_detected: true,
|
||||
strict_deep_investigation_bypass_allowed: false,
|
||||
semantic_deep_investigation_hint_detected: false,
|
||||
semantic_aggregate_shape_detected: true,
|
||||
followup_semantic_override_to_deep_allowed: false
|
||||
},
|
||||
followup_context_detected: Boolean(followupContext),
|
||||
unsupported_address_intent_fallback_to_deep: false,
|
||||
deep_analysis_signal_fallback_to_deep: false,
|
||||
aggregate_analytics_signal_fallback_to_deep: false,
|
||||
deep_session_continuation_fallback_to_deep: false,
|
||||
final_decision: {
|
||||
run_address_lane: true,
|
||||
tool_gate_decision: "run_address_lane",
|
||||
tool_gate_reason: "address_signal_detected",
|
||||
living_mode: "address_data",
|
||||
living_reason: "address_lane_triggered"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
const standaloneAggregateAnalyticsFollowupFallback = Boolean(followupContext &&
|
||||
aggregateBusinessAnalyticsBridgeDetected &&
|
||||
llmContractMode === null &&
|
||||
!((resolvedIntentResolution.intent && ADDRESS_INTENTS_KEEP_ADDRESS_LANE.has(resolvedIntentResolution.intent)) ||
|
||||
(llmContractIntent && ADDRESS_INTENTS_KEEP_ADDRESS_LANE.has(llmContractIntent)) ||
|
||||
openContractsAddressSignal));
|
||||
if (standaloneAggregateAnalyticsFollowupFallback) {
|
||||
return {
|
||||
runAddressLane: false,
|
||||
toolGateDecision: "skip_address_lane",
|
||||
toolGateReason: "aggregate_analytics_signal_fallback_to_deep",
|
||||
livingMode: "deep_analysis",
|
||||
livingReason: "aggregate_analytics_signal_fallback_to_deep",
|
||||
orchestrationContract: {
|
||||
schema_version: "assistant_orchestration_contract_v1",
|
||||
hard_meta_mode: null,
|
||||
provider_execution: providerExecution,
|
||||
address_mode: resolvedModeDetection.mode,
|
||||
address_mode_confidence: resolvedModeDetection.confidence,
|
||||
address_intent: resolvedIntentResolution.intent,
|
||||
address_intent_confidence: resolvedIntentResolution.confidence,
|
||||
strong_data_signal_detected: strongDataSignal,
|
||||
data_retrieval_signal_detected: dataRetrievalSignal,
|
||||
semantic_contract_valid: semanticContractValid,
|
||||
semantic_apply_canonical_recommended: semanticApplyCanonicalRecommended,
|
||||
semantic_reason_codes: semanticReasonCodes,
|
||||
semantic_route_arbitration: {
|
||||
supported_address_intent_detected: false,
|
||||
strict_deep_investigation_bypass_allowed: false,
|
||||
semantic_deep_investigation_hint_detected: false,
|
||||
semantic_aggregate_shape_detected: true,
|
||||
followup_semantic_override_to_deep_allowed: true
|
||||
},
|
||||
followup_context_detected: true,
|
||||
unsupported_address_intent_fallback_to_deep: false,
|
||||
deep_analysis_signal_fallback_to_deep: false,
|
||||
aggregate_analytics_signal_fallback_to_deep: true,
|
||||
deep_session_continuation_fallback_to_deep: false,
|
||||
final_decision: {
|
||||
run_address_lane: false,
|
||||
tool_gate_decision: "skip_address_lane",
|
||||
tool_gate_reason: "aggregate_analytics_signal_fallback_to_deep",
|
||||
living_mode: "deep_analysis",
|
||||
living_reason: "aggregate_analytics_signal_fallback_to_deep"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
if (nonDomainQueryIndexed) {
|
||||
return {
|
||||
runAddressLane: false,
|
||||
@@ -458,7 +607,6 @@ export function createAssistantRoutePolicy(deps) {
|
||||
};
|
||||
}
|
||||
const metaAnswerFollowupSignal = metaSignals.metaAnswerFollowupSignal;
|
||||
const baseToolGate = resolveAddressToolGateDecision(effectiveAddressUserMessage, followupContext, llmPreDecomposeMeta, rawUserMessage);
|
||||
const preserveAddressLaneSignal = Boolean((llmPreDecomposeMeta?.llmCanonicalCandidateDetected &&
|
||||
llmPreDecomposeMeta?.applied &&
|
||||
llmContractMode === "address_query") ||
|
||||
@@ -483,6 +631,12 @@ export function createAssistantRoutePolicy(deps) {
|
||||
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
|
||||
@@ -517,8 +671,7 @@ export function createAssistantRoutePolicy(deps) {
|
||||
semanticDeepInvestigationHintDetected ||
|
||||
aggregateBusinessAnalyticsSignal) &&
|
||||
!preserveAddressLaneSignal &&
|
||||
!keepAddressLaneByIntent &&
|
||||
!supportedAddressIntentDetected &&
|
||||
!supportedAddressRouteCandidateDetected &&
|
||||
(!followupContext || followupSemanticOverrideToDeepAllowed));
|
||||
const deepAnalysisPreferenceDetected = Boolean(hasDeepAnalysisPreferenceSignal(rawUserMessage) ||
|
||||
hasDeepAnalysisPreferenceSignal(repairedRawUserMessage) ||
|
||||
@@ -528,6 +681,19 @@ 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 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}`)));
|
||||
@@ -537,17 +703,16 @@ export function createAssistantRoutePolicy(deps) {
|
||||
const deepAnalysisSignalFallbackToDeep = Boolean(baseToolGate?.runAddressLane &&
|
||||
!llmRuntimeUnavailableDetected &&
|
||||
(deepAnalysisPreferenceDetected || semanticDeepInvestigationHintDetected) &&
|
||||
!keepAddressLaneByIntent &&
|
||||
!supportedAddressIntentDetected &&
|
||||
!protectAddressLaneFromFallback &&
|
||||
!vatExplainFollowupSignal &&
|
||||
(!followupContext || !dataRetrievalSignal || followupSemanticOverrideToDeepAllowed));
|
||||
const aggregateAnalyticsFallbackToDeep = Boolean(baseToolGate?.runAddressLane &&
|
||||
!llmRuntimeUnavailableDetected &&
|
||||
aggregateBusinessAnalyticsSignal &&
|
||||
!keepAddressLaneByIntent &&
|
||||
!supportedAddressIntentDetected &&
|
||||
!protectAddressLaneFromFallback &&
|
||||
(!followupContext ||
|
||||
llmContractMode === "unsupported" ||
|
||||
llmContractMode === null ||
|
||||
semanticAggregateShapeDetected ||
|
||||
!semanticApplyCanonicalRecommended ||
|
||||
standaloneAddressTopicSignal));
|
||||
@@ -667,10 +832,11 @@ export function createAssistantRoutePolicy(deps) {
|
||||
semantic_apply_canonical_recommended: semanticApplyCanonicalRecommended,
|
||||
semantic_reason_codes: semanticReasonCodes,
|
||||
semantic_route_arbitration: {
|
||||
supported_address_intent_detected: supportedAddressIntentDetected,
|
||||
supported_address_intent_detected: supportedAddressRouteCandidateDetected,
|
||||
strict_deep_investigation_bypass_allowed: strictDeepInvestigationBypassAllowed,
|
||||
semantic_deep_investigation_hint_detected: semanticDeepInvestigationHintDetected,
|
||||
semantic_aggregate_shape_detected: semanticAggregateShapeDetected,
|
||||
exact_address_intent_protected_from_semantic_deep_hint: exactAddressIntentProtectedFromSemanticDeepHint,
|
||||
followup_semantic_override_to_deep_allowed: followupSemanticOverrideToDeepAllowed
|
||||
},
|
||||
followup_context_detected: Boolean(followupContext),
|
||||
|
||||
Reference in New Issue
Block a user