diff --git a/backend/ai-core/internal/background/thinker.go b/backend/ai-core/internal/background/thinker.go index 9f22a0f..5413d88 100644 --- a/backend/ai-core/internal/background/thinker.go +++ b/backend/ai-core/internal/background/thinker.go @@ -1321,6 +1321,49 @@ func (t *Thinker) performThink(triggerReason string) { break } + // Handle 【查看群聊:适配器名:群号】 — fetch recent group context on demand. + if idx := strings.Index(roundContent, "【查看群聊:"); idx >= 0 { + rest := roundContent[idx+len("【查看群聊:"):] + if end := strings.Index(rest, "】"); end > 0 { + spec := strings.TrimSpace(rest[:end]) + parts := strings.SplitN(spec, ":", 2) + if len(parts) == 2 { + adapterName, groupID := parts[0], parts[1] + // Find the channel to get the correct platform type. + t.mu.Lock() + var platform string + for _, ch := range t.platformChannels { + if ch.AdapterName == adapterName && ch.ChannelID == groupID && ch.ChannelType == "group" { + platform = ch.Platform + break + } + } + t.mu.Unlock() + if platform == "" { + platform = "obv11" // fallback + } + log.Printf("[后台思考] 请求查看群聊 %s/%s (adapter=%s)", platform, groupID, adapterName) + if t.memClient != nil { + namespace := fmt.Sprintf("platform_%s_group_%s", platform, groupID) + chanMems, cErr := t.memClient.Query(ctx, model.MemoryQuery{UserID: namespace, Limit: 5}) + if cErr == nil && len(chanMems) > 0 { + var sb strings.Builder + sb.WriteString(fmt.Sprintf("【群聊 %s/%s 最近聊天记录】\n", platform, groupID)) + for _, m := range chanMems { + sb.WriteString(fmt.Sprintf("- %s\n", m.Content)) + } + currentMessages = append(currentMessages, model.LLMMessage{ + Role: model.RoleUser, + Content: sb.String() + "\n(你可以基于这些信息继续思考。如果需要,输出【继续思考】。)", + }) + roundContent += "【继续思考】" + log.Printf("[后台思考] 已获取群聊 %s/%s 的 %d 条记录,继续思考", platform, groupID, len(chanMems)) + } + } + } + } + } + // Strip control marker before storing. cleanContent := strings.TrimSpace(strings.Replace(roundContent, "【继续思考】", "", 1)) allContents = append(allContents, cleanContent) @@ -1435,7 +1478,7 @@ func (t *Thinker) buildThinkingSystemPrompt(personaConfig *persona.PersonaConfig 3. 【主动消息】标记必须独占一行开头,内容直接对开拓者说话(用"你"称呼他),像主动找他聊天一样。 4. 如果你在反思中提到"主动消息"这个词但不打算发消息,不要使用【主动消息】这个带括号的标记——我会误解析。 5. 2-4句话即可。 - 6. 如果你觉得还有需要继续思考的事情,在反思末尾独占一行写【继续思考】标记,我会让你再想一轮。如果没有了就不要再写。` + 6. 如果你觉得还有需要继续思考的事情,在反思末尾独占一行写【继续思考】标记,我会让你再想一轮。如果没有了就不要再写。\n\t7. 如果你想知道某个群聊最近在聊什么,写【查看群聊:适配器名:群号】——如【查看群聊:obv11-main:531082168】。适配器名见上方「可用频道列表」。` case "silence": thinkingInstructions = `