fix: 后台思考记忆来源感知 — 不再将所有记忆标为'关于开拓者的事'
两个改动: 1. 提示词中将「你记得的关于开拓者的事」改为「你近期收集到的信息」, 并注明记忆可能来自不同对话和群聊,不都与开拓者有关 2. 思考时除管理员个人记忆外,额外检索各平台频道的群聊记忆, 以 [群聊123] 前缀标注来源,让模型能区分信息来源 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -788,6 +788,36 @@ func (t *Thinker) performThink(triggerReason string) {
|
||||
log.Printf("[后台思考] 模糊搜索补充 %d 条记忆", len(fuzzyResults))
|
||||
}
|
||||
}
|
||||
|
||||
// Also pull recent channel/group memories so the model is aware of group activity.
|
||||
if t.memClient != nil && len(t.platformChannels) > 0 {
|
||||
chanSeen := make(map[string]bool)
|
||||
for _, m := range memories {
|
||||
chanSeen[m.ID] = true
|
||||
}
|
||||
oldCount := len(memories)
|
||||
for _, ch := range t.platformChannels {
|
||||
namespace := fmt.Sprintf("platform_%s_%s_%s", ch.Platform, ch.ChannelType, ch.ChannelID)
|
||||
chanMems, cErr := t.memClient.Query(ctx, model.MemoryQuery{
|
||||
UserID: namespace,
|
||||
Limit: 5,
|
||||
})
|
||||
if cErr != nil {
|
||||
continue
|
||||
}
|
||||
for _, m := range chanMems {
|
||||
if !chanSeen[m.ID] {
|
||||
chanSeen[m.ID] = true
|
||||
labeled := m
|
||||
labeled.Content = fmt.Sprintf("[群聊%s] %s", ch.ChannelID, m.Content)
|
||||
memories = append(memories, labeled)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(memories) > oldCount {
|
||||
log.Printf("[后台思考] 频道记忆补充 %d 条", len(memories)-oldCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 查询 IoT 设备状态(每次都查询,无间隔限制)
|
||||
@@ -1145,9 +1175,10 @@ func (t *Thinker) buildThinkingUserPrompt(
|
||||
sb.WriteString(fmt.Sprintf("\n🔍 **重要**:开拓者最后说的是「%s」。请认真判断:他现在是不是在休息/睡觉/忙?如果是,不要输出【主动消息】指令行。\n", lastUserMsg))
|
||||
}
|
||||
|
||||
// 现有记忆
|
||||
// 现有记忆(可能来自管理员对话、群聊观察等多个来源)
|
||||
if len(memories) > 0 {
|
||||
sb.WriteString("\n【你记得的关于开拓者的事】\n")
|
||||
sb.WriteString("\n【你近期收集到的信息】\n")
|
||||
sb.WriteString("(这些记忆来自不同的对话和群聊,不一定都和开拓者有关。请根据记忆内容中标注的来源判断是谁的经历。)\n")
|
||||
for i, m := range memories {
|
||||
if i >= 15 {
|
||||
sb.WriteString(fmt.Sprintf("... 还有 %d 条记忆未列出\n", len(memories)-15))
|
||||
@@ -1157,7 +1188,7 @@ func (t *Thinker) buildThinkingUserPrompt(
|
||||
m.Category.DisplayName(), m.Importance, m.Content))
|
||||
}
|
||||
} else {
|
||||
sb.WriteString("\n【你记得的关于开拓者的事】\n(暂无相关记忆)\n")
|
||||
sb.WriteString("\n【你近期收集到的信息】\n(暂无相关记忆)\n")
|
||||
}
|
||||
|
||||
// 思考链:注入上一轮的结论和待续问题
|
||||
|
||||
Reference in New Issue
Block a user