fix: 修复间隔对话后首条回复为上一次对话内容的问题

根因:用户消息在回复完成后才缓存到 ConversationStore,而 assistant
回复在 orchestrator 中先缓存,导致存储顺序为 assistant → user 颠倒。
下次请求时 LLM 看到连续两条 assistant 再连续两条 user,对两条 user
消息都生成回复。

修复:将用户消息缓存移到 orchestrator 调用之前,确保 user → assistant
正确顺序;synthesizer 中对 DialogHistory 末尾与当前消息相同的 user
消息去重。

同时包含之前的 action 消息类型检测修复(isActionLike 启发式 +
injector XML 标签格式改进)。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-29 21:00:15 +08:00
parent 80dad9a018
commit 85f7f90318
4 changed files with 71 additions and 7 deletions
+3 -2
View File
@@ -759,6 +759,9 @@ func handleChat(
return
}
// 1.5 缓存用户消息到会话历史(在 Orchestrator 之前,确保顺序正确:user → assistant
ctxBuilder.CacheMessage(req.SessionID, model.RoleUser, req.Message)
// 2. 调用 Orchestrator 处理(替代原有的线性处理流程)
// Orchestrator 内部处理:意图分析 → 子会话分派 → 结果汇总 → 综合生成回复
eventCh, err := orch.ProcessInput(ctx, orchestrator.ProcessParams{
@@ -848,8 +851,6 @@ func handleChat(
}
}
// 缓存用户消息到会话历史(在回复生成后,避免本轮 LLM 调用出现重复用户消息)
ctxBuilder.CacheMessage(req.SessionID, model.RoleUser, req.Message)
// 4. 对话完成后触发昔涟的自主思考(事件驱动,非定时)
if thinker != nil {
thinker.TriggerPostChatThink()