Prefer current travel context in follow-up answers #329

Merged
m merged 1 commits from codex/chat-semantic-inventory into main 2026-08-25 04:05:01 +00:00
3 changed files with 17 additions and 0 deletions
+3
View File
@@ -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,
@@ -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) {
+7
View File
@@ -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 {