sweep: dedup session->Turn conversion, fix drifted line reference (V-581)
chatHistory (voice.go) and rememberTurn (clarify.go) both built the same
dialogue.Turn{Intent, Slots, Text} projection of a *dialogue.Session
inline; factor it into sessionAsTurn and use it in both. Also name the
history-depth cap (previously a bare "3") as maxCarriedHistory, and fix
chatHistory's doc comment, which cited "lines 373-395" for the dialogue
merge in runTurn -- that block has since moved to lines 385-394. Point
at the step-6 comment instead of a line range so the reference survives
future edits. No behavior change; bookkeeping only, not the clarify/
reminder slot-decision logic.
This commit is contained in:
@@ -527,20 +527,22 @@ func (h *reactiveHandler) finishClarified(ctx context.Context, dec router.Decisi
|
|||||||
return reply
|
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
|
// 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
|
// inherits from, carrying up to 4 prior turns of history for anaphora. Capped so
|
||||||
// one long conversation can't grow the session unboundedly.
|
// 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) {
|
func (h *reactiveHandler) rememberTurn(ctx context.Context, prev *dialogue.Session, dec router.Decision, now time.Time) {
|
||||||
var history []dialogue.Turn
|
var history []dialogue.Turn
|
||||||
if prev != nil {
|
if prev != nil {
|
||||||
history = append(history, dialogue.Turn{
|
history = append(history, sessionAsTurn(prev))
|
||||||
Intent: prev.Intent,
|
|
||||||
Slots: prev.Slots,
|
|
||||||
Text: prev.Slots.Text,
|
|
||||||
})
|
|
||||||
maxHist := len(prev.History)
|
maxHist := len(prev.History)
|
||||||
if maxHist > 3 {
|
if maxHist > maxCarriedHistory {
|
||||||
maxHist = 3
|
maxHist = maxCarriedHistory
|
||||||
}
|
}
|
||||||
history = append(history, prev.History[:maxHist]...)
|
history = append(history, prev.History[:maxHist]...)
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-6
@@ -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
|
// chatHistory collects dialogue turns from the session store for the current
|
||||||
// conversation. Returns prior user utterances (newest last) up to a depth of
|
// conversation. Returns prior user utterances (newest last) up to a depth of
|
||||||
// 4 turns. Returns nil when there's no session or no history.
|
// 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
|
return nil
|
||||||
}
|
}
|
||||||
// History already includes the immediate prior turn (set by the dialogue
|
// 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 := make([]dialogue.Turn, 0, 1+len(prev.History))
|
||||||
out = append(out, dialogue.Turn{
|
out = append(out, sessionAsTurn(prev))
|
||||||
Intent: prev.Intent,
|
|
||||||
Slots: prev.Slots,
|
|
||||||
Text: prev.Slots.Text,
|
|
||||||
})
|
|
||||||
out = append(out, prev.History...)
|
out = append(out, prev.History...)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user