From 59239635cd50f94e847bdf40c86f3f6b121a8d9c Mon Sep 17 00:00:00 2001 From: Mikhail Date: Tue, 25 Aug 2026 06:59:13 +0300 Subject: [PATCH] Prefer current travel context in follow-up answers --- cmd/core-runtime/main.go | 3 +++ modules/interaction/domain/semantics_test.go | 7 +++++++ modules/interaction/domain/travel.go | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/cmd/core-runtime/main.go b/cmd/core-runtime/main.go index 35e4069..a37dead 100644 --- a/cmd/core-runtime/main.go +++ b/cmd/core-runtime/main.go @@ -872,6 +872,9 @@ func main() { needsCognition = false planningReply = identityReply } + if strings.TrimSpace(planningReply) != "" { + semantic.Reply = planningReply + } log.Printf("chat response final message=%q act=%s deterministic=%s handled=%t fallback=%q planning=%q", utterance.Content, semantic.Interpretation.SpeechAct, deterministicSpeechAct, responseResult.Handled, semantic.Reply, planningReply) response := interaction.ChatMessageResponse{ ConversationID: conversation.ID, diff --git a/modules/interaction/domain/semantics_test.go b/modules/interaction/domain/semantics_test.go index d4ba2f0..a9848e2 100644 --- a/modules/interaction/domain/semantics_test.go +++ b/modules/interaction/domain/semantics_test.go @@ -113,6 +113,13 @@ func TestTravelSearchClarification(t *testing.T) { if got := TravelSearchClarification("Найди билеты, какой ближайший самолёт", contextHistory); got != "Из какого города вылетать в Сочи и на какую дату?" { t.Fatalf("travel destination should be inherited from context, got %q", got) } + noisyContext := []interaction.HumanUtterance{ + {Content: "Как можно добраться до Сочи?"}, + {Content: "Какая погода в Питере?"}, + } + if got := TravelSearchClarification("Найди билеты", noisyContext); got != "Из какого города вылетать в Сочи и на какую дату?" { + t.Fatalf("unrelated weather history must not replace travel destination, got %q", got) + } } func TestInterpretUtteranceDirectiveRecordsOutcomeWithoutExecution(t *testing.T) { diff --git a/modules/interaction/domain/travel.go b/modules/interaction/domain/travel.go index bacb247..08bcb15 100644 --- a/modules/interaction/domain/travel.go +++ b/modules/interaction/domain/travel.go @@ -148,6 +148,9 @@ func TravelSearchClarification(message string, history []interaction.HumanUttera func travelContextDestination(history []interaction.HumanUtterance) string { for index := len(history) - 1; index >= 0; index-- { tokens := semanticTokens(history[index].Content) + if !travelContextCue(tokens) { + continue + } for tokenIndex, token := range tokens { if token != "в" && token != "до" { continue @@ -160,6 +163,10 @@ func travelContextDestination(history []interaction.HumanUtterance) string { return "" } +func travelContextCue(tokens []string) bool { + return travelCue(tokens) || containsStemInTokens(tokens, "добрат", "передвиг", "ехать", "едем", "лететь", "поездк") +} + func capitalizeWord(value string) string { runes := []rune(value) if len(runes) == 0 { -- 2.54.0