fix: route source-dependent questions to research
CI / test (push) Successful in 54s
CI / test (pull_request) Successful in 53s

This commit is contained in:
m
2026-08-24 06:29:56 +03:00
parent 5c98bc3568
commit f6f68ffb04
4 changed files with 61 additions and 2 deletions
+17
View File
@@ -405,6 +405,9 @@ func capabilityHintsFor(primary, secondary interaction.SpeechAct, tokens []strin
if primary == interaction.SpeechActQuestion || primary == interaction.SpeechActRequestToInvestigate || secondary == interaction.SpeechActQuestion || secondary == interaction.SpeechActRequestToInvestigate {
add("COGNITIVE_REASONING")
}
if sourceDependentQuestion(primary, secondary, tokens) {
add("WEB_RESEARCH")
}
if containsToken(tokens, "напомни") || containsToken(tokens, "напомин") {
add("SCHEDULE_REMINDER")
}
@@ -446,6 +449,20 @@ func capabilityHintsFor(primary, secondary interaction.SpeechAct, tokens []strin
return values
}
// sourceDependentQuestion identifies semantic classes whose answer depends on
// a current or externally observed source. It intentionally uses no named
// place, person or one-off question branch; when the cue is absent the
// truth-first fallback remains in force.
func sourceDependentQuestion(primary, secondary interaction.SpeechAct, tokens []string) bool {
inquiry := primary == interaction.SpeechActQuestion || primary == interaction.SpeechActRequestToInvestigate || secondary == interaction.SpeechActQuestion || secondary == interaction.SpeechActRequestToInvestigate
if !inquiry {
return false
}
currentCue := containsStemInTokens(tokens, "сейчас", "сегодня", "текущ", "актуаль", "последн", "прямо")
observedStateCue := containsStemInTokens(tokens, "погод", "температур", "осад", "ветер", "курс", "цен", "стоим", "новост", "распис", "событ", "статус", "доступен", "работает", "запущен", "срок")
return currentCue || observedStateCue
}
func informationRequestKind(message string, candidate interaction.SemanticCandidate) interaction.InformationRequestKind {
tokens := semanticTokens(message)
if len(tokens) == 0 {
+19
View File
@@ -133,6 +133,25 @@ func TestInformationRequestsAreClassifiedOnceByInteraction(t *testing.T) {
}
}
func TestSourceDependentQuestionRequestsWebResearchWithoutEntityBranch(t *testing.T) {
candidate := BuildDeterministicCandidate("какая погода в Киеве?", "", time.Unix(10, 0).UnixMilli())
seen := false
for _, hint := range candidate.CapabilityHints {
if hint == "WEB_RESEARCH" {
seen = true
}
}
if !seen {
t.Fatalf("source-dependent question was not routed to WEB_RESEARCH: %+v", candidate)
}
ordinary := BuildDeterministicCandidate("что такое гравитация?", "", time.Unix(10, 0).UnixMilli())
for _, hint := range ordinary.CapabilityHints {
if hint == "WEB_RESEARCH" {
t.Fatalf("ordinary conceptual question was incorrectly routed to WEB_RESEARCH: %+v", ordinary)
}
}
}
func TestDeterministicCandidateKeepsFirstPersonCompletedWorkAsAssertion(t *testing.T) {
candidate := BuildDeterministicCandidate("Я всё уже настроил.", "", time.Unix(10, 0).UnixMilli())
if candidate.PrimarySpeechAct != interaction.SpeechActAssertion {