Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: global memory setting & tool enabled logic (#12610)

Rdmclin2ceeb9c661326
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 185d7632e24..b5809daa6c9 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -164,10 +164,10 @@
"memory.effort.low.title": "Low",
"memory.effort.medium.title": "Medium",
"memory.effort.title": "Aggressiveness",
- "memory.off.desc": "Disable memory for this conversation.",
- "memory.off.title": "Disable Memory",
- "memory.on.desc": "Remember preferences and info from conversations.",
- "memory.on.title": "Enable Memory",
+ "memory.off.desc": "AI will not search, create, or update memories in this conversation.",
+ "memory.off.title": "Disable Memory Tool",
+ "memory.on.desc": "Allow AI to actively search and manage your memories during conversation.",
+ "memory.on.title": "Enable Memory Tool",
"memory.title": "Memory",
"mention.title": "Mention Members",
"messageAction.collapse": "Collapse Message",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index d73c889d090..3325accc6ed 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -164,10 +164,10 @@
"memory.effort.low.title": "低",
"memory.effort.medium.title": "中",
"memory.effort.title": "积极性",
- "memory.off.desc": "禁用此对话的记忆功能。",
- "memory.off.title": "关闭记忆",
- "memory.on.desc": "从对话中记住偏好和信息。",
- "memory.on.title": "启用记忆",
+ "memory.off.desc": "AI 将不会在此对话中搜索、创建或更新记忆。",
+ "memory.off.title": "关闭记忆工具",
+ "memory.on.desc": "允许 AI 在对话中主动搜索和管理你的记忆。",
+ "memory.on.title": "启用记忆工具",
"memory.title": "记忆",
"mention.title": "提及成员",
"messageAction.collapse": "收起消息",
diff --git a/packages/builtin-tools/src/index.ts b/packages/builtin-tools/src/index.ts
index 0afdb4cf0d8..6bbb0d4b9ba 100644
--- a/packages/builtin-tools/src/index.ts
+++ b/packages/builtin-tools/src/index.ts
@@ -27,6 +27,7 @@ export const defaultToolIds = [
SkillStoreManifest.identifier,
WebBrowsingManifest.identifier,
KnowledgeBaseManifest.identifier,
+ MemoryManifest.identifier,
];
export const builtinTools: LobeBuiltinTool[] = [
diff --git a/src/features/ChatInput/ActionBar/Memory/Controls.tsx b/src/features/ChatInput/ActionBar/Memory/Controls.tsx
index b7883ff7439..46ba84ffa15 100644
--- a/src/features/ChatInput/ActionBar/Memory/Controls.tsx
+++ b/src/features/ChatInput/ActionBar/Memory/Controls.tsx
@@ -60,7 +60,9 @@ interface ToggleOption {
const ToggleItem = memo<ToggleOption>(({ value, description, icon, label }) => {
const agentId = useAgentId();
const { updateAgentChatConfig } = useUpdateAgentConfig();
- const isEnabled = useAgentStore((s) => chatConfigByIdSelectors.isMemoryEnabledById(agentId)(s));
+ const isEnabled = useAgentStore((s) =>
+ chatConfigByIdSelectors.isMemoryToolEnabledById(agentId)(s),
+ );
const isActive = value === 'on' ? isEnabled : !isEnabled;
@@ -90,8 +92,8 @@ const Controls = memo(() => {
const agentId = useAgentId();
const { updateAgentChatConfig } = useUpdateAgentConfig();
const [isEnabled, effort] = useAgentStore((s) => [
- chatConfigByIdSelectors.isMemoryEnabledById(agentId)(s),
- chatConfigByIdSelectors.getMemoryEffortById(agentId)(s),
+ chatConfigByIdSelectors.isMemoryToolEnabledById(agentId)(s),
+ chatConfigByIdSelectors.getMemoryToolEffortById(agentId)(s),
]);
const toggleOptions: ToggleOption[] = [
diff --git a/src/features/ChatInput/ActionBar/Memory/index.tsx b/src/features/ChatInput/ActionBar/Memory/index.tsx
index 22139963013..20cf500f4d9 100644
--- a/src/features/ChatInput/ActionBar/Memory/index.tsx
+++ b/src/features/ChatInput/ActionBar/Memory/index.tsx
@@ -18,7 +18,7 @@ const Memory = memo(() => {
const { updateAgentChatConfig } = useUpdateAgentConfig();
const [isLoading, isEnabled] = useAgentStore((s) => [
agentByIdSelectors.isAgentConfigLoadingById(agentId)(s),
- chatConfigByIdSelectors.isMemoryEnabledById(agentId)(s),
+ chatConfigByIdSelectors.isMemoryToolEnabledById(agentId)(s),
]);
const isMobile = useIsMobile();
diff --git a/src/helpers/toolEngineering/index.ts b/src/helpers/toolEngineering/index.ts
index 1ba58b4c015..085123f562e 100644
--- a/src/helpers/toolEngineering/index.ts
+++ b/src/helpers/toolEngineering/index.ts
@@ -2,6 +2,7 @@
* Tools Engineering - Unified tools processing using ToolsEngine
*/
import { KnowledgeBaseManifest } from '@lobechat/builtin-tool-knowledge-base';
+import { MemoryManifest } from '@lobechat/builtin-tool-memory';
import { WebBrowsingManifest } from '@lobechat/builtin-tool-web-browsing';
import { defaultToolIds } from '@lobechat/builtin-tools';
import { isDesktop } from '@lobechat/const';
@@ -11,7 +12,7 @@ import { type ChatCompletionTool, type WorkingModel } from '@lobechat/types';
import { type LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
import { getAgentStoreState } from '@/store/agent';
-import { agentSelectors } from '@/store/agent/selectors';
+import { agentChatConfigSelectors, agentSelectors } from '@/store/agent/selectors';
import { getToolStoreState } from '@/store/tool';
import {
klavisStoreSelectors,
@@ -116,6 +117,11 @@ export const createAgentToolsEngine = (workingModel: WorkingModel) =>
return agentSelectors.hasEnabledKnowledgeBases(agentState);
}
+ // For MemoryManifest, check per-agent memory tool toggle
+ if (pluginId === MemoryManifest.identifier) {
+ return agentChatConfigSelectors.isMemoryToolEnabled(getAgentStoreState());
+ }
+
// For all other plugins, enable by default
return true;
},
diff --git a/src/locales/default/chat.ts b/src/locales/default/chat.ts
index 5d2041b7d78..61e47b17e88 100644
--- a/src/locales/default/chat.ts
+++ b/src/locales/default/chat.ts
@@ -265,10 +265,10 @@ export default {
'memory.effort.low.title': 'Low',
'memory.effort.medium.title': 'Medium',
'memory.effort.title': 'Aggressiveness',
- 'memory.off.desc': 'Disable memory for this conversation.',
- 'memory.off.title': 'Disable Memory',
- 'memory.on.desc': 'Remember preferences and info from conversations.',
- 'memory.on.title': 'Enable Memory',
+ 'memory.off.desc': 'AI will not search, create, or update memories in this conversation.',
+ 'memory.off.title': 'Disable Memory Tool',
+ 'memory.on.desc': 'Allow AI to actively search and manage your memories during conversation.',
+ 'memory.on.title': 'Enable Memory Tool',
'memory.title': 'Memory',
'search.grounding.searchQueries': 'Search Keywords',
'search.grounding.title': 'Found {{count}} results',
diff --git a/src/services/chat/index.ts b/src/services/chat/index.ts
index 06be2594326..161c70c8ff5 100644
--- a/src/services/chat/index.ts
+++ b/src/services/chat/index.ts
@@ -142,9 +142,7 @@ class ChatService {
// =================== 1.1 process user memories =================== //
- const globalMemoryEnabled = settingsSelectors.memoryEnabled(getUserStoreState());
- const agentMemoryEnabled = chatConfig.memory?.enabled ?? false;
- const enableUserMemories = globalMemoryEnabled && agentMemoryEnabled;
+ const enableUserMemories = settingsSelectors.memoryEnabled(getUserStoreState());
const userMemorySettings = settingsSelectors.currentMemorySettings(getUserStoreState());
const effectiveMemoryEffort =
chatConfig.memory?.effort ?? userMemorySettings.effort ?? 'medium';
diff --git a/src/store/agent/selectors/chatConfigByIdSelectors.test.ts b/src/store/agent/selectors/chatConfigByIdSelectors.test.ts
index 0709694f399..b8c9b18b69f 100644
--- a/src/store/agent/selectors/chatConfigByIdSelectors.test.ts
+++ b/src/store/agent/selectors/chatConfigByIdSelectors.test.ts
@@ -249,7 +249,7 @@ describe('chatConfigByIdSelectors', () => {
});
});
- describe('getMemoryConfigById', () => {
+ describe('getMemoryToolConfigById', () => {
it('should return memory config for specified agent', () => {
const state = createState({
agentMap: {
@@ -261,7 +261,7 @@ describe('chatConfigByIdSelectors', () => {
},
});
- expect(chatConfigByIdSelectors.getMemoryConfigById('agent-1')(state)).toEqual({
+ expect(chatConfigByIdSelectors.getMemoryToolConfigById('agent-1')(state)).toEqual({
effort: 'high',
enabled: true,
toolPermission: 'read-write',
@@ -273,7 +273,7 @@ describe('chatConfigByIdSelectors', () => {
agentMap: { 'agent-1': {} },
});
- expect(chatConfigByIdSelectors.getMemoryConfigById('agent-1')(state)).toBeUndefined();
+ expect(chatConfigByIdSelectors.getMemoryToolConfigById('agent-1')(state)).toBeUndefined();
});
it('should return undefined for non-existent agent', () => {
@@ -281,11 +281,13 @@ describe('chatConfigByIdSelectors', () => {
agentMap: {},
});
- expect(chatConfigByIdSelectors.getMemoryConfigById('non-existent')(state)).toBeUndefined();
+ expect(
+ chatConfigByIdSelectors.getMemoryToolConfigById('non-existent')(state),
+ ).toBeUndefined();
});
});
- describe('isMemoryEnabledById', () => {
+ describe('isMemoryToolEnabledById', () => {
it('should return true when memory is enabled', () => {
const state = createState({
agentMap: {
@@ -293,7 +295,7 @@ describe('chatConfigByIdSelectors', () => {
},
});
- expect(chatConfigByIdSelectors.isMemoryEnabledById('agent-1')(state)).toBe(true);
+ expect(chatConfigByIdSelectors.isMemoryToolEnabledById('agent-1')(state)).toBe(true);
});
it('should return false when memory is explicitly disabled', () => {
@@ -303,7 +305,7 @@ describe('chatConfigByIdSelectors', () => {
},
});
- expect(chatConfigByIdSelectors.isMemoryEnabledById('agent-1')(state)).toBe(false);
+ expect(chatConfigByIdSelectors.isMemoryToolEnabledById('agent-1')(state)).toBe(false);
});
it('should return false when memory config is not set (default)', () => {
@@ -311,7 +313,7 @@ describe('chatConfigByIdSelectors', () => {
agentMap: { 'agent-1': {} },
});
- expect(chatConfigByIdSelectors.isMemoryEnabledById('agent-1')(state)).toBe(false);
+ expect(chatConfigByIdSelectors.isMemoryToolEnabledById('agent-1')(state)).toBe(false);
});
it('should return false when memory exists but enabled is not set', () => {
@@ -321,7 +323,7 @@ describe('chatConfigByIdSelectors', () => {
},
});
- expect(chatConfigByIdSelectors.isMemoryEnabledById('agent-1')(state)).toBe(false);
+ expect(chatConfigByIdSelectors.isMemoryToolEnabledById('agent-1')(state)).toBe(false);
});
it('should return false for non-existent agent', () => {
@@ -329,7 +331,7 @@ describe('chatConfigByIdSelectors', () => {
agentMap: {},
});
- expect(chatConfigByIdSelectors.isMemoryEnabledById('non-existent')(state)).toBe(false);
+ expect(chatConfigByIdSelectors.isMemoryToolEnabledById('non-existent')(state)).toBe(false);
});
it('should work with different agents independently', () => {
@@ -341,13 +343,13 @@ describe('chatConfigByIdSelectors', () => {
},
});
- expect(chatConfigByIdSelectors.isMemoryEnabledById('agent-1')(state)).toBe(true);
- expect(chatConfigByIdSelectors.isMemoryEnabledById('agent-2')(state)).toBe(false);
- expect(chatConfigByIdSelectors.isMemoryEnabledById('agent-3')(state)).toBe(false);
+ expect(chatConfigByIdSelectors.isMemoryToolEnabledById('agent-1')(state)).toBe(true);
+ expect(chatConfigByIdSelectors.isMemoryToolEnabledById('agent-2')(state)).toBe(false);
+ expect(chatConfigByIdSelectors.isMemoryToolEnabledById('agent-3')(state)).toBe(false);
});
});
- describe('getMemoryEffortById', () => {
+ describe('getMemoryToolEffortById', () => {
it('should return effort level for specified agent', () => {
const state = createState({
agentMap: {
@@ -355,7 +357,7 @@ describe('chatConfigByIdSelectors', () => {
},
});
- expect(chatConfigByIdSelectors.getMemoryEffortById('agent-1')(state)).toBe('high');
+ expect(chatConfigByIdSelectors.getMemoryToolEffortById('agent-1')(state)).toBe('high');
});
it('should return "medium" as default when effort is not set', () => {
@@ -365,7 +367,7 @@ describe('chatConfigByIdSelectors', () => {
},
});
- expect(chatConfigByIdSelectors.getMemoryEffortById('agent-1')(state)).toBe('medium');
+ expect(chatConfigByIdSelectors.getMemoryToolEffortById('agent-1')(state)).toBe('medium');
});
it('should return "medium" when memory config is not set', () => {
@@ -373,7 +375,7 @@ describe('chatConfigByIdSelectors', () => {
agentMap: { 'agent-1': {} },
});
- expect(chatConfigByIdSelectors.getMemoryEffortById('agent-1')(state)).toBe('medium');
+ expect(chatConfigByIdSelectors.getMemoryToolEffortById('agent-1')(state)).toBe('medium');
});
it('should return "medium" for non-existent agent', () => {
@@ -381,7 +383,7 @@ describe('chatConfigByIdSelectors', () => {
agentMap: {},
});
- expect(chatConfigByIdSelectors.getMemoryEffortById('non-existent')(state)).toBe('medium');
+ expect(chatConfigByIdSelectors.getMemoryToolEffortById('non-existent')(state)).toBe('medium');
});
it('should return each effort level correctly', () => {
@@ -393,9 +395,9 @@ describe('chatConfigByIdSelectors', () => {
},
});
- expect(chatConfigByIdSelectors.getMemoryEffortById('agent-low')(state)).toBe('low');
- expect(chatConfigByIdSelectors.getMemoryEffortById('agent-medium')(state)).toBe('medium');
- expect(chatConfigByIdSelectors.getMemoryEffortById('agent-high')(state)).toBe('high');
+ expect(chatConfigByIdSelectors.getMemoryToolEffortById('agent-low')(state)).toBe('low');
+ expect(chatConfigByIdSelectors.getMemoryToolEffortById('agent-medium')(state)).toBe('medium');
+ expect(chatConfigByIdSelectors.getMemoryToolEffortById('agent-high')(state)).toBe('high');
});
});
diff --git a/src/store/agent/selectors/chatConfigByIdSelectors.ts b/src/store/agent/selectors/chatConfigByIdSelectors.ts
index fc905fc752d..b7d77a560fc 100644
--- a/src/store/agent/selectors/chatConfigByIdSelectors.ts
+++ b/src/store/agent/selectors/chatConfigByIdSelectors.ts
@@ -54,24 +54,24 @@ const getUseModelBuiltinSearchById = (agentId: string) => (s: AgentStoreState) =
const getSearchFCModelById = (agentId: string) => (s: AgentStoreState) =>
getChatConfigById(agentId)(s).searchFCModel || DEFAULT_AGENT_SEARCH_FC_MODEL;
-const getMemoryConfigById = (agentId: string) => (s: AgentStoreState) =>
+const getMemoryToolConfigById = (agentId: string) => (s: AgentStoreState) =>
getChatConfigById(agentId)(s).memory;
-const isMemoryEnabledById = (agentId: string) => (s: AgentStoreState) =>
+const isMemoryToolEnabledById = (agentId: string) => (s: AgentStoreState) =>
getChatConfigById(agentId)(s).memory?.enabled ?? false;
-const getMemoryEffortById = (agentId: string) => (s: AgentStoreState) =>
+const getMemoryToolEffortById = (agentId: string) => (s: AgentStoreState) =>
getChatConfigById(agentId)(s).memory?.effort ?? 'medium';
export const chatConfigByIdSelectors = {
getChatConfigById,
getEnableHistoryCountById,
getHistoryCountById,
- getMemoryConfigById,
- getMemoryEffortById,
+ getMemoryToolConfigById,
+ getMemoryToolEffortById,
getSearchFCModelById,
getSearchModeById,
getUseModelBuiltinSearchById,
isEnableSearchById,
- isMemoryEnabledById,
+ isMemoryToolEnabledById,
};
diff --git a/src/store/agent/selectors/chatConfigSelectors.ts b/src/store/agent/selectors/chatConfigSelectors.ts
index ce628830d3a..d80586e17d7 100644
--- a/src/store/agent/selectors/chatConfigSelectors.ts
+++ b/src/store/agent/selectors/chatConfigSelectors.ts
@@ -27,6 +27,9 @@ const enableHistoryCount = (s: AgentStoreState) =>
const historyCount = (s: AgentStoreState): number =>
chatConfigByIdSelectors.getHistoryCountById(s.activeAgentId || '')(s);
+const isMemoryToolEnabled = (s: AgentStoreState) =>
+ chatConfigByIdSelectors.isMemoryToolEnabledById(s.activeAgentId || '')(s);
+
const enableHistoryDivider =
(historyLength: number, currentIndex: number) => (s: AgentStoreState) => {
const config = currentChatConfig(s);
@@ -45,6 +48,7 @@ export const agentChatConfigSelectors = {
enableHistoryDivider,
historyCount,
isAgentEnableSearch,
+ isMemoryToolEnabled,
searchFCModel,
useModelBuiltinSearch,
};