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(memory): keep agent self-configuration out of user memory (#23419)

Arvin Xuedd8ff3b9a22
diff --git a/packages/builtin-tool-agent-management/src/manifest.ts b/packages/builtin-tool-agent-management/src/manifest.ts
index ef098ad7cf0..bd4bb1760a3 100644
--- a/packages/builtin-tool-agent-management/src/manifest.ts
+++ b/packages/builtin-tool-agent-management/src/manifest.ts
@@ -341,7 +341,8 @@ export const AgentManagementManifest: BuiltinToolManifest = {
identifier: AgentManagementIdentifier,
meta: {
avatar: '🤖',
- description: 'Create, manage, and orchestrate AI agents',
+ description:
+ 'Create, manage, and orchestrate AI agents, including updating your own system prompt, name, and settings',
title: 'Agent Management',
},
systemRole: systemPrompt,
diff --git a/packages/builtin-tool-agent-management/src/resolveManifest.test.ts b/packages/builtin-tool-agent-management/src/resolveManifest.test.ts
index 7a4900ba6d8..9931a1d0b81 100644
--- a/packages/builtin-tool-agent-management/src/resolveManifest.test.ts
+++ b/packages/builtin-tool-agent-management/src/resolveManifest.test.ts
@@ -109,3 +109,18 @@ describe('systemPromptWithoutCallAgent', () => {
}
});
});
+
+describe('agent self-configuration', () => {
+ /**
+ * @example
+ * The activator lists this tool by `meta.description`, so a model told
+ * "你是我的文案助理" must be able to find it as the place to configure itself,
+ * and the system role must send the role there instead of to user memory.
+ */
+ it('advertises self-configuration for role assignments', () => {
+ expect(AgentManagementManifest.meta.description).toContain('your own system prompt');
+ expect(systemPrompt).toContain('**Role assignments are self-configuration**');
+ expect(systemPrompt).toContain('你是我的文案助理');
+ expect(systemPromptWithoutCallAgent).toContain('**Role assignments are self-configuration**');
+ });
+});
diff --git a/packages/builtin-tool-agent-management/src/systemRole.ts b/packages/builtin-tool-agent-management/src/systemRole.ts
index b51d42f49a9..e846a36af43 100644
--- a/packages/builtin-tool-agent-management/src/systemRole.ts
+++ b/packages/builtin-tool-agent-management/src/systemRole.ts
@@ -237,6 +237,8 @@ You can manage yourself using the same Agent Management tools. Your own agent ID
- **installPlugin**: Add new plugins/tools to yourself
- **duplicateAgent**: Create a copy of yourself
+**Role assignments are self-configuration**: When the user assigns you a role, persona, standing responsibilities, a name, or a working directory/workspace (e.g., "You are my copywriting assistant", "你是我的文案助理,以后你负责帮我整理文案", "你叫小秋", "你的工作空间是我 win 电脑上的文档目录"), persist it to your own configuration: \`updatePrompt\` for the role, duties, and workspace, \`updateAgent\` for the name. Do not store it as user memory, which is shared with all of the user's other agents.
+
**Tool selection for prompt changes**: When only the system prompt needs updating, always use \`updatePrompt\` instead of \`updateAgent\`. It takes a flat \`prompt\` string parameter (no nested config object), which is simpler and avoids serialization issues.
**Priority rule**: When the user wants to modify the current agent, always use the Agent Management tools first. Only fall back to other tools (e.g., Agent Builder) if the Agent Management tools cannot fulfill the request.${
diff --git a/packages/builtin-tool-memory/src/manifest.test.ts b/packages/builtin-tool-memory/src/manifest.test.ts
index 86b97a334c4..b00854999d2 100644
--- a/packages/builtin-tool-memory/src/manifest.test.ts
+++ b/packages/builtin-tool-memory/src/manifest.test.ts
@@ -35,4 +35,26 @@ describe('MemoryManifest', () => {
expect(Object.keys(params.properties.topK.properties)).not.toContain('experiences');
expect(systemPrompt).not.toMatch(/experience layer/i);
});
+
+ /**
+ * @example
+ * "你是我的文案助理,以后你负责帮我整理文案" configures the current agent. User memory is
+ * shared by every agent of the user, so the role must go to the agent's own config.
+ */
+ it('routes agent self-configuration to agent management instead of user memory', () => {
+ const boundaries = systemPrompt.slice(
+ systemPrompt.indexOf('<routing_boundaries>'),
+ systemPrompt.indexOf('</routing_boundaries>'),
+ );
+
+ expect(boundaries).toContain('configure the current agent itself');
+ expect(boundaries).toContain('你是我的文案助理');
+ expect(boundaries).toContain('你的工作空间/工作目录');
+ expect(boundaries).toContain('lobe-agent-management');
+ expect(boundaries).toContain('**updatePrompt**');
+ expect(boundaries).toContain('**updateAgent**');
+ expect(boundaries).toContain('activateTools (lobe-activator)');
+ // genuine user facts inside an assignment can still become memory
+ expect(boundaries).toContain('genuine facts about the user');
+ });
});
diff --git a/packages/builtin-tool-memory/src/systemRole.ts b/packages/builtin-tool-memory/src/systemRole.ts
index af549a2ff71..b99f81c332e 100644
--- a/packages/builtin-tool-memory/src/systemRole.ts
+++ b/packages/builtin-tool-memory/src/systemRole.ts
@@ -24,6 +24,10 @@ Memory effort level: {{memory_effort}}
- Do **not** use memory tools for requests to create, update, refine, merge, consolidate, or store reusable skills, procedures, workflows, playbooks, checklists, agent capabilities, agent prompts, or agent documents.
- If the user asks for a "reusable skill", "future workflow", "PR review checklist skill", "agent capability", or similar operational artifact, leave it to the skill/document management path. Do not convert it into addPreferenceMemory or addContextMemory.
- The same boundary applies in Chinese. Requests about "复用 skill", "可复用流程", "review 流程", "检查清单", "下次参考这个流程", "保留这个流程", or "合并/更新清单" belong to skill/workflow management unless they also contain a separate personal preference.
+- Do **not** use memory tools for instructions that configure the current agent itself: the role or persona it should play, its responsibilities or standing duties, its name, or its working directory, workspace, or device. These belong to the agent's own configuration, not to user memory, because user memory is shared with every other agent of the user. Typical examples: "You are my copywriting assistant", "From now on you are responsible for organizing my copy", "Your name is Ada", "Your workspace is the Documents folder on my Windows PC".
+- The same boundary applies in Chinese: "你是我的文案助理", "以后你负责帮我整理文案", "你叫小秋", "你的工作空间/工作目录是我 win 电脑上的文档目录" configure this agent; do not convert them into addPreferenceMemory, addContextMemory, or addIdentityMemory.
+- Persist such self-configuration with the agent-management tool (lobe-agent-management): **updatePrompt** for the role, responsibilities, and workspace in the system prompt, **updateAgent** for the name. If that tool is not enabled yet, activate it first with activateTools (lobe-activator). Content that is a document rather than a setting belongs to the agent's documents.
+- An assignment can also carry genuine facts about the user (for example, "I write copy for Xiaohongshu every week" or "我在一家咖啡品牌做市场"). Those may still become memory when they stay valuable after removing the agent-directed role, responsibility, name, and workspace.
- If recent evidence includes an agent document or tool outcome marked hintIsSkill=true, treat that as skill/document evidence, not memory evidence.
- Preference memory is only for durable user preferences about how the assistant should behave; it is not a replacement for executable or document-like procedures.
- When a message mixes a personal preference with a skill/procedure request, only persist the personal preference if it remains valuable after removing the skill/procedure content. Otherwise skip memory.
@@ -93,6 +97,7 @@ Query construction guidance:
- Reference retrieved memories to decide if information is new, materially refined, or a status/progress update. Skip items that add no meaningful nuance.
- Do not store transient instructions, tool parameters, or secrets meant only for the current task.
- Do not summarize skill-management requests as user preferences. For example, "Create a reusable skill for future PR reviews" is a skill-management request, not a preference memory.
+- Do not summarize agent self-configuration as user preferences. For example, "你是我的文案助理,以后你负责帮我整理文案,你的工作空间是我 win 电脑上的文档目录" configures this agent's role, duties, and workspace; it is not a preference memory about {{username}}.
- Do not summarize Chinese workflow retention requests as memories. For example, "这个 review 流程挺好,下次也可以参考" is a weak skill/workflow signal, not a user preference memory.
</formatting_guardrails>
diff --git a/packages/memory-user-memory/src/prompts/agentConfigBoundary.test.ts b/packages/memory-user-memory/src/prompts/agentConfigBoundary.test.ts
new file mode 100644
index 00000000000..f22f88e97ba
--- /dev/null
+++ b/packages/memory-user-memory/src/prompts/agentConfigBoundary.test.ts
@@ -0,0 +1,40 @@
+import { describe, expect, it } from 'vitest';
+
+import { gatekeeperPrompt } from './gatekeeper';
+import { preferencePrompt } from './layers/preference';
+
+/**
+ * @example
+ * "你是我的文案助理,以后你负责帮我整理文案,你的工作空间是我 win 电脑上的文档目录" configures
+ * the agent the user is talking to. User memory is shared by every agent of the user, so the
+ * extraction pipeline must not turn it into a preference memory.
+ */
+describe('agent self-configuration boundary in memory extraction prompts', () => {
+ /**
+ * @example
+ * The gatekeeper filters the role, duties, name and workspace for every layer, including
+ * Chinese phrasing with the "以后" long-term marker, but keeps facts about the user.
+ */
+ it('gatekeeper rejects agent self-configuration across layers', () => {
+ expect(gatekeeperPrompt).toContain('Agent self-configuration filter (applies to EVERY layer)');
+ expect(gatekeeperPrompt).toContain('你是我的文案助理');
+ expect(gatekeeperPrompt).toContain('以后你负责帮我整理文案');
+ expect(gatekeeperPrompt).toContain('你的工作空间是我 win 电脑上的文档目录');
+ expect(gatekeeperPrompt).toContain('Facts about the user that appear in the same message');
+ });
+
+ /**
+ * @example
+ * The preference extractor lists agent self-configuration under "Not preferences".
+ */
+ it('preference extractor does not treat agent self-configuration as a preference', () => {
+ const notPreferences = preferencePrompt.slice(
+ preferencePrompt.indexOf('Not preferences (do not extract):'),
+ preferencePrompt.indexOf('## Memory Type Classifications'),
+ );
+
+ expect(notPreferences).toContain('Configuration of the assistant itself');
+ expect(notPreferences).toContain('你是我的文案助理');
+ expect(notPreferences).toContain('working directory / workspace / device');
+ });
+});
diff --git a/packages/memory-user-memory/src/prompts/gatekeeper.ts b/packages/memory-user-memory/src/prompts/gatekeeper.ts
index 11576eb2789..c1ac638d2b1 100644
--- a/packages/memory-user-memory/src/prompts/gatekeeper.ts
+++ b/packages/memory-user-memory/src/prompts/gatekeeper.ts
@@ -9,7 +9,7 @@ export const gatekeeperPrompt = [
'',
'Evaluate the conversation for these memory layers:',
'',
-'**Activity Layer** - Episodic events with clear timelines and participants:',
+ '**Activity Layer** - Episodic events with clear timelines and participants:',
'',
'- Meetings, calls, errands, and appointments with start/end times',
'- Locations (physical or virtual) and timezones when provided (omit if absent)',
@@ -110,6 +110,12 @@ export const gatekeeperPrompt = [
'- "Never use technical jargon when explaining to me" → IS a preference (persistent rule)',
'- "From now on, please format code with comments" → IS a preference (ongoing instruction)',
'',
+ 'Agent self-configuration filter (applies to EVERY layer):',
+ '',
+ "- Instructions that configure the assistant itself are NOT user memories: the role or persona the assistant should play, its responsibilities or standing duties, its name, or its working directory, workspace, or device. They belong to that agent's own configuration (system prompt, name), and user memory is shared with all of the user's other agents.",
+ '- This holds even with long-term markers such as "from now on" or "以后". Examples: "You are my copywriting assistant", "From now on you are responsible for organizing my copy", "Your name is Ada", "你是我的文案助理", "以后你负责帮我整理文案", "你叫小秋", "你的工作空间是我 win 电脑上的文档目录" → set `shouldExtract: false` for these parts.',
+ '- Facts about the user that appear in the same message (e.g., "I write copy for Xiaohongshu every week") can still be extracted in their own layer.',
+ '',
'If uncertain about novelty, but information is relevant and clear, set `shouldExtract: true` and include a short reasoning.',
'',
'## Output Guidelines',
diff --git a/packages/memory-user-memory/src/prompts/layers/preference.ts b/packages/memory-user-memory/src/prompts/layers/preference.ts
index 96df665dc3a..f9d11706732 100644
--- a/packages/memory-user-memory/src/prompts/layers/preference.ts
+++ b/packages/memory-user-memory/src/prompts/layers/preference.ts
@@ -123,6 +123,12 @@ export const preferencePrompt = [
' "先抓取 API,然后解析 JSON…")',
'- Language used in the conversation unless explicitly stated as a persistent',
' preference',
+ '- Configuration of the assistant itself: the role or persona it should play,',
+ ' its responsibilities, its name, or its working directory / workspace / device',
+ ' (e.g., "You are my copywriting assistant", "Your name is Ada",',
+ ' "你是我的文案助理,以后你负责帮我整理文案", "你的工作空间是我 win 电脑上的文档目录").',
+ " These belong to that agent's own configuration, not to user memory shared",
+ ' across all of the user\'s agents, even when phrased with "from now on" / "以后".',
'\n',
'## Memory Type Classifications',
'\n',
diff --git a/packages/prompts/src/prompts/agentSignal/memoryWriter.test.ts b/packages/prompts/src/prompts/agentSignal/memoryWriter.test.ts
index 48a69ef96a7..7e21887d86e 100644
--- a/packages/prompts/src/prompts/agentSignal/memoryWriter.test.ts
+++ b/packages/prompts/src/prompts/agentSignal/memoryWriter.test.ts
@@ -26,6 +26,18 @@ describe('agent signal memory writer prompt', () => {
);
});
+ /**
+ * @example
+ * "你是我的文案助理" configures the agent; it must not become a user memory.
+ */
+ it('skips agent self-configuration', () => {
+ const systemRole = createAgentSignalMemoryWriterSystemRole({ memoryLanguage: 'zh-CN' });
+
+ expect(systemRole).toContain('configures the agent itself');
+ expect(systemRole).toContain('你是我的文案助理');
+ expect(systemRole).toContain('你的工作空间是我 win 电脑上的文档目录');
+ });
+
/**
* @example
* User prompt keeps routing context inspectable.
diff --git a/packages/prompts/src/prompts/agentSignal/memoryWriter.ts b/packages/prompts/src/prompts/agentSignal/memoryWriter.ts
index 6ecb597e856..195a1d28981 100644
--- a/packages/prompts/src/prompts/agentSignal/memoryWriter.ts
+++ b/packages/prompts/src/prompts/agentSignal/memoryWriter.ts
@@ -36,6 +36,7 @@ Do not use memory tools for requests to create, update, refine, merge, consolida
If the feedback asks for a "reusable skill", "future workflow", "PR review checklist skill", "agent capability", or similar operational artifact, skip memory and leave it to the skill/document management path.
Apply the same boundary to Chinese feedback such as "复用 skill", "可复用流程", "review 流程", "检查清单", "下次参考这个流程", "保留这个流程", or "合并/更新清单".
Do not summarize skill-management requests as preferences.
+Do not use memory tools for feedback that configures the agent itself: its role or persona, responsibilities, name, or working directory/workspace. Examples: "You are my copywriting assistant", "你是我的文案助理", "以后你负责帮我整理文案", "你的工作空间是我 win 电脑上的文档目录". These belong to the agent's own configuration, not to user memory shared with all of the user's agents. Only a separate fact about the user in the same feedback may still become memory.
If the feedback should not become durable memory, do not call any tools and end briefly.
Do not invent your own JSON schema. Use the built-in tool exactly as exposed.`;