diff --git a/cmd/core-runtime/human_response_gate_test.go b/cmd/core-runtime/human_response_gate_test.go new file mode 100644 index 0000000..1a6c487 --- /dev/null +++ b/cmd/core-runtime/human_response_gate_test.go @@ -0,0 +1,25 @@ +package main + +import "testing" + +func TestShouldInvokeHumanResponseSkipsDeterministicFastPaths(t *testing.T) { + tests := []struct { + name string + stableConversational bool + identityReply string + memoryInstructionReply string + want bool + }{ + {name: "stable conversational", stableConversational: true}, + {name: "identity", identityReply: "Меня зовут Домовой."}, + {name: "memory instruction", memoryInstructionReply: "Запомнил."}, + {name: "ordinary continuity", want: true}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if got := shouldInvokeHumanResponse(test.stableConversational, test.identityReply, test.memoryInstructionReply); got != test.want { + t.Fatalf("shouldInvokeHumanResponse() = %t, want %t", got, test.want) + } + }) + } +} diff --git a/cmd/core-runtime/main.go b/cmd/core-runtime/main.go index 3cefdb6..2eb7f18 100644 --- a/cmd/core-runtime/main.go +++ b/cmd/core-runtime/main.go @@ -753,12 +753,16 @@ func main() { http.Error(w, "save chat semantics", http.StatusInternalServerError) return } - responseResult, responseErr := responseClient.Respond(r.Context(), r.Header.Get("Authorization"), continuity.HumanResponseRequest{ - SourceUtteranceID: string(utterance.ID), - SourceIntentID: string(intent.ID), - Message: effectiveTaskMessage, - RequestedAtUnixMillis: now.UnixMilli(), - }) + var responseResult continuity.HumanResponseResult + var responseErr error + if shouldInvokeHumanResponse(stableConversational, identityReply, memoryInstructionReply) { + responseResult, responseErr = responseClient.Respond(r.Context(), r.Header.Get("Authorization"), continuity.HumanResponseRequest{ + SourceUtteranceID: string(utterance.ID), + SourceIntentID: string(intent.ID), + Message: effectiveTaskMessage, + RequestedAtUnixMillis: now.UnixMilli(), + }) + } if semantic.Interpretation.SpeechAct == interaction.SpeechActCorrection { learning.recordCorrection(r.Context(), correctionLearningInput{Utterance: utterance, Intent: intent, At: now}) } @@ -1723,6 +1727,10 @@ func main() { } } +func shouldInvokeHumanResponse(stableConversational bool, identityReply, memoryInstructionReply string) bool { + return !stableConversational && identityReply == "" && memoryInstructionReply == "" +} + func shouldRunGeneralResearch(kind interaction.InformationRequestKind) bool { return kind == "" || kind == interaction.InformationRequestTimeDifference }