Move cognition-first interpretation for free-form Russian
CI / test (push) Failing after 14s

This commit is contained in:
m
2026-08-18 16:40:46 +03:00
parent 11a6a23f6e
commit 52074e2895
8 changed files with 312 additions and 193 deletions
@@ -17,6 +17,7 @@ import (
"git.cin.su/m/Assistant/contracts/cognitive"
"git.cin.su/m/Assistant/contracts/identity"
"git.cin.su/m/Assistant/contracts/interaction"
"git.cin.su/m/Assistant/platform/ids"
"git.cin.su/m/Assistant/contracts/situation"
interactiondomain "git.cin.su/m/Assistant/modules/interaction/domain"
)
@@ -74,7 +75,28 @@ func TestLiveInterpretationTrace(t *testing.T) {
now: time.Now,
allowCanary: true,
}
for _, message := range []string{"ты кто", "можешь расказать об утре"} {
for _, message := range []string{
"расскажи как это работает",
"Расскажи, как это работает?",
"можешь объяснить почему база растёт",
"почему postgres использует столько памяти",
"разберись почему сервис упал",
"посмотри что произошло",
"исправь ошибку если найдёшь",
"разберись почему падает и исправь если причина очевидна",
"нет не UPO а UPO2",
"нет не UPO а UPO2 и обнови конфиг",
"postgres сейчас работает",
"основная база называется UPO",
"привет",
"спасибо",
"ты кто",
"ты кто?",
"как тебя зовут",
"кто ты вообще",
"что ты думаешь",
"расскажи подробнее",
} {
conversation := interaction.Conversation{ID: "trace-conversation", ActorID: "trace-actor", PrincipalID: "domovoy-creator-principal", Channel: interaction.ChannelWebChat, State: interaction.ConversationOpen}
utterance, _, _, err := interactiondomain.NewHumanUtterance(conversation, interaction.ChatMessageRequest{Message: message}, time.Now())
if err != nil {
@@ -121,15 +143,27 @@ func TestLiveInterpretationTrace(t *testing.T) {
if rawResponse == "" {
t.Fatalf("message=%q raw response is empty", message)
}
if message == "ты кто" {
if semantic.Interpretation.SpeechAct != interaction.SpeechActQuestion || !semantic.NeedsCognition {
t.Fatalf("semantic path still fails punctuation-free identity question: %+v", semantic.Interpretation)
}
if gatewayResponse.Candidate.PrimarySpeechAct != "QUESTION" {
t.Fatalf("gateway did not preserve question semantics: %+v", gatewayResponse.Candidate)
}
cognitiveCandidate, err := cognitiveCandidateFromGateway(utterance.ID, gatewayResponse.Candidate, time.Now())
if err != nil {
t.Fatal(err)
}
t.Logf("TRACE message=%q deterministic=%s/%s needs_cognition=%t raw=%q gateway_candidate=%+v", message, semantic.Interpretation.SpeechAct, semantic.Interpretation.Applicability, semantic.NeedsCognition, truncate(rawResponse, 180), gatewayResponse.Candidate)
selected := interactiondomain.ApplyCognitiveCandidate(semantic, utterance.Content, cognitiveCandidate, nil)
cognitionUsed := selected.Interpretation.Source == string(interaction.CandidateSourceCognitive)
clarificationReason := string(selected.Interpretation.Clarification)
t.Logf("TRACE message=%q", message)
deterministic := semantic.Candidates[0]
t.Logf(" deterministic candidate: %+v", deterministic)
t.Logf(" raw response=%q", truncate(rawResponse, 180))
t.Logf(" cognitive candidate: %+v", cognitiveCandidate)
t.Logf(" selected interpretation: act=%s secondary=%s selection_source=%s needs_cognition=%t",
selected.Interpretation.SpeechAct,
selected.Interpretation.SecondarySpeechAct,
selected.Interpretation.Source,
selected.Interpretation.NeedsCognition,
)
t.Logf(" cognition used: %t", cognitionUsed)
t.Logf(" clarification reason: %s", clarificationReason)
t.Logf(" reply=%q", selected.Reply)
}
}
@@ -217,3 +251,30 @@ func truncate(value string, max int) string {
}
return value[:max] + "..."
}
func cognitiveCandidateFromGateway(utteranceID interaction.HumanUtteranceID, candidate cognitive.GatewayInterpretationCandidate, now interface{ UnixMilli() int64 }) (interaction.SemanticCandidate, error) {
id, err := ids.New()
if err != nil {
return interaction.SemanticCandidate{}, err
}
capabilityHints := make([]string, 0, len(candidate.CapabilityHints))
for _, hint := range candidate.CapabilityHints {
capabilityHints = append(capabilityHints, string(hint))
}
return interaction.SemanticCandidate{
ID: interaction.SemanticCandidateID(id),
UtteranceID: utteranceID,
Source: interaction.CandidateSourceCognitive,
SelectionState: interaction.CandidateSelected,
PrimarySpeechAct: interaction.SpeechAct(candidate.PrimarySpeechAct),
SecondarySpeechAct: interaction.SpeechAct(candidate.SecondarySpeechAct),
ConfidenceMillis: candidate.ConfidenceMillis,
Applicability: interaction.SemanticApplicability(candidate.Applicability),
RequestedOutcome: candidate.RequestedOutcome,
Clarification: interaction.ClarificationState(candidate.Clarification),
NeedsCognition: candidate.NeedsCognition,
SelectionReason: candidate.SelectionReason,
CapabilityHints: capabilityHints,
RecordedAtUnixMillis: now.UnixMilli(),
}, nil
}
+2 -7
View File
@@ -61,12 +61,7 @@ func (c cognitiveInterpretationClient) Interpret(ctx context.Context, request co
}
func shouldRequestBroaderInterpretation(result interactiondomain.SemanticResult) bool {
switch result.Interpretation.Applicability {
case interaction.SemanticNeedsBroaderInterpret, interaction.SemanticLowConfidence, interaction.SemanticMixedIntent:
return true
default:
return false
}
return interactiondomain.ShouldAttemptCognitive(result)
}
func buildGatewayInterpretationRequest(session identity.CreatorSession, utterance interaction.HumanUtterance, semantic interactiondomain.SemanticResult, projectNames []string) cognitive.GatewayInterpretationRequest {
@@ -122,4 +117,4 @@ func capabilityHintStrings(values []capability.CapabilityKind) []string {
result = append(result, string(value))
}
return result
}
}
+2 -2
View File
@@ -293,7 +293,7 @@ func main() {
http.Error(w, "interpret chat message", http.StatusServiceUnavailable)
return
}
if shouldRequestBroaderInterpretation(semantic) {
if interactiondomain.ShouldAttemptCognitive(semantic) {
projectNames := make([]string, 0, len(semantic.Projects))
for _, ref := range semantic.Projects {
if ref.ProjectDisplayName != "" {
@@ -1170,4 +1170,4 @@ func evidenceRefsToEpistemics(values []work.EvidenceRef) []epistemics.EvidenceRe
result = append(result, epistemics.EvidenceRef(value))
}
return result
}
}