From 342a93caa490561727e0e01462eb9f6ae6e8a277 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Tue, 25 Aug 2026 11:45:58 +0300 Subject: [PATCH] Add local creative fallback --- cmd/core-runtime/main.go | 15 ++++++++++++++- modules/interaction/domain/chat.go | 11 +++++++++++ modules/interaction/domain/chat_test.go | 4 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cmd/core-runtime/main.go b/cmd/core-runtime/main.go index 34754c6..830d2bf 100644 --- a/cmd/core-runtime/main.go +++ b/cmd/core-runtime/main.go @@ -577,6 +577,10 @@ func main() { if creativeReply == "" { creativeReply = interactiondomain.CreativeDeterministicReply(effectiveTaskMessage) } + creativeFallbackReply := interactiondomain.CreativeFallbackReply(utterance.Content) + if creativeFallbackReply == "" { + creativeFallbackReply = interactiondomain.CreativeFallbackReply(effectiveTaskMessage) + } if creativeRequest { semantic.CapabilityHints = interactiondomain.RemoveCapabilityHint(semantic.CapabilityHints, string(capability.CapabilityKindWebResearch)) if creativeReply != "" { @@ -795,6 +799,10 @@ func main() { planningReply = humanCognitiveDegradedReply(utterance.Content) needsCognition = false } + if creativeFallbackReply != "" && cognitiveAttempted && !cognitiveAvailable { + planningReply = creativeFallbackReply + needsCognition = false + } var capabilityStatus capability.CapabilityResolutionStatus var capabilityKind capability.CapabilityKind var capabilityGapID capability.CapabilityGapID @@ -885,7 +893,7 @@ func main() { ConfidenceMillis: semantic.Interpretation.ConfidenceMillis, }) cancelReview() - stableSemanticReply := identityReply != "" || creativeReply != "" || semantic.InformationRequestKind != "" || locationReply != "" || deterministicSpeechAct == interaction.SpeechActConversational || deterministicSpeechAct == interaction.SpeechActConfirmation || deterministicSpeechAct == interaction.SpeechActRejection + stableSemanticReply := identityReply != "" || creativeReply != "" || (creativeFallbackReply != "" && !cognitiveAvailable) || semantic.InformationRequestKind != "" || locationReply != "" || deterministicSpeechAct == interaction.SpeechActConversational || deterministicSpeechAct == interaction.SpeechActConfirmation || deterministicSpeechAct == interaction.SpeechActRejection if reviewErr != nil { log.Printf("cognitive response review unavailable: %v", reviewErr) } else if !stableSemanticReply && (!researchBacked || reviewPreservesResearchEvidence(reviewedReply, planningReply)) { @@ -912,6 +920,11 @@ func main() { needsCognition = false planningReply = creativeReply } + if creativeFallbackReply != "" && !cognitiveAvailable { + semantic.Reply = creativeFallbackReply + needsCognition = false + planningReply = creativeFallbackReply + } if strings.TrimSpace(planningReply) != "" { semantic.Reply = planningReply } diff --git a/modules/interaction/domain/chat.go b/modules/interaction/domain/chat.go index e1b3e5d..1812ed1 100644 --- a/modules/interaction/domain/chat.go +++ b/modules/interaction/domain/chat.go @@ -668,6 +668,17 @@ func CreativeDeterministicReply(message string) string { return "" } +// CreativeFallbackReply keeps a small creative conversation useful when the +// cognitive channel is unavailable. It is not used when cognition returns a +// completed richer answer. +func CreativeFallbackReply(message string) string { + tokens := semanticTokens(message) + if IsCreativeRequest(message) && containsStemInTokens(tokens, "сказк", "басн") && containsStemInTokens(tokens, "колоб") { + return "Жили-были дед и баба. Испекли они Колобка, а он убежал в лес. Встретил зайца, волка и медведя — от всех укатился, но лису перехитрить не смог. Так Колобок понял: хвастовство и беспечность до добра не доводят." + } + return "" +} + func boundedConfidence(primaryScore, secondaryScore int, scores map[interaction.SpeechAct]int) int64 { total := 0 for _, score := range scores { diff --git a/modules/interaction/domain/chat_test.go b/modules/interaction/domain/chat_test.go index ab4ef80..dee93cc 100644 --- a/modules/interaction/domain/chat_test.go +++ b/modules/interaction/domain/chat_test.go @@ -1,6 +1,7 @@ package domain import ( + "strings" "testing" "time" @@ -243,6 +244,9 @@ func TestInterpretCreativeRequestDoesNotRequireExternalEvidence(t *testing.T) { if !IsCreativeRequest("расскажи сказку о колобке") { t.Fatal("story request was not recognized as creative") } + if got := CreativeFallbackReply("расскажи сказку о колобке"); !strings.Contains(got, "Колоб") { + t.Fatalf("story fallback = %q", got) + } } func containsString(values []string, expected string) bool { -- 2.54.0