Merge the clarify and voice sweep (#228)

chatHistory's doc comment pointed at a line range that had moved. It now names
runTurn's step 6, which survives the next edit. chatHistory and rememberTurn
each built the same dialogue.Turn projection inline; one sessionAsTurn helper
now serves both. The history cap was a bare 3 with no tie to the four turns
both doc comments quote.

The clarify decision points are left untouched. V-577 and V-579 own them.

(V-581)
This commit is contained in:
2026-08-06 02:14:25 +04:00
2 changed files with 22 additions and 13 deletions
+9 -7
View File
@@ -527,20 +527,22 @@ func (h *reactiveHandler) finishClarified(ctx context.Context, dec router.Decisi
return reply
}
// maxCarriedHistory — how many turns of PRIOR history (beyond the immediate
// last turn) rememberTurn carries forward. The session ends up holding this
// many plus the one just-finished turn, so callers describing the total
// depth (chatHistory's doc comment, this one) say "up to 4".
const maxCarriedHistory = 3
// rememberTurn stores this turn as the dialogue session the next follow-up
// inherits from, carrying up to 4 prior turns of history for anaphora. Capped so
// one long conversation can't grow the session unboundedly.
func (h *reactiveHandler) rememberTurn(ctx context.Context, prev *dialogue.Session, dec router.Decision, now time.Time) {
var history []dialogue.Turn
if prev != nil {
history = append(history, dialogue.Turn{
Intent: prev.Intent,
Slots: prev.Slots,
Text: prev.Slots.Text,
})
history = append(history, sessionAsTurn(prev))
maxHist := len(prev.History)
if maxHist > 3 {
maxHist = 3
if maxHist > maxCarriedHistory {
maxHist = maxCarriedHistory
}
history = append(history, prev.History[:maxHist]...)
}
+13 -6
View File
@@ -528,6 +528,17 @@ func (h *reactiveHandler) replySystem(ctx context.Context, dec router.Decision)
}
}
// sessionAsTurn projects a stored session onto the dialogue.Turn shape used in
// history lists. Shared by chatHistory and rememberTurn (clarify.go) so the
// same session is described the same way in both places.
func sessionAsTurn(s *dialogue.Session) dialogue.Turn {
return dialogue.Turn{
Intent: s.Intent,
Slots: s.Slots,
Text: s.Slots.Text,
}
}
// chatHistory collects dialogue turns from the session store for the current
// conversation. Returns prior user utterances (newest last) up to a depth of
// 4 turns. Returns nil when there's no session or no history.
@@ -541,13 +552,9 @@ func (h *reactiveHandler) chatHistory(ctx context.Context) []dialogue.Turn {
return nil
}
// History already includes the immediate prior turn (set by the dialogue
// merge at lines 373-395), plus up to 3 more from deeper history.
// merge in runTurn's step 6, above), plus up to 3 more from deeper history.
out := make([]dialogue.Turn, 0, 1+len(prev.History))
out = append(out, dialogue.Turn{
Intent: prev.Intent,
Slots: prev.Slots,
Text: prev.Slots.Text,
})
out = append(out, sessionAsTurn(prev))
out = append(out, prev.History...)
return out
}