From 29217ca93509860adc5afb9b11eff2941667f45e Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sun, 30 Aug 2026 00:34:30 +0300 Subject: [PATCH] classify stable acknowledgements before continuation --- modules/interaction/domain/chat.go | 13 +++++++++++++ modules/interaction/domain/chat_test.go | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/modules/interaction/domain/chat.go b/modules/interaction/domain/chat.go index 39c7f74..b42e66d 100644 --- a/modules/interaction/domain/chat.go +++ b/modules/interaction/domain/chat.go @@ -278,6 +278,7 @@ func semanticScores(tokens []string, hasQuestionMark bool, explicitCorrection bo } questionWords := map[string]struct{}{"кто": {}, "что": {}, "как": {}, "почему": {}, "зачем": {}, "где": {}, "когда": {}, "сколько": {}, "какой": {}, "какая": {}, "какие": {}, "чей": {}} conversationWords := []string{"привет", "здравствуйте", "спасибо", "ку", "здравствуй"} + confirmationWords := []string{"хорошо", "ладно", "окей", "ок", "понял", "понятно"} investigateStems := []string{"разбер", "проверь", "проанализ", "исслед", "выясн", "уточн", "подум", "понят", "посмотри", "попроб", "повтор", "снов"} directiveStems := []string{"сдел", "запуст", "созд", "настро", "добав", "измени", "помен", "использ", "удал", "напом", "подключ", "исправ", "обрати", "спрос", "найд", "посчитай", "рассчитай", "ответь", "вывед"} explanatoryRequestStems := []string{"расска", "раска", "объяс", "опиш", "покаж", "подскаж", "сообщ"} @@ -292,6 +293,9 @@ func semanticScores(tokens []string, hasQuestionMark bool, explicitCorrection bo if containsStem(token, conversationWords...) { scores[interaction.SpeechActConversational] += 3 } + if containsExactToken(token, confirmationWords...) { + scores[interaction.SpeechActConfirmation] += 3 + } if containsStem(token, investigateStems...) { scores[interaction.SpeechActRequestToInvestigate] += 3 scores[interaction.SpeechActQuestion]++ @@ -810,6 +814,15 @@ func containsStem(token string, stems ...string) bool { return false } +func containsExactToken(token string, words ...string) bool { + for _, word := range words { + if token == word { + return true + } + } + return false +} + func containsStemInTokens(tokens []string, stems ...string) bool { for _, token := range tokens { if containsStem(token, stems...) { diff --git a/modules/interaction/domain/chat_test.go b/modules/interaction/domain/chat_test.go index c9ac96a..995569a 100644 --- a/modules/interaction/domain/chat_test.go +++ b/modules/interaction/domain/chat_test.go @@ -314,6 +314,18 @@ func TestRememberedPreferenceIsNotRenderedAsIdentity(t *testing.T) { } } +func TestStableAcknowledgementsDoNotBecomeTravelRequests(t *testing.T) { + for _, message := range []string{"Хорошо", "Ладно", "Понял"} { + candidate := BuildDeterministicCandidate(message, "", time.Unix(10, 0).UnixMilli()) + if candidate.PrimarySpeechAct != interaction.SpeechActConfirmation { + t.Fatalf("%q: expected confirmation, got %s", message, candidate.PrimarySpeechAct) + } + if reply, stable := StableConversationalReply(message, candidate.PrimarySpeechAct); !stable || reply != "Хорошо." { + t.Fatalf("%q: stable reply = %q, %t", message, reply, stable) + } + } +} + func TestCreativeRequestsDoNotRouteToWebResearch(t *testing.T) { for _, message := range []string{"нарисуй круг", "расскажи сказку о колобке"} { candidate := BuildDeterministicCandidate(message, "", time.Now().UnixMilli())