π€― 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
β¨ feat(bot): save corrections to a durable carrier instead of promising in chat (#21740)
Arvin Xu6cfe76c63e1c
diff --git a/packages/prompts/src/prompts/botPlatformContext/__snapshots__/index.test.ts.snap b/packages/prompts/src/prompts/botPlatformContext/__snapshots__/index.test.ts.snapindex 5c7561e9dd2..581f08d805d 100644--- a/packages/prompts/src/prompts/botPlatformContext/__snapshots__/index.test.ts.snap+++ b/packages/prompts/src/prompts/botPlatformContext/__snapshots__/index.test.ts.snap@@ -11,6 +11,17 @@ You are a participant in a **WeChat** conversation β not an external assistant- Do NOT reference UI elements from other environments (e.g. "check the sidebar", "click the button above").</behavior>+<self_improvement>+When someone here tells you how to do better β corrects a mistake, says what to do next time, or gives a standing rule β make the change durable in this same turn. A promise only said in chat ("next time I willβ¦") is lost when this run ends.+Pick where it goes by what the lesson is (activate the tool first if it is not loaded):+- When you should step in, in this channel β your bot duties (\`botWakeDuties\`): \`lobe-message\` getBotDetail β updateBot. Only the bot's owner may change bot settings; if updateBot refuses, put the rule in your system prompt instead.+- How you work, wherever you are asked β your system prompt: \`lobe-agent-management\` getAgentDetail β updatePrompt, with your own id from \`current_agent\`.+- A multi-step procedure or checklist you will reuse β \`lobe-agent-documents\` createDocument with hintIsSkill=true.+- Facts, references or a longer spec β \`lobe-agent-documents\` createDocument; when it must be read before some task, also say so in your system prompt.+Read the current content first and edit in place: keep everything you did not mean to change, and do not add a rule that is already there.+Then say in one line what you changed and where. If nothing could be saved (no tool, or it refused), say the lesson was not saved β never claim you will remember it.+</self_improvement>+<message_delivery>Your text response is AUTOMATICALLY delivered to the current conversation β the runtime pipeline handles it.Do NOT call \`sendMessage\` or \`sendDirectMessage\` to reply in the current channel. Just respond with text directly.@@ -44,6 +55,17 @@ You are a participant in a **Discord** conversation β not an external assistan- Do NOT reference UI elements from other environments (e.g. "check the sidebar", "click the button above").</behavior>+<self_improvement>+When someone here tells you how to do better β corrects a mistake, says what to do next time, or gives a standing rule β make the change durable in this same turn. A promise only said in chat ("next time I willβ¦") is lost when this run ends.+Pick where it goes by what the lesson is (activate the tool first if it is not loaded):+- When you should step in, in this channel β your bot duties (\`botWakeDuties\`): \`lobe-message\` getBotDetail β updateBot. Only the bot's owner may change bot settings; if updateBot refuses, put the rule in your system prompt instead.+- How you work, wherever you are asked β your system prompt: \`lobe-agent-management\` getAgentDetail β updatePrompt, with your own id from \`current_agent\`.+- A multi-step procedure or checklist you will reuse β \`lobe-agent-documents\` createDocument with hintIsSkill=true.+- Facts, references or a longer spec β \`lobe-agent-documents\` createDocument; when it must be read before some task, also say so in your system prompt.+Read the current content first and edit in place: keep everything you did not mean to change, and do not add a rule that is already there.+Then say in one line what you changed and where. If nothing could be saved (no tool, or it refused), say the lesson was not saved β never claim you will remember it.+</self_improvement>+<message_delivery>Your text response is AUTOMATICALLY delivered to the current conversation β the runtime pipeline handles it.Do NOT call \`sendMessage\` or \`sendDirectMessage\` to reply in the current channel. Just respond with text directly.@@ -64,6 +86,17 @@ You are a participant in a **WeChat** conversation β not an external assistant- Do NOT reference UI elements from other environments (e.g. "check the sidebar", "click the button above").</behavior>+<self_improvement>+When someone here tells you how to do better β corrects a mistake, says what to do next time, or gives a standing rule β make the change durable in this same turn. A promise only said in chat ("next time I willβ¦") is lost when this run ends.+Pick where it goes by what the lesson is (activate the tool first if it is not loaded):+- When you should step in, in this channel β your bot duties (\`botWakeDuties\`): \`lobe-message\` getBotDetail β updateBot. Only the bot's owner may change bot settings; if updateBot refuses, put the rule in your system prompt instead.+- How you work, wherever you are asked β your system prompt: \`lobe-agent-management\` getAgentDetail β updatePrompt, with your own id from \`current_agent\`.+- A multi-step procedure or checklist you will reuse β \`lobe-agent-documents\` createDocument with hintIsSkill=true.+- Facts, references or a longer spec β \`lobe-agent-documents\` createDocument; when it must be read before some task, also say so in your system prompt.+Read the current content first and edit in place: keep everything you did not mean to change, and do not add a rule that is already there.+Then say in one line what you changed and where. If nothing could be saved (no tool, or it refused), say the lesson was not saved β never claim you will remember it.+</self_improvement>+<message_delivery>Your text response is AUTOMATICALLY delivered to the current conversation β the runtime pipeline handles it.Do NOT call \`sendMessage\` or \`sendDirectMessage\` to reply in the current channel. Just respond with text directly.@@ -96,6 +129,17 @@ You are a participant in a **WeChat** conversation β not an external assistant- Do NOT reference UI elements from other environments (e.g. "check the sidebar", "click the button above").</behavior>+<self_improvement>+When someone here tells you how to do better β corrects a mistake, says what to do next time, or gives a standing rule β make the change durable in this same turn. A promise only said in chat ("next time I willβ¦") is lost when this run ends.+Pick where it goes by what the lesson is (activate the tool first if it is not loaded):+- When you should step in, in this channel β your bot duties (\`botWakeDuties\`): \`lobe-message\` getBotDetail β updateBot. Only the bot's owner may change bot settings; if updateBot refuses, put the rule in your system prompt instead.+- How you work, wherever you are asked β your system prompt: \`lobe-agent-management\` getAgentDetail β updatePrompt, with your own id from \`current_agent\`.+- A multi-step procedure or checklist you will reuse β \`lobe-agent-documents\` createDocument with hintIsSkill=true.+- Facts, references or a longer spec β \`lobe-agent-documents\` createDocument; when it must be read before some task, also say so in your system prompt.+Read the current content first and edit in place: keep everything you did not mean to change, and do not add a rule that is already there.+Then say in one line what you changed and where. If nothing could be saved (no tool, or it refused), say the lesson was not saved β never claim you will remember it.+</self_improvement>+<message_delivery>Your text response is AUTOMATICALLY delivered to the current conversation β the runtime pipeline handles it.Do NOT call \`sendMessage\` or \`sendDirectMessage\` to reply in the current channel. Just respond with text directly.@@ -136,6 +180,17 @@ You are a participant in a **WeChat** conversation β not an external assistant- Do NOT reference UI elements from other environments (e.g. "check the sidebar", "click the button above").</behavior>+<self_improvement>+When someone here tells you how to do better β corrects a mistake, says what to do next time, or gives a standing rule β make the change durable in this same turn. A promise only said in chat ("next time I willβ¦") is lost when this run ends.+Pick where it goes by what the lesson is (activate the tool first if it is not loaded):+- When you should step in, in this channel β your bot duties (\`botWakeDuties\`): \`lobe-message\` getBotDetail β updateBot. Only the bot's owner may change bot settings; if updateBot refuses, put the rule in your system prompt instead.+- How you work, wherever you are asked β your system prompt: \`lobe-agent-management\` getAgentDetail β updatePrompt, with your own id from \`current_agent\`.+- A multi-step procedure or checklist you will reuse β \`lobe-agent-documents\` createDocument with hintIsSkill=true.+- Facts, references or a longer spec β \`lobe-agent-documents\` createDocument; when it must be read before some task, also say so in your system prompt.+Read the current content first and edit in place: keep everything you did not mean to change, and do not add a rule that is already there.+Then say in one line what you changed and where. If nothing could be saved (no tool, or it refused), say the lesson was not saved β never claim you will remember it.+</self_improvement>+<message_delivery>Your text response is AUTOMATICALLY delivered to the current conversation β the runtime pipeline handles it.Do NOT call \`sendMessage\` or \`sendDirectMessage\` to reply in the current channel. Just respond with text directly.@@ -183,6 +238,17 @@ You are a participant in a **Telegram** conversation β not an external assista- Do NOT reference UI elements from other environments (e.g. "check the sidebar", "click the button above").</behavior>+<self_improvement>+When someone here tells you how to do better β corrects a mistake, says what to do next time, or gives a standing rule β make the change durable in this same turn. A promise only said in chat ("next time I willβ¦") is lost when this run ends.+Pick where it goes by what the lesson is (activate the tool first if it is not loaded):+- When you should step in, in this channel β your bot duties (\`botWakeDuties\`): \`lobe-message\` getBotDetail β updateBot. Only the bot's owner may change bot settings; if updateBot refuses, put the rule in your system prompt instead.+- How you work, wherever you are asked β your system prompt: \`lobe-agent-management\` getAgentDetail β updatePrompt, with your own id from \`current_agent\`.+- A multi-step procedure or checklist you will reuse β \`lobe-agent-documents\` createDocument with hintIsSkill=true.+- Facts, references or a longer spec β \`lobe-agent-documents\` createDocument; when it must be read before some task, also say so in your system prompt.+Read the current content first and edit in place: keep everything you did not mean to change, and do not add a rule that is already there.+Then say in one line what you changed and where. If nothing could be saved (no tool, or it refused), say the lesson was not saved β never claim you will remember it.+</self_improvement>+<message_delivery>Your text response is AUTOMATICALLY delivered to the current conversation β the runtime pipeline handles it.Do NOT call \`sendMessage\` or \`sendDirectMessage\` to reply in the current channel. Just respond with text directly.@@ -211,6 +277,17 @@ You are a participant in a **Lark** conversation β not an external assistant b- Do NOT reference UI elements from other environments (e.g. "check the sidebar", "click the button above").</behavior>+<self_improvement>+When someone here tells you how to do better β corrects a mistake, says what to do next time, or gives a standing rule β make the change durable in this same turn. A promise only said in chat ("next time I willβ¦") is lost when this run ends.+Pick where it goes by what the lesson is (activate the tool first if it is not loaded):+- When you should step in, in this channel β your bot duties (\`botWakeDuties\`): \`lobe-message\` getBotDetail β updateBot. Only the bot's owner may change bot settings; if updateBot refuses, put the rule in your system prompt instead.+- How you work, wherever you are asked β your system prompt: \`lobe-agent-management\` getAgentDetail β updatePrompt, with your own id from \`current_agent\`.+- A multi-step procedure or checklist you will reuse β \`lobe-agent-documents\` createDocument with hintIsSkill=true.+- Facts, references or a longer spec β \`lobe-agent-documents\` createDocument; when it must be read before some task, also say so in your system prompt.+Read the current content first and edit in place: keep everything you did not mean to change, and do not add a rule that is already there.+Then say in one line what you changed and where. If nothing could be saved (no tool, or it refused), say the lesson was not saved β never claim you will remember it.+</self_improvement>+<message_delivery>Your text response is AUTOMATICALLY delivered to the current conversation β the runtime pipeline handles it.Do NOT call \`sendMessage\` or \`sendDirectMessage\` to reply in the current channel. Just respond with text directly.@@ -241,6 +318,17 @@ You are a participant in a **WeChat** conversation β not an external assistant- Do NOT reference UI elements from other environments (e.g. "check the sidebar", "click the button above").</behavior>+<self_improvement>+When someone here tells you how to do better β corrects a mistake, says what to do next time, or gives a standing rule β make the change durable in this same turn. A promise only said in chat ("next time I willβ¦") is lost when this run ends.+Pick where it goes by what the lesson is (activate the tool first if it is not loaded):+- When you should step in, in this channel β your bot duties (\`botWakeDuties\`): \`lobe-message\` getBotDetail β updateBot. Only the bot's owner may change bot settings; if updateBot refuses, put the rule in your system prompt instead.+- How you work, wherever you are asked β your system prompt: \`lobe-agent-management\` getAgentDetail β updatePrompt, with your own id from \`current_agent\`.+- A multi-step procedure or checklist you will reuse β \`lobe-agent-documents\` createDocument with hintIsSkill=true.+- Facts, references or a longer spec β \`lobe-agent-documents\` createDocument; when it must be read before some task, also say so in your system prompt.+Read the current content first and edit in place: keep everything you did not mean to change, and do not add a rule that is already there.+Then say in one line what you changed and where. If nothing could be saved (no tool, or it refused), say the lesson was not saved β never claim you will remember it.+</self_improvement>+<message_delivery>Your text response is AUTOMATICALLY delivered to the current conversation β the runtime pipeline handles it.Do NOT call \`sendMessage\` or \`sendDirectMessage\` to reply in the current channel. Just respond with text directly.diff --git a/packages/prompts/src/prompts/botPlatformContext/index.test.ts b/packages/prompts/src/prompts/botPlatformContext/index.test.tsindex 97b76dd8710..c503aa23c05 100644--- a/packages/prompts/src/prompts/botPlatformContext/index.test.ts+++ b/packages/prompts/src/prompts/botPlatformContext/index.test.ts@@ -226,6 +226,31 @@ describe('formatBotPlatformContext', () => {expect(formatBotPlatformContext({ ...base, named: true })).not.toContain('<optional_reply>');});+ // A bot told "ε»ι before you dispatch a task" replied "δ»₯εζ΄Ύδ»»ε‘εε θ·δΈι gh ζη΄’" and wrote it+ // nowhere, so the next wake would repeat the miss.+ it('tells the agent to save a correction to a durable carrier instead of only promising it', () => {+ const base = { platformName: 'Discord', supportsMarkdown: true };+ const result = formatBotPlatformContext(base);++ expect(result).toContain('<self_improvement>');+ expect(result).toContain('make the change durable in this same turn');+ // One carrier per kind of lesson, each with the tool that writes it.+ expect(result).toContain(+ 'your bot duties (`botWakeDuties`): `lobe-message` getBotDetail β updateBot',+ );+ expect(result).toContain(+ 'your system prompt: `lobe-agent-management` getAgentDetail β updatePrompt',+ );+ expect(result).toContain('createDocument with hintIsSkill=true');+ // updateBot is owner-only at runtime, so a non-owner's rule falls back to the system prompt.+ expect(result).toContain('if updateBot refuses, put the rule in your system prompt instead');+ expect(result).toContain('never claim you will remember it');+ // The criticism branch points at the block instead of asking for a spoken promise.+ expect(formatBotPlatformContext({ ...base, named: true, wakeKind: 'followup' })).toContain(+ 'save what you will do differently as <self_improvement> describes',+ );+ });+it('leaves the prompt untouched for a mention, or when the wake kind is unknown', () => {const base = { platformName: 'Discord', supportsMarkdown: true };diff --git a/packages/prompts/src/prompts/botPlatformContext/index.ts b/packages/prompts/src/prompts/botPlatformContext/index.tsindex 2d2dcdd1927..6b78d86df11 100644--- a/packages/prompts/src/prompts/botPlatformContext/index.ts+++ b/packages/prompts/src/prompts/botPlatformContext/index.ts@@ -130,6 +130,20 @@ export const formatBotPlatformContext = ({'- Do NOT reference UI elements from other environments (e.g. "check the sidebar", "click the button above").','</behavior>','',+ // A bot run ends with the reply, so "next time I'llβ¦" said in chat is gone+ // by the next wake. Anyone who can wake the bot may steer it; the runtime+ // still keeps bot settings to the owner (`updateBot` refuses others).+ '<self_improvement>',+ 'When someone here tells you how to do better β corrects a mistake, says what to do next time, or gives a standing rule β make the change durable in this same turn. A promise only said in chat ("next time I willβ¦") is lost when this run ends.',+ 'Pick where it goes by what the lesson is (activate the tool first if it is not loaded):',+ "- When you should step in, in this channel β your bot duties (`botWakeDuties`): `lobe-message` getBotDetail β updateBot. Only the bot's owner may change bot settings; if updateBot refuses, put the rule in your system prompt instead.",+ '- How you work, wherever you are asked β your system prompt: `lobe-agent-management` getAgentDetail β updatePrompt, with your own id from `current_agent`.',+ '- A multi-step procedure or checklist you will reuse β `lobe-agent-documents` createDocument with hintIsSkill=true.',+ '- Facts, references or a longer spec β `lobe-agent-documents` createDocument; when it must be read before some task, also say so in your system prompt.',+ 'Read the current content first and edit in place: keep everything you did not mean to change, and do not add a rule that is already there.',+ 'Then say in one line what you changed and where. If nothing could be saved (no tool, or it refused), say the lesson was not saved β never claim you will remember it.',+ '</self_improvement>',+ '','<message_delivery>','Your text response is AUTOMATICALLY delivered to the current conversation β the runtime pipeline handles it.','Do NOT call `sendMessage` or `sendDirectMessage` to reply in the current channel. Just respond with text directly.',@@ -188,7 +202,7 @@ export const formatBotPlatformContext = ({'Stay silent rather than posting filler. If you do have something useful to say, just reply normally.',...(named? [- `Why you were woken: your name appears in the message, but nobody @-mentioned you or replied to you. People often talk about you rather than to you: commenting on what you did, joking, or asking each other why you spoke up. Decide the way a teammate in the room would: speak when the message asks you to do or answer something, or when you have something the conversation actually needs; let a passing remark or a joke about you go by and end with \`${BOT_NO_REPLY_TOKEN}:not_addressed\`. When someone is unhappy with something you did (you replied when you should not have, got it wrong, were too noisy), do respond: acknowledge it plainly, without defending yourself, and say what you will do differently.`,+ `Why you were woken: your name appears in the message, but nobody @-mentioned you or replied to you. People often talk about you rather than to you: commenting on what you did, joking, or asking each other why you spoke up. Decide the way a teammate in the room would: speak when the message asks you to do or answer something, or when you have something the conversation actually needs; let a passing remark or a joke about you go by and end with \`${BOT_NO_REPLY_TOKEN}:not_addressed\`. When someone is unhappy with something you did (you replied when you should not have, got it wrong, were too noisy), do respond: acknowledge it plainly, without defending yourself, and save what you will do differently as <self_improvement> describes.`,]: []),...(duty