refactor(loop): extract speak voice backfill into applyBatchVoice (M57)

This commit is contained in:
AskaEth committed 2026-10-27 21:33:05 +08:00
1 parent 39ae883a4e
commit c9da488749
2 files changed
+10 -5

No files matched your search

+1 -5
View File
@@ -187,11 +187,7 @@ func (l *Loop) driveTurn(ctx context.Context, sessionID string, msgs []model.Mes
}
msgs = batch.messages
res.ToolCallsExecuted += batch.executed
// speak 的出站结论逐批回填(M57):后面批次里没有 speak 时保留
// 前面那批的结论 —— 这条回复想用语音这件事发生在哪一批都算数。
if batch.voice != nil {
res.Voice = batch.voice
}
applyBatchVoice(res, &batch)
l.saveCheckpoint(ctx, sessionID, step, msgs, agent.StopReasonToolCalls)
// 关键工具循环安全网(或终止钩子)不等真正的最终答案
+9
View File
@@ -86,6 +86,15 @@ func (l *Loop) withSpeakSpec(schemas []model.ToolSpec) []model.ToolSpec {
return append(out, *spec)
}
// applyBatchVoice 把一批工具调用的语音结论回填进本回合的 Result。
// 后面批次里没有 speak 时保留前面那批的结论 —— 「这条回复想用语音」
// 发生在哪一批都算数。
func applyBatchVoice(res *Result, batch *toolRunResult) {
if batch.voice != nil {
res.Voice = batch.voice
}
}
// captureVoice 从一批调用的结局里提取本回合的出站语音结论。返回 nil
// 表示「这一批没有要求语音」,Result.Voice 因此保持 nil,客户端按纯
// 文本呈现 —— 与没有 speak 之前逐字节一致。