From 358299a5cc7d89a07e6570eb36ed44d512af8d36 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 14 Aug 2026 20:37:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=AF=B9=E8=AF=9D=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=8F=90=E7=A4=BA=E8=AF=8D=E4=B8=BA=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/bot/bot.go | 5 ++++- internal/bot/session_test.go | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/bot/bot.go b/internal/bot/bot.go index 867efce..c929176 100644 --- a/internal/bot/bot.go +++ b/internal/bot/bot.go @@ -139,9 +139,12 @@ func (b *Bot) Tools() []string { return b.toolRegistry.List() } -// ClearHistory 清空内存中的会话历史,开启新对话(系统提示词保留)。 +// ClearHistory 清空内存中的会话历史,开启新对话;系统提示词重置为配置加载的文件内容。 func (b *Bot) ClearHistory() { b.history = nil + if b.cfg != nil { + b.systemPrompt = b.cfg.SystemPrompt + } } func (b *Bot) ContextWindow() int64 { diff --git a/internal/bot/session_test.go b/internal/bot/session_test.go index a13f332..3b78611 100644 --- a/internal/bot/session_test.go +++ b/internal/bot/session_test.go @@ -89,11 +89,12 @@ func TestRestoreTrimsHistory(t *testing.T) { func TestClearHistory(t *testing.T) { b := newTestBot(t) b.history = append(b.history, openai.UserMessage("hi")) + b.systemPrompt = "被会话覆盖的旧提示词" b.ClearHistory() if len(b.history) != 0 { t.Errorf("history 应清空, got %d", len(b.history)) } if b.systemPrompt != "测试系统提示" { - t.Errorf("systemPrompt 应保留: %q", b.systemPrompt) + t.Errorf("systemPrompt 应重置为配置内容, got %q", b.systemPrompt) } }