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: execAgent should get builtin discoverable tools into manifests (#13804)

LiJian0b490a7268fc
diff --git a/src/server/modules/AgentRuntime/RuntimeExecutors.ts b/src/server/modules/AgentRuntime/RuntimeExecutors.ts
index 232e83be7d8..e4d1dd373cb 100644
--- a/src/server/modules/AgentRuntime/RuntimeExecutors.ts
+++ b/src/server/modules/AgentRuntime/RuntimeExecutors.ts
@@ -1389,6 +1389,12 @@ export const createRuntimeExecutors = (
});
execution = { attempts: 1, result: dispatchResult };
} else {
+ // Inject source from sourceMap so BuiltinToolsExecutor can route
+ // lobehubSkill / klavis tools correctly (LLM responses don't carry source)
+ if (toolSource && !chatToolPayload.source) {
+ chatToolPayload.source = toolSource;
+ }
+
// Execute tool using ToolExecutionService
log(`[${operationLogId}] Executing tool ${toolName} ...`);
execution = await executeToolWithRetry(
@@ -1683,6 +1689,15 @@ export const createRuntimeExecutors = (
});
execution = { attempts: 1, result: dispatchResult };
} else {
+ // Inject source from sourceMap so BuiltinToolsExecutor can route
+ // lobehubSkill / klavis tools correctly (LLM responses don't carry source)
+ const batchToolSource =
+ state.operationToolSet?.sourceMap?.[chatToolPayload.identifier] ??
+ state.toolSourceMap?.[chatToolPayload.identifier];
+ if (batchToolSource && !chatToolPayload.source) {
+ chatToolPayload.source = batchToolSource;
+ }
+
execution = await executeToolWithRetry(
() =>
toolExecutionService.executeTool(chatToolPayload, {
diff --git a/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts b/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts
index 412ac383cb9..9649b6965a9 100644
--- a/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts
+++ b/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts
@@ -315,8 +315,10 @@ describe('AiAgentService.execAgent - device tool pipeline (LOBE-5636)', () => {
const callArgs = mockCreateOperation.mock.calls[0][0];
const manifestMap = callArgs.toolSet.manifestMap;
- // RemoteDevice should NOT be in manifestMap — no manual injection
- expect(manifestMap[RemoteDeviceManifest.identifier]).toBeUndefined();
+ // RemoteDevice is present in manifestMap (discoverable builtin),
+ // but should NOT be in enabledToolIds when gateway is not configured
+ const enabledToolIds = callArgs.toolSet.enabledToolIds;
+ expect(enabledToolIds).not.toContain(RemoteDeviceManifest.identifier);
});
});
@@ -491,8 +493,8 @@ describe('AiAgentService.execAgent - device tool pipeline (LOBE-5636)', () => {
const manifestMap = callArgs.toolSet.manifestMap;
expect(manifestMap['test-tool']).toBe(mockManifest);
- // No extra manifests added manually
- expect(Object.keys(manifestMap)).toEqual(['test-tool']);
+ // manifestMap also includes discoverable builtin tools for activator discovery
+ expect(Object.keys(manifestMap)).toContain('test-tool');
});
});
});
diff --git a/src/server/services/aiAgent/index.ts b/src/server/services/aiAgent/index.ts
index 61f8da10c14..1a975ab6ab2 100644
--- a/src/server/services/aiAgent/index.ts
+++ b/src/server/services/aiAgent/index.ts
@@ -609,11 +609,34 @@ export class AiAgentService {
log('execAgent: enabled tool ids: %O', toolsResult.enabledToolIds);
+ // Start with the scoped manifest map (pluginIds + defaultToolIds)
const manifestMap = toolsEngine.getEnabledPluginManifests(pluginIds);
manifestMap.forEach((manifest, id) => {
toolManifestMap[id] = manifest;
});
+ // Also include discoverable builtin tools that are not yet in the map,
+ // so the activator can find their manifests when dynamically enabling them
+ // (e.g., lobe-creds, lobe-cron). Exclude discoverable:false tools to prevent
+ // internal infrastructure tools from being surfaced to the activator.
+ for (const tool of builtinTools) {
+ if (tool.discoverable !== false && !toolManifestMap[tool.identifier]) {
+ toolManifestMap[tool.identifier] = tool.manifest as LobeToolManifest;
+ }
+ }
+
+ // Include lobehub skill and klavis manifests for activator discovery
+ for (const manifest of lobehubSkillManifests) {
+ if (!toolManifestMap[manifest.identifier]) {
+ toolManifestMap[manifest.identifier] = manifest;
+ }
+ }
+ for (const manifest of klavisManifests) {
+ if (!toolManifestMap[manifest.identifier]) {
+ toolManifestMap[manifest.identifier] = manifest;
+ }
+ }
+
for (const manifest of lobehubSkillManifests) {
toolSourceMap[manifest.identifier] = 'lobehubSkill';
}