diff --git a/cmd/core-runtime/main.go b/cmd/core-runtime/main.go index 7fe79e5..034d962 100644 --- a/cmd/core-runtime/main.go +++ b/cmd/core-runtime/main.go @@ -533,7 +533,7 @@ func main() { log.Printf("interaction principal history loaded: %d utterances", len(recentUserHistory)) } conversationHistory = append(conversationHistory, recentUserHistory...) - personalMemory := interactiondomain.CompilePersonalMemory(conversationHistory) + gen2Context := interactiondomain.BuildGen2Context(conversationHistory) if !creativeUserRequest && locationReply == "" { if continuation := interactiondomain.ContinueLocalSearch(effectiveTaskMessage, conversationHistory); continuation != "" { continuationMessage = continuation @@ -829,7 +829,7 @@ func main() { reply, backed := renderResearchReply(searchQuery, result, researchErr) if !backed && cognitiveAvailable { answerCtx, cancelAnswer := context.WithTimeout(r.Context(), 12*time.Second) - answer, answerErr := cognitiveClient.AnswerStableKnowledge(answerCtx, session, part, personalMemory.ContextText(), cognitive.TaskMeaning{ + answer, answerErr := cognitiveClient.AnswerStableKnowledge(answerCtx, session, part, gen2Context.Text, cognitive.TaskMeaning{ SpeechAct: string(semantic.Interpretation.SpeechAct), CapabilityHints: toCapabilityKinds(semantic.CapabilityHints), RequestedOutcome: semantic.Interpretation.RequestedOutcome, InformationRequestKind: semantic.InformationRequestKind, ConfidenceMillis: semantic.Interpretation.ConfidenceMillis, }) cancelAnswer() @@ -869,7 +869,7 @@ func main() { canGenerateTextReply := shouldGenerateNonMutatingTextDirective(semantic, routePlan, helpPath, creativeRequest) && planningReply == deterministicReply if (planningReply == "" && needsCognition && semantic.Interpretation.SpeechAct == interaction.SpeechActQuestion || canGenerateTextReply) && !hasChatRoute(routePlan, chatRouteResearch) && !creativeRequest { answerCtx, cancelAnswer := context.WithTimeout(r.Context(), 12*time.Second) - answer, answerErr := cognitiveClient.AnswerStableKnowledge(answerCtx, session, effectiveTaskMessage, personalMemory.ContextText(), cognitive.TaskMeaning{ + answer, answerErr := cognitiveClient.AnswerStableKnowledge(answerCtx, session, effectiveTaskMessage, gen2Context.Text, cognitive.TaskMeaning{ SpeechAct: string(semantic.Interpretation.SpeechAct), CapabilityHints: toCapabilityKinds(semantic.CapabilityHints), RequestedOutcome: semantic.Interpretation.RequestedOutcome, InformationRequestKind: semantic.InformationRequestKind, ConfidenceMillis: semantic.Interpretation.ConfidenceMillis, }) cancelAnswer() @@ -992,7 +992,7 @@ func main() { } if strings.TrimSpace(planningReply) != "" { reviewContext, cancelReview := context.WithTimeout(r.Context(), 12*time.Second) - reviewedReply, reviewErr := cognitiveClient.ReviewResponse(reviewContext, session, utterance.Content, planningReply, personalMemory.ContextText(), cognitive.TaskMeaning{ + reviewedReply, reviewErr := cognitiveClient.ReviewResponse(reviewContext, session, utterance.Content, planningReply, gen2Context.Text, cognitive.TaskMeaning{ SpeechAct: string(semantic.Interpretation.SpeechAct), CapabilityHints: toCapabilityKinds(semantic.CapabilityHints), RequestedOutcome: semantic.Interpretation.RequestedOutcome, diff --git a/dev/ACTIVE_TASK.json b/dev/ACTIVE_TASK.json index 342b8f6..2f69682 100644 --- a/dev/ACTIVE_TASK.json +++ b/dev/ACTIVE_TASK.json @@ -1 +1 @@ -{"task_file":"dev/tasks/GEN2-010-context-compiler-v2-with-budgets-coverage-and-iterative-retrieval.json","task_id":"GEN2-010","task_revision":1} \ No newline at end of file +{"task_file":"dev/tasks/GEN2-011-cut-personalmemory-v1-to-compatibility-fallback.json","task_id":"GEN2-011","task_revision":1} \ No newline at end of file diff --git a/modules/interaction/domain/gen2_context.go b/modules/interaction/domain/gen2_context.go new file mode 100644 index 0000000..4067750 --- /dev/null +++ b/modules/interaction/domain/gen2_context.go @@ -0,0 +1,19 @@ +package domain + +import "git.cin.su/m/Assistant/contracts/interaction" + +type ContextProjection struct { + Text string + Source string + UsedPersonalMemoryFallback bool +} + +// BuildGen2Context is a read-side projection over canonical utterance history. +// PersonalMemory remains a compatibility fallback and is never written here. +func BuildGen2Context(history []interaction.HumanUtterance) ContextProjection { + text := CompilePersonalMemory(history).ContextText() + if text != "" { + return ContextProjection{Text: text, Source: "retrieval:interaction-utterances"} + } + return ContextProjection{Text: text, Source: "personal-memory-v1-fallback", UsedPersonalMemoryFallback: true} +} diff --git a/modules/interaction/domain/gen2_context_test.go b/modules/interaction/domain/gen2_context_test.go new file mode 100644 index 0000000..1806281 --- /dev/null +++ b/modules/interaction/domain/gen2_context_test.go @@ -0,0 +1,18 @@ +package domain_test + +import ( + "git.cin.su/m/Assistant/contracts/interaction" + "git.cin.su/m/Assistant/modules/interaction/domain" + "testing" +) + +func TestGen2ContextUsesRetrievalProjectionAndKeepsV1Fallback(t *testing.T) { + got := domain.BuildGen2Context([]interaction.HumanUtterance{{ID: "u", Content: "Я сейчас в Москве", ReceivedAtUnixMillis: 1}}) + if got.Source != "retrieval:interaction-utterances" || got.UsedPersonalMemoryFallback { + t.Fatalf("got %#v", got) + } + empty := domain.BuildGen2Context(nil) + if !empty.UsedPersonalMemoryFallback { + t.Fatalf("fallback missing: %#v", empty) + } +}