Use local creative fallback when cognition is unavailable #341

Merged
m merged 1 commits from codex/creative-chat-routing into main 2026-08-25 08:49:58 +00:00
3 changed files with 29 additions and 1 deletions
+14 -1
View File
@@ -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
}
+11
View File
@@ -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 {
+4
View File
@@ -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 {