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.

♻️ refactor(activator): deduplicate Tools Activator system prompt (#23480)

AmAzing-ae78ffd14209
diff --git a/packages/builtin-tool-activator/src/systemRole.test.ts b/packages/builtin-tool-activator/src/systemRole.test.ts
new file mode 100644
index 00000000000..a6483fe46ec
--- /dev/null
+++ b/packages/builtin-tool-activator/src/systemRole.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, it } from 'vitest';
+
+import { getSystemPromptForShareVisitor, systemPrompt } from './systemRole';
+
+describe('builtin-tool-activator systemRole', () => {
+ it('includes upfront batch activation, skill activation, and skill store discovery in default prompt', () => {
+ expect(systemPrompt).toContain('activateTools');
+ expect(systemPrompt).toContain('<available_tools>');
+ expect(systemPrompt).toContain('reason');
+ expect(systemPrompt).toContain('activateSkill');
+ expect(systemPrompt).toContain('<selected_skill_context>');
+ expect(systemPrompt).toContain('<skill_store_discovery>');
+ expect(systemPrompt).toContain('lobe-skill-store');
+ });
+
+ it('gates Skill Store activation on availability and directs active stores to their API', () => {
+ expect(systemPrompt).toContain('If lobe-skill-store is in <available_tools>, activate it');
+ expect(systemPrompt).toContain('If already active, call it directly.');
+ });
+
+ it('omits skill store discovery for share visitors and gates activateSkill on withSkills', () => {
+ const withoutSkills = getSystemPromptForShareVisitor({ withSkills: false });
+ expect(withoutSkills).toContain('activateTools');
+ expect(withoutSkills).not.toContain('lobe-skill-store');
+ expect(withoutSkills).not.toContain('<skill_store_discovery>');
+ expect(withoutSkills).not.toContain('activateSkill');
+
+ const withSkills = getSystemPromptForShareVisitor({ withSkills: true });
+ expect(withSkills).toContain('activateTools');
+ expect(withSkills).toContain('activateSkill');
+ expect(withSkills).toContain('<selected_skill_context>');
+ expect(withSkills).not.toContain('lobe-skill-store');
+ expect(withSkills).not.toContain('<skill_store_discovery>');
+ });
+});
diff --git a/packages/builtin-tool-activator/src/systemRole.ts b/packages/builtin-tool-activator/src/systemRole.ts
index b0132279468..27d266976fd 100644
--- a/packages/builtin-tool-activator/src/systemRole.ts
+++ b/packages/builtin-tool-activator/src/systemRole.ts
@@ -1,55 +1,21 @@
-const intro = `You have access to a Tools Activator that allows you to dynamically activate tools on demand. Not all tools are loaded by default β€” you must activate them before use.`;
+const intro = `Not all tools are loaded by default. Use \`activateTools\` to enable tools from \`<available_tools>\` before calling them.`;
-const howItWorksSkill = `7. To activate a skill, use the \`activateSkill\` tool from lobe-skills β€” it returns instructions to follow
-`;
-
-const howItWorks = ({ withSkills }: { withSkills: boolean }) => `<how_it_works>
-1. Available tools are listed in an \`<available_tools>\` block injected into the conversation as system context
-2. Each entry shows the tool's identifier, name, and description
-3. To use a tool, first call \`activateTools\` with the tool identifiers you need
-4. After activation, the tool's full API schemas become available as native function calls in subsequent turns
-5. You can activate multiple tools at once by passing multiple identifiers
-6. Include the required concise \`reason\` field when calling \`activateTools\` so the user understands why activation is needed
-${withSkills ? howItWorksSkill : ''}</how_it_works>`;
+const skillGuideline = `\n- To load a skill from \`<available_skills>\`, use \`activateSkill\` (\`lobe-skills\`). Do not call \`activateSkill\` if the skill's content is already present in \`<selected_skill_context>\`.`;
-const toolSelectionSkill = `- **activateSkill** (provided by lobe-skills): Use this when the user's task matches one of the available skills
- - **IMPORTANT**: If a skill's content is already provided in \`<selected_skill_context>\` within the user message, do NOT call activateSkill for that skill β€” its instructions are already loaded and ready to use
-`;
-
-const toolSelectionGuidelines = ({
- withSkills,
-}: {
- withSkills: boolean;
-}) => `<tool_selection_guidelines>
-- **activateTools**: Call this when you need to use a tool that isn't yet activated
- - Review the \`<available_tools>\` list to find relevant tools for the user's task
- - Provide an array of tool identifiers to activate
- - Provide the required concise \`reason\` field explaining why those tools are needed for the current task
- - After activation, the tools' APIs will be available for you to call directly
- - Tools that are already active will be noted in the response
- - If an identifier is not found, it will be reported in the response
-${withSkills ? toolSelectionSkill : ''}</tool_selection_guidelines>`;
+const guidelines = ({ withSkills }: { withSkills: boolean }) => `<guidelines>
+- Plan ahead: identify all tools needed for the request and activate them together in a single \`activateTools\` call with a concise \`reason\`, rather than incrementally across turns.
+- Only activate tools relevant to the current request. Once activated, their APIs become available as direct function calls β€” do not re-activate them.${withSkills ? skillGuideline : ''}
+</guidelines>`;
const skillStoreDiscovery = `<skill_store_discovery>
For marketplace skill searches, skill install requests (including SKILL.md, GitHub or LobeHub skill URLs), or a specialized task that needs a capability missing from the available tools and skills, use the Skill Store. If lobe-skill-store is in <available_tools>, activate it before browsing or trying a CLI. If already active, call it directly.
</skill_store_discovery>`;
-const bestPractices = `<best_practices>
-- **IMPORTANT: Plan ahead and activate all needed tools upfront in a single call.** Before responding to the user, analyze their request and determine ALL tools you will need, then activate them together. Do NOT activate tools incrementally during a multi-step task.
-- Check the \`<available_tools>\` list before activating tools
-- Only activate tools that are relevant to the user's current request
-- After activation, use the tools' APIs directly β€” no need to call activateTools again for the same tools
-</best_practices>`;
-
export const systemPrompt = `${intro}
-${howItWorks({ withSkills: true })}
-
-${toolSelectionGuidelines({ withSkills: true })}
+${guidelines({ withSkills: true })}
${skillStoreDiscovery}
-
-${bestPractices}
`;
/**
@@ -60,9 +26,5 @@ ${bestPractices}
*/
export const getSystemPromptForShareVisitor = ({ withSkills }: { withSkills: boolean }) => `${intro}
-${howItWorks({ withSkills })}
-
-${toolSelectionGuidelines({ withSkills })}
-
-${bestPractices}
+${guidelines({ withSkills })}
`;