feat: Agent 记忆系统替代预设功能,全功能协调运作
核心改造: - 取消 Agent 预设(保留兼容),新增 AI Agent 记忆系统 - 自动提取 → 存储 → 检索 → 注入上下文的完整记忆闭环 - 记忆类型:事实/偏好/规则/事件,支持重要性评分和标签 新增文件: - services/memory-manager.ts: 记忆管理核心 - 关键词+标签+重要性加权检索 - 会话结束自动提取(LLM 驱动) - 去重检测、使用频率追踪 - components/memory-panel.ts: 记忆管理面板 UI 修改文件: - types.d.ts: 新增 MemoryEntry/MemorySearchResult 类型 - db/chat-db.ts: 升级 v2,新增 memories 存储 - input-area.ts: 对话流集成记忆检索+自动提取 - agent-engine.ts: Agent Loop 注入记忆上下文 - settings-modal.ts: 记忆开关设置 - main.ts: 记忆系统初始化 - index.html: 记忆设置面板 HTML - style.css: 记忆面板完整样式 功能协调: - 对话流: 记忆检索 → RAG 检索 → 系统提示词组合 → 流式对话 - Agent Loop: 记忆检索 → 系统提示词注入 → 工具调用循环 - 会话结束: 自动提取关键信息 → 存入记忆库 - 跨会话: 记忆持久化 IndexedDB,新对话自动召回相关记忆
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
getEnabledToolDefinitions,
|
||||
needsConfirmation
|
||||
} from './tool-registry.js';
|
||||
import { searchMemories, buildMemoryContext, markMemoryUsed, isMemoryEnabled } from './memory-manager.js';
|
||||
import { showToast } from '../components/toast.js';
|
||||
import type {
|
||||
OllamaMessage,
|
||||
@@ -45,13 +46,28 @@ export async function runAgentLoop(
|
||||
|
||||
const messages: OllamaMessage[] = [];
|
||||
|
||||
let systemPromptParts: string[] = [];
|
||||
|
||||
if (state.get<boolean>(KEYS.SYSTEM_PROMPT_ENABLED)) {
|
||||
const systemPrompt = state.get<string>(KEYS.SYSTEM_PROMPT, '');
|
||||
if (systemPrompt) {
|
||||
messages.push({ role: 'system', content: systemPrompt });
|
||||
if (systemPrompt) systemPromptParts.push(systemPrompt);
|
||||
}
|
||||
|
||||
// 注入记忆上下文
|
||||
if (isMemoryEnabled() && userContent) {
|
||||
const relevantMemories = searchMemories(userContent, 6);
|
||||
if (relevantMemories.length > 0) {
|
||||
systemPromptParts.push(buildMemoryContext(relevantMemories));
|
||||
for (const m of relevantMemories) {
|
||||
await markMemoryUsed(m.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (systemPromptParts.length > 0) {
|
||||
messages.push({ role: 'system', content: systemPromptParts.join('\n\n') });
|
||||
}
|
||||
|
||||
for (const msg of historyMessages) {
|
||||
messages.push({
|
||||
role: msg.role as 'user' | 'assistant',
|
||||
|
||||
Reference in New Issue
Block a user