diff --git a/backend/ai-core/internal/background/thinker.go b/backend/ai-core/internal/background/thinker.go index 50d0e26..c8ed50f 100644 --- a/backend/ai-core/internal/background/thinker.go +++ b/backend/ai-core/internal/background/thinker.go @@ -511,7 +511,7 @@ func NewThinker( lightThinkEnabled: cfg.LightThinkEnabled, lightThinkInterval: cfg.LightThinkInterval, silenceTimeout: cfg.SilenceTimeout, - proactiveMsgMinGap: getEnvDuration("PROACTIVE_MSG_MIN_GAP_SEC", 1800), + proactiveMsgMinGap: getEnvDuration("PROACTIVE_MSG_MIN_GAP_SEC", 300), postChatDelay: cfg.PostChatDelay, minThinkGap: cfg.MinThinkGap, offlineThinkGap: cfg.OfflineThinkGap, @@ -1956,7 +1956,7 @@ func (t *Thinker) storeThought(content string, toolCallsJSON string, toolCallCou } } else if canPush { gapSinceLast := time.Since(t.lastProactiveTime()) - if gapSinceLast < 30*time.Minute { + if gapSinceLast < t.proactiveMsgMinGap { log.Printf("[后台思考] 主动消息距上次仅 %v,跳过推送", gapSinceLast.Round(time.Second)) canPush = false } else { @@ -1965,6 +1965,11 @@ func (t *Thinker) storeThought(content string, toolCallsJSON string, toolCallCou } } } + // 被拦截的主动消息:清除标记,防止 LLM 下次以为发过了 + if !canPush && proactiveMsg != "" { + content = strings.ReplaceAll(content, "【主动消息】", "【未发送】") + content = strings.ReplaceAll(content, "【话题发起】", "【未发送】") + } // Copy target for use after unlock (avoid race). var targetCopy *ProactiveTarget if proactiveTarget != nil {