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(agent): make builtin tools discoverable by default (#23455)

AmAzing-b9c46964633c
diff --git a/apps/server/src/modules/Mecha/ContextEngineering/providers/index.ts b/apps/server/src/modules/Mecha/ContextEngineering/providers/index.ts
index 01a8c880df8..4f56ae124c8 100644
--- a/apps/server/src/modules/Mecha/ContextEngineering/providers/index.ts
+++ b/apps/server/src/modules/Mecha/ContextEngineering/providers/index.ts
@@ -1,6 +1,9 @@
import { type AgentState, selectToolSourceMap } from '@lobechat/agent-runtime';
import { formatWebOnboardingStateMessage } from '@lobechat/builtin-tool-web-onboarding/utils';
-import { defaultUninstalledBuiltinTools } from '@lobechat/builtin-tools';
+import {
+ resolveUninstalledBuiltinTools,
+ type UninstalledBuiltinToolsScope,
+} from '@lobechat/builtin-tools';
import { AGENT_PLAN_FILE_TYPE } from '@lobechat/const';
import type { AvailablePluginInfo } from '@lobechat/context-engine';
import {
@@ -462,20 +465,10 @@ export const createServerContextFactProviders = ({
// workspace plus the personal one β€” the same slot the tool store reads.
listUninstalledBuiltinIds: async () => {
const settings = await new UserModel(db, userId).getUserSettings();
- const tool = settings?.tool as
- | {
- uninstalledBuiltinTools?: string[];
- uninstalledBuiltinToolsByWorkspace?: Record<string, string[] | undefined>;
- }
- | null
- | undefined;
- const stored = workspaceId
- ? tool?.uninstalledBuiltinToolsByWorkspace?.[workspaceId]
- : tool?.uninstalledBuiltinTools;
- // Never configured (new account, or a workspace without its own slot)
- // means the default seed β€” non-recommended builtins start uninstalled β€”
- // exactly as the browser's tool store resolves it.
- return stored === undefined ? defaultUninstalledBuiltinTools : stored;
+ return resolveUninstalledBuiltinTools(
+ settings?.tool as UninstalledBuiltinToolsScope | undefined,
+ workspaceId,
+ );
},
listSandboxFiles: async (topicId) =>
diff --git a/apps/server/src/modules/Mecha/ContextEngineering/providers/serverContextFactProviders.test.ts b/apps/server/src/modules/Mecha/ContextEngineering/providers/serverContextFactProviders.test.ts
index 3666c1a09ff..d931a273264 100644
--- a/apps/server/src/modules/Mecha/ContextEngineering/providers/serverContextFactProviders.test.ts
+++ b/apps/server/src/modules/Mecha/ContextEngineering/providers/serverContextFactProviders.test.ts
@@ -1,4 +1,4 @@
-import { defaultUninstalledBuiltinTools } from '@lobechat/builtin-tools';
+import { defaultUninstalledBuiltinTools, onDemandBuiltinToolIds } from '@lobechat/builtin-tools';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { createServerContextFactProviders } from './index';
@@ -247,7 +247,9 @@ describe('createServerContextFactProviders', () => {
state: {} as never,
}).listUninstalledBuiltinIds!(),
).resolves.toEqual(defaultUninstalledBuiltinTools);
- expect(defaultUninstalledBuiltinTools.length).toBeGreaterThan(0);
+ expect(
+ defaultUninstalledBuiltinTools.filter((id) => onDemandBuiltinToolIds.includes(id)),
+ ).toEqual([]);
});
it('returns the app origin and the workspace slug when it resolves', async () => {
diff --git a/apps/server/src/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts b/apps/server/src/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts
index 2d8642222e4..ab25dffde63 100644
--- a/apps/server/src/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts
+++ b/apps/server/src/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts
@@ -284,29 +284,29 @@ describe('AiAgentService.execAgent - device tool pipeline ()', () => {
).toBeDefined();
});
- it.each([undefined, ['lobe-computer-use']])(
- 'gates Computer Use discovery on reported support %j',
- async (supportedTools) => {
+ it.each([
+ { discoverable: false, supportedTools: undefined },
+ { discoverable: false, supportedTools: [] },
+ { discoverable: true, supportedTools: [AuvManifest.identifier] },
+ ])(
+ 'gates default Computer Use discovery on reported support $supportedTools',
+ async ({ discoverable, supportedTools }) => {
const { deviceGateway } = await import('@/server/services/deviceGateway');
vi.spyOn(deviceGateway, 'isConfigured', 'get').mockReturnValue(true);
mockQueryDeviceList.mockResolvedValue([
{ deviceId: 'dev-1', hostname: 'Mac', online: true, platform: 'darwin' },
]);
mockQueryDeviceSystemInfo.mockResolvedValue({ supportedTools });
- // Computer Use is opt-in per agent; the device report gates it after that.
mockGetAgentConfig.mockResolvedValue(
- createBaseAgentConfig({
- agencyConfig: { executionTarget: 'local' },
- plugins: [{ identifier: AuvManifest.identifier, mode: 'auto' }],
- }),
+ createBaseAgentConfig({ agencyConfig: { executionTarget: 'local' } }),
);
await service.execAgent({ agentId: 'agent-1', prompt: 'Hello', deviceId: 'dev-1' });
const map = mockCreateOperation.mock.calls[0][0].toolSet.manifestMap;
- expect(Boolean(map[AuvManifest.identifier])).toBe(Boolean(supportedTools));
+ expect(Boolean(map[AuvManifest.identifier])).toBe(discoverable);
},
);
- it('keeps Computer Use out for an agent that has not turned it on, even on a supporting device', async () => {
+ it('keeps explicitly disabled Computer Use out even on a supporting device', async () => {
const { deviceGateway } = await import('@/server/services/deviceGateway');
vi.spyOn(deviceGateway, 'isConfigured', 'get').mockReturnValue(true);
mockQueryDeviceList.mockResolvedValue([
@@ -314,7 +314,10 @@ describe('AiAgentService.execAgent - device tool pipeline ()', () => {
]);
mockQueryDeviceSystemInfo.mockResolvedValue({ supportedTools: [AuvManifest.identifier] });
mockGetAgentConfig.mockResolvedValue(
- createBaseAgentConfig({ agencyConfig: { executionTarget: 'local' } }),
+ createBaseAgentConfig({
+ agencyConfig: { executionTarget: 'local' },
+ plugins: [{ identifier: AuvManifest.identifier, mode: 'disabled' }],
+ }),
);
await service.execAgent({ agentId: 'agent-1', prompt: 'Hello', deviceId: 'dev-1' });
const map = mockCreateOperation.mock.calls[0][0].toolSet.manifestMap;
diff --git a/apps/server/src/services/aiAgent/__tests__/execAgent.pluginTriState.test.ts b/apps/server/src/services/aiAgent/__tests__/execAgent.pluginTriState.test.ts
index a6e3f683c29..5b83c8a11b8 100644
--- a/apps/server/src/services/aiAgent/__tests__/execAgent.pluginTriState.test.ts
+++ b/apps/server/src/services/aiAgent/__tests__/execAgent.pluginTriState.test.ts
@@ -1,4 +1,3 @@
-import { onDemandBuiltinToolIds } from '@lobechat/builtin-tools';
import type * as ModelBankModule from 'model-bank';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -273,9 +272,9 @@ describe('AiAgentService.execAgent - agent plugin entries (on / off / disabled)'
expect(installedPluginsArg().map((p) => p.identifier)).toEqual(['plugin-a']);
expect(toolManifestMapArg()).toHaveProperty('plugin-a');
expect(disabledPluginIdsArg()).toContain('plugin-b');
- // The pinned builtin stays discoverable; only builtins the agent never chose are cut.
+ // Both the legacy pin and the implicit default remain discoverable.
expect(disabledPluginIdsArg()).not.toContain('lobe-image-generation');
- expect(disabledPluginIdsArg()).toContain('lobe-video-generation');
+ expect(disabledPluginIdsArg()).not.toContain('lobe-video-generation');
});
it('offers a pinned media tool up front in Chat mode, which has no activator', async () => {
@@ -333,9 +332,9 @@ describe('AiAgentService.execAgent - agent plugin entries (on / off / disabled)'
const installed = installedPluginsArg().map((p) => p.identifier);
expect(installed).toEqual(['plugin-a']);
expect(agentConfigPluginsArg()).toEqual([]);
- // Only builtins the agent never opted into are cut; the string entry is on.
+
expect(disabledPluginIdsArg()).not.toContain('plugin-a');
- expect(disabledPluginIdsArg().every((id) => onDemandBuiltinToolIds.includes(id))).toBe(true);
+ expect(disabledPluginIdsArg()).not.toContain('lobe-creds');
});
it('brings in a plugin the agent has off on the turn that @-mentions it', async () => {
diff --git a/apps/server/src/services/aiAgent/pipeline/__tests__/toolDiscovery.installedPlugins.test.ts b/apps/server/src/services/aiAgent/pipeline/__tests__/toolDiscovery.installedPlugins.test.ts
index 197d6db4ba4..149f0e4ceb6 100644
--- a/apps/server/src/services/aiAgent/pipeline/__tests__/toolDiscovery.installedPlugins.test.ts
+++ b/apps/server/src/services/aiAgent/pipeline/__tests__/toolDiscovery.installedPlugins.test.ts
@@ -1,3 +1,6 @@
+import { AuvManifest } from '@lobechat/builtin-tool-auv';
+import { onDemandBuiltinToolIds } from '@lobechat/builtin-tools';
+import { isToolEnabledByFeatureFlags } from '@lobechat/builtin-tools/featureGates';
import { type LobeToolManifest, ToolResolver } from '@lobechat/context-engine';
import { describe, expect, it, vi } from 'vitest';
@@ -158,7 +161,11 @@ describe('Agent first-turn tool payload', () => {
const capabilities = ['lobe-user-memory', 'lobe-web-browsing'];
expect(result.toolsResult.enabledToolIds.toSorted()).toEqual(loaders);
expect(offeredToolNames(result)).toHaveLength(6);
- expect(availableToolIds(result.toolManifestMap, loaders).toSorted()).toEqual(expected);
+ expect(
+ availableToolIds(result.toolManifestMap, loaders)
+ .filter((id) => capabilities.includes(id))
+ .toSorted(),
+ ).toEqual(expected);
const activated = result.toolsEngine!.generateToolsDetailed({
context: { isExplicitActivation: true },
model: 'test-model',
@@ -179,12 +186,31 @@ describe('Agent first-turn tool payload', () => {
});
describe('discoverTools β€” installed plugins are opt-in per agent', () => {
- it('only offers a configurable builtin to discovery when this agent opted in', async () => {
- const id = 'lobe-skill-store';
- expect((await run()).toolManifestMap[id]).toBeUndefined();
- const on = await run({ autoSkillIds: [id] });
- expect(availableToolIds(on.toolManifestMap, on.toolsResult.enabledToolIds)).toContain(id);
- expect(on.toolsResult.enabledToolIds).not.toContain(id);
+ // This server fixture has no device and no optional feature flags.
+ const availableBuiltins = onDemandBuiltinToolIds.filter(
+ (id) => id !== AuvManifest.identifier && isToolEnabledByFeatureFlags(id, {}),
+ );
+ it.each(availableBuiltins)('defers %s until activation and respects opt-out', async (id) => {
+ const result = await run();
+ expect(availableToolIds(result.toolManifestMap, result.toolsResult.enabledToolIds)).toContain(
+ id,
+ );
+ expect(result.toolsResult.enabledToolIds).not.toContain(id);
+ expect(offeredToolNames(result).filter((name) => name.startsWith(`${id}____`))).toEqual([]);
+ const activate = (engine: typeof result.toolsEngine) =>
+ engine!.generateToolsDetailed({
+ context: { isExplicitActivation: true },
+ model: 'test-model',
+ provider: 'test-provider',
+ skipDefaultTools: true,
+ toolIds: [id],
+ });
+ const activated = activate(result.toolsEngine);
+ expect(activated.enabledToolIds).toEqual([id]);
+ expect(offeredToolNames(activated)).toContainEqual(expect.stringMatching(`^${id}____`));
+ const off = await run({ disabledPluginIds: [id] });
+ expect(off.toolManifestMap[id]).toBeUndefined();
+ expect(activate(off.toolsEngine).enabledToolIds).not.toContain(id);
});
it('keeps an installed plugin the agent never turned on out of the run', async () => {
diff --git a/apps/server/src/services/aiAgent/pipeline/execTurn.ts b/apps/server/src/services/aiAgent/pipeline/execTurn.ts
index 01f5ae5457c..c275b4c65dc 100644
--- a/apps/server/src/services/aiAgent/pipeline/execTurn.ts
+++ b/apps/server/src/services/aiAgent/pipeline/execTurn.ts
@@ -1,7 +1,12 @@
import type { SandboxStorageClaim } from '@lobechat/builtin-tool-cloud-sandbox';
+import { isOnDemandBuiltinTool } from '@lobechat/builtin-tools';
import type { LobeChatDatabase } from '@lobechat/database';
import type { AgentSenderMetadata, ExecAgentResult, UserInterventionConfig } from '@lobechat/types';
-import { agentShareFileAccessScope, ordinaryFileAccessScope } from '@lobechat/types';
+import {
+ agentShareFileAccessScope,
+ ordinaryFileAccessScope,
+ resolveToolMode,
+} from '@lobechat/types';
import { nanoid } from '@lobechat/utils';
import debug from 'debug';
@@ -621,10 +626,13 @@ export const execAgentTurn = async (
}
// 4. Fetch user settings (memory config + timezone)
- const { enableExpertise, globalMemoryEnabled, userTimezone } = await traceSendStage(
- 'run_settings',
- () => resolveRunSettings({ agentConfig, runFacts, shareGate }),
- );
+ const { enableExpertise, globalMemoryEnabled, uninstalledBuiltinIds, userTimezone } =
+ await traceSendStage('run_settings', () =>
+ resolveRunSettings({ agentConfig, runFacts, shareGate, workspaceId: deps.workspaceId }),
+ );
+ if (!shareGate && !exclusivePluginIds && resolveToolMode(agentConfig.chatConfig) === 'agent') {
+ disabledPluginIds.push(...uninstalledBuiltinIds.filter(isOnDemandBuiltinTool));
+ }
log(
'execAgent: globalMemoryEnabled=%s, timezone=%s',
globalMemoryEnabled,
diff --git a/apps/server/src/services/aiAgent/pipeline/runSettings.ts b/apps/server/src/services/aiAgent/pipeline/runSettings.ts
index 832ab88247c..5ff41d4e530 100644
--- a/apps/server/src/services/aiAgent/pipeline/runSettings.ts
+++ b/apps/server/src/services/aiAgent/pipeline/runSettings.ts
@@ -1,3 +1,7 @@
+import {
+ resolveUninstalledBuiltinTools,
+ type UninstalledBuiltinToolsScope,
+} from '@lobechat/builtin-tools';
import debug from 'debug';
import type { AgentConfigWithId } from '@/server/services/agent';
@@ -11,11 +15,13 @@ export interface RunSettingsInput {
agentConfig: AgentConfigWithId;
runFacts: RunFacts;
shareGate?: AgentShareGate;
+ workspaceId?: string;
}
export interface RunSettings {
enableExpertise: boolean;
globalMemoryEnabled: boolean;
+ uninstalledBuiltinIds: string[];
userTimezone?: string;
}
@@ -24,14 +30,20 @@ export const resolveRunSettings = async ({
agentConfig,
runFacts,
shareGate,
+ workspaceId,
}: RunSettingsInput): Promise<RunSettings> => {
// Agent-level memory config takes priority; fallback to user-level setting
const agentMemoryEnabled = agentConfig.chatConfig?.memory?.enabled;
let globalMemoryEnabled = agentMemoryEnabled ?? false;
let enableExpertise = false;
+ let uninstalledBuiltinIds: string[] = [];
let userTimezone: string | undefined;
try {
const settings = await runFacts.userSettings();
+ uninstalledBuiltinIds = resolveUninstalledBuiltinTools(
+ settings?.tool as UninstalledBuiltinToolsScope | undefined,
+ workspaceId,
+ );
const memorySettings = settings?.memory as { enabled?: boolean } | undefined;
globalMemoryEnabled = agentMemoryEnabled ?? memorySettings?.enabled !== false;
@@ -67,5 +79,5 @@ export const resolveRunSettings = async ({
enableExpertise = false;
}
- return { enableExpertise, globalMemoryEnabled, userTimezone };
+ return { enableExpertise, globalMemoryEnabled, uninstalledBuiltinIds, userTimezone };
};
diff --git a/apps/server/src/services/aiAgent/pipeline/toolDiscovery/index.ts b/apps/server/src/services/aiAgent/pipeline/toolDiscovery/index.ts
index eb4ecf0475b..6077d6b06e2 100644
--- a/apps/server/src/services/aiAgent/pipeline/toolDiscovery/index.ts
+++ b/apps/server/src/services/aiAgent/pipeline/toolDiscovery/index.ts
@@ -9,7 +9,7 @@ import {
SELF_FEEDBACK_INTENT_IDENTIFIER,
shouldExposeSelfFeedbackIntentTool,
} from '@lobechat/builtin-tool-self-iteration';
-import { getUnselectedBuiltinToolIds, runtimeManagedToolIds } from '@lobechat/builtin-tools';
+import { getUnavailableBuiltinToolIds, runtimeManagedToolIds } from '@lobechat/builtin-tools';
import { getFeatureDisabledToolIds } from '@lobechat/builtin-tools/featureGates';
import type {
AgentGroupConfig,
@@ -517,7 +517,10 @@ export const discoverTools = async (
// Share runs have a separate grant-based discovery pool and allowlist.
if (!shareGate)
disabledPluginIds.push(
- ...getUnselectedBuiltinToolIds([...optedInIds, ...agentPlugins, ...boundConnectorIds]),
+ ...getUnavailableBuiltinToolIds(
+ [...optedInIds, ...agentPlugins, ...boundConnectorIds],
+ agentConfig.chatConfig,
+ ),
);
// Resolve THE device decision for this run; see `resolveDevicePlan`.
diff --git a/packages/builtin-agents/src/agents/inbox/index.ts b/packages/builtin-agents/src/agents/inbox/index.ts
index 871a3ecbafc..3d64748d46f 100644
--- a/packages/builtin-agents/src/agents/inbox/index.ts
+++ b/packages/builtin-agents/src/agents/inbox/index.ts
@@ -1,4 +1,3 @@
-import { AgentDocumentsIdentifier } from '@lobechat/builtin-tool-agent-documents';
import { UserInteractionIdentifier } from '@lobechat/builtin-tool-user-interaction';
import { DEFAULT_INBOX_AVATAR } from '@lobechat/const';
@@ -14,7 +13,7 @@ import { createSystemRole } from './systemRole';
export const INBOX: BuiltinAgentDefinition = {
avatar: DEFAULT_INBOX_AVATAR,
runtime: (ctx) => ({
- plugins: [AgentDocumentsIdentifier, UserInteractionIdentifier, ...(ctx.plugins || [])],
+ plugins: [UserInteractionIdentifier, ...(ctx.plugins || [])],
// A user-customized prompt wins; the runtime one is only the default.
systemRole:
ctx.storedSystemRole ||
diff --git a/packages/builtin-tools/src/index.ts b/packages/builtin-tools/src/index.ts
index 9c05d8e6e09..d0f62654de8 100644
--- a/packages/builtin-tools/src/index.ts
+++ b/packages/builtin-tools/src/index.ts
@@ -650,8 +650,14 @@ export const onDemandBuiltinToolIds = builtinTools
.map((tool) => tool.identifier);
const onDemandBuiltinIds = new Set(onDemandBuiltinToolIds);
-/** An installed tool is not permission to offer it to every agent. */
-export const getUnselectedBuiltinToolIds = (available: Iterable<string>) => {
+/** Agent mode discovers installed builtins by default. Other modes keep their configured toolset. */
+export const getUnavailableBuiltinToolIds = (
+ available: Iterable<string>,
+ chatConfig?: Pick<LobeAgentChatConfig, 'toolMode' | 'enableAgentMode'> | null,
+ uninstalled: readonly string[] = [],
+) => {
+ if (resolveToolMode(chatConfig) === 'agent') return uninstalled.filter(isOnDemandBuiltinTool);
+
const allowed = new Set(available);
return onDemandBuiltinToolIds.filter((id) => !allowed.has(id));
};
@@ -662,13 +668,47 @@ const recommendedBuiltinIds = new Set(
);
/**
- * Non-hidden builtin tools that are NOT in RECOMMENDED_SKILLS.
+ * Non-selectable, non-recommended tools that require installation from the Skill Store.
* These tools default to uninstalled and must be explicitly installed by the user from the Skill Store.
*/
export const defaultUninstalledBuiltinTools = builtinTools
- .filter((t) => !t.hidden && !recommendedBuiltinIds.has(t.identifier))
+ .filter(
+ (t) =>
+ !t.hidden && !isOnDemandBuiltinTool(t.identifier) && !recommendedBuiltinIds.has(t.identifier),
+ )
.map((t) => t.identifier);
+/**
+ * Minimal view of `settings.tool` covering just the builtin-tool install slots.
+ * Typed locally so the helpers accept the loosened shape returned by
+ * `getUserState()` while still spreading the rest of `tool` through at runtime.
+ */
+export interface UninstalledBuiltinToolsScope {
+ uninstalledBuiltinTools?: string[];
+ uninstalledBuiltinToolsByWorkspace?: Record<string, string[] | undefined>;
+}
+
+/**
+ * Resolve the uninstalled-builtin-tools list for the active scope.
+ *
+ * - Personal context (`workspaceId == null`) β†’ the user's personal list.
+ * - Workspace context β†’ the per-workspace list; a workspace with no stored
+ * entry falls back to the default seed (a clean default state), never the
+ * user's personal customization.
+ *
+ * `undefined` (never configured) maps to the default seed in both scopes.
+ */
+export const resolveUninstalledBuiltinTools = (
+ tool: UninstalledBuiltinToolsScope | null | undefined,
+ workspaceId?: string | null,
+): string[] => {
+ const stored = workspaceId
+ ? tool?.uninstalledBuiltinToolsByWorkspace?.[workspaceId]
+ : tool?.uninstalledBuiltinTools;
+
+ return stored === undefined ? defaultUninstalledBuiltinTools : stored;
+};
+
const builtinIdentifierSet = new Set(builtinTools.map((tool) => tool.identifier));
/**
diff --git a/src/features/ChatInput/ActionBar/Tools/useActivationSets.test.ts b/src/features/ChatInput/ActionBar/Tools/useActivationSets.test.ts
index e5f60658c61..8c5bebb9603 100644
--- a/src/features/ChatInput/ActionBar/Tools/useActivationSets.test.ts
+++ b/src/features/ChatInput/ActionBar/Tools/useActivationSets.test.ts
@@ -19,8 +19,9 @@ describe('resolveActivationSets', () => {
const { checkedSet, disabledIdSet } = resolve([]);
expect([...disabledIdSet]).toEqual(
- expect.arrayContaining(['excalidraw', 'gmail', 'linear', 'slack', 'lobe-skill-store']),
+ expect.arrayContaining(['excalidraw', 'gmail', 'linear', 'slack']),
);
+ expect(disabledIdSet.has('lobe-creds')).toBe(false);
expect(checkedSet.size).toBe(0);
});
@@ -51,6 +52,6 @@ describe('resolveActivationSets', () => {
const { optInIds } = resolve([]);
expect(resolveImplicitMode('gmail', optInIds)).toBe('disabled');
- expect(resolveImplicitMode('lobe-image-generation', optInIds)).toBe('disabled');
+ expect(resolveImplicitMode('lobe-image-generation', optInIds)).toBe('auto');
});
});
diff --git a/src/features/ChatInput/ActionBar/Tools/useActivationSets.ts b/src/features/ChatInput/ActionBar/Tools/useActivationSets.ts
index a1143044862..9322c5ae0e4 100644
--- a/src/features/ChatInput/ActionBar/Tools/useActivationSets.ts
+++ b/src/features/ChatInput/ActionBar/Tools/useActivationSets.ts
@@ -24,9 +24,11 @@ export const CONNECTOR_MODES: AgentPluginMode[] = ['auto', 'disabled'];
export const resolveActivationSets = ({
connectorIds: connectorIdList,
librarySkillIds,
+ discoverBuiltins = true,
pinnedIds,
rawPlugins,
}: {
+ discoverBuiltins?: boolean;
connectorIds: readonly string[];
librarySkillIds: readonly string[];
/** The agent's pinned identifiers. */
@@ -35,14 +37,19 @@ export const resolveActivationSets = ({
rawPlugins: AgentPluginEntry[] | undefined;
}) => {
const connectorIds = new Set(connectorIdList);
- const optInIds = new Set([...onDemandBuiltinToolIds, ...librarySkillIds, ...connectorIdList]);
+ const optInIds = new Set([...librarySkillIds, ...connectorIdList]);
return {
checkedSet: new Set(
pinnedIds.filter((id) => !connectorIds.has(id) && !onDemandBuiltinToolIds.includes(id)),
),
connectorIds,
- disabledIdSet: new Set(resolveDisabledIds(rawPlugins, optInIds)),
+ disabledIdSet: new Set(
+ resolveDisabledIds(
+ rawPlugins,
+ discoverBuiltins ? optInIds : [...optInIds, ...onDemandBuiltinToolIds],
+ ),
+ ),
/** Identifiers that are off without an entry, so Auto must be written explicitly. */
optInIds,
};
@@ -52,6 +59,7 @@ export const resolveActivationSets = ({
export const useActivationSets = (
pinnedIds: string[],
rawPlugins: AgentPluginEntry[] | undefined,
+ discoverBuiltins: boolean,
) => {
const connectorIds = useToolStore(getConnectorIdentifiers, isEqual);
const marketAgentSkills = useToolStore(agentSkillsSelectors.getMarketAgentSkills, isEqual);
@@ -61,12 +69,13 @@ export const useActivationSets = (
() =>
resolveActivationSets({
connectorIds,
+ discoverBuiltins,
librarySkillIds: [...marketAgentSkills, ...userAgentSkills].map(
(skill) => skill.identifier,
),
pinnedIds,
rawPlugins,
}),
- [connectorIds, marketAgentSkills, userAgentSkills, pinnedIds, rawPlugins],
+ [connectorIds, discoverBuiltins, marketAgentSkills, userAgentSkills, pinnedIds, rawPlugins],
);
};
diff --git a/src/features/ChatInput/ActionBar/Tools/useControls.tsx b/src/features/ChatInput/ActionBar/Tools/useControls.tsx
index 788da1b5b6d..5ce58e99d35 100644
--- a/src/features/ChatInput/ActionBar/Tools/useControls.tsx
+++ b/src/features/ChatInput/ActionBar/Tools/useControls.tsx
@@ -3,7 +3,7 @@ import { MemoryManifest } from '@lobechat/builtin-tool-memory';
import { VideoGenerationIdentifier } from '@lobechat/builtin-tool-video-generation';
import { WebBrowsingManifest } from '@lobechat/builtin-tool-web-browsing';
import { getConnectorCatalog } from '@lobechat/const';
-import { parsePluginEntry, upsertPluginMode } from '@lobechat/types';
+import { parsePluginEntry, resolveToolMode, upsertPluginMode } from '@lobechat/types';
import type { ItemType } from '@lobehub/ui';
import { Avatar, confirmModal, Icon, Popover, Tag, Tooltip } from '@lobehub/ui';
import { McpIcon, SkillsIcon } from '@lobehub/ui/icons';
@@ -155,7 +155,11 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =
);
const marketAgentSkills = useToolStore(agentSkillsSelectors.getMarketAgentSkills, isEqual);
const userAgentSkills = useToolStore(agentSkillsSelectors.getUserAgentSkills, isEqual);
- const activationSets = useActivationSets(checked, rawPlugins);
+ const discoverBuiltins = useAgentStore(
+ (s) =>
+ resolveToolMode(agentByIdSelectors.getAgentConfigById(agentId)(s)?.chatConfig) === 'agent',
+ );
+ const activationSets = useActivationSets(checked, rawPlugins, discoverBuiltins);
const { disabledIdSet, optInIds } = activationSets;
const builtinList = useToolStore(builtinToolSelectors.metaListIncludingHidden, isEqual);
@@ -209,12 +213,12 @@ export const useControls = ({ closeDropdown }: { closeDropdown?: () => void } =
plugins,
id,
pinMediaTool ? 'pinned' : mode,
- resolveImplicitMode(id, optInIds),
+ mode === 'auto' && !discoverBuiltins ? 'disabled' : resolveImplicitMode(id, optInIds),
),
});
}
},
- [agentId, canEdit, optInIds, updateAgentConfig],
+ [agentId, canEdit, discoverBuiltins, optInIds, updateAgentConfig],
);
const openSkillPolicyMenu = useCallback((id: string) => {
diff --git a/src/features/ProfileEditor/AgentTool.tsx b/src/features/ProfileEditor/AgentTool.tsx
index 6effe48d222..4763ee14b79 100644
--- a/src/features/ProfileEditor/AgentTool.tsx
+++ b/src/features/ProfileEditor/AgentTool.tsx
@@ -1,8 +1,15 @@
'use client';
-import { isOnDemandBuiltinTool } from '@lobechat/builtin-tools';
+import { isOnDemandBuiltinTool, onDemandBuiltinToolIds } from '@lobechat/builtin-tools';
import { getConnectorCatalog } from '@lobechat/const';
-import { parsePluginEntry, upsertConnectorEnabled, upsertPluginMode } from '@lobechat/types';
+import {
+ getDisabledPluginIds,
+ getOptedInPluginIds,
+ parsePluginEntry,
+ resolveToolMode,
+ upsertConnectorEnabled,
+ upsertPluginMode,
+} from '@lobechat/types';
import type { ItemType } from '@lobehub/ui';
import { Avatar, Button, cssVar, Flexbox, Icon } from '@lobehub/ui';
import { McpIcon, SkillsIcon } from '@lobehub/ui/icons';
@@ -135,19 +142,6 @@ const AgentTool = memo<AgentToolProps>(
// A connector is two-state: this page turns it on (found on demand) or off, never pinned.
const connectorIdList = useToolStore(getConnectorIdentifiers, isEqual);
const connectorIds = useMemo(() => new Set(connectorIdList), [connectorIdList]);
- // Everything switched on for this agent: pinned entries, plus the entries that carry an
- // explicit `auto` β€” a connector turned on here, a library skill set to Auto in the chat input.
- const enabledIds = useMemo(
- () =>
- new Set(
- (config?.plugins ?? [])
- .map((entry) => parsePluginEntry(entry))
- .filter((entry) => entry.mode !== 'disabled')
- .map((entry) => entry.identifier),
- ),
- [config?.plugins],
- );
-
const updateAgentConfigById = useAgentStore((s) => s.updateAgentConfigById);
const installedPluginList = useToolStore(pluginSelectors.installedPluginMetaList, isEqual);
@@ -165,6 +159,19 @@ const AgentTool = memo<AgentToolProps>(
: builtinToolSelectors.metaList,
isEqual,
);
+ const implicitToolIds = useMemo(
+ () =>
+ resolveToolMode(config?.chatConfig) === 'agent'
+ ? profileBuiltinList.map((tool) => tool.identifier).filter(isOnDemandBuiltinTool)
+ : [],
+ [config?.chatConfig, profileBuiltinList],
+ );
+ const enabledIds = useMemo(() => {
+ const ids = new Set([...implicitToolIds, ...getOptedInPluginIds(config?.plugins)]);
+ for (const id of getDisabledPluginIds(config?.plugins)) ids.delete(id);
+ return ids;
+ }, [implicitToolIds, config?.plugins]);
+
const nonProfileConfigurableBuiltinToolIds = useToolStore(
builtinToolSelectors.nonProfileConfigurableBuiltinToolIds({
isManualMode: isManualSkillMode,
@@ -266,17 +273,15 @@ const AgentTool = memo<AgentToolProps>(
const hasEntry = (config?.plugins ?? []).some(
(entry) => parsePluginEntry(entry).identifier === pluginId,
);
- if (shouldEnable ? hasPlugin : !hasEntry) return;
+ if (shouldEnable ? hasPlugin : !hasEntry && !hasPlugin) return;
// upsertPluginMode operates on the raw (possibly mixed-shape) config,
// so an existing disabled entry is flipped in place instead of being
// dropped from the array.
await updateAgentConfigById(effectiveAgentId, {
- plugins:
- shouldEnable &&
- (allSkillIdentifiers.has(pluginId) ||
- connectorIds.has(pluginId) ||
- isOnDemandBuiltinTool(pluginId))
+ plugins: isOnDemandBuiltinTool(pluginId)
+ ? upsertConnectorEnabled(config?.plugins, pluginId, shouldEnable)
+ : shouldEnable && (allSkillIdentifiers.has(pluginId) || connectorIds.has(pluginId))
? upsertConnectorEnabled(config?.plugins, pluginId, true)
: upsertPluginMode(config?.plugins, pluginId, shouldEnable ? 'pinned' : 'auto'),
});
@@ -808,7 +813,7 @@ const AgentTool = memo<AgentToolProps>(
// ──────────────────────────────────────────────
// Build the set of all valid identifiers known to the system
const validIdentifiers = useMemo(() => {
- const all = new Set<string>();
+ const all = new Set(onDemandBuiltinToolIds);
// 1. Builtin tools (includes Composio metas)
for (const tool of knownBuiltinList) all.add(tool.identifier);
@@ -893,7 +898,7 @@ const AgentTool = memo<AgentToolProps>(
const listedTools = useMemo(() => {
const entries = (config?.plugins ?? []).map((entry) => parsePluginEntry(entry));
const visible = getVisibleProfileToolIds(
- entries.map((entry) => entry.identifier),
+ [...new Set([...implicitToolIds, ...entries.map((entry) => entry.identifier)])],
{
agentConnectorIdentifiers,
nonConfigurableBuiltinToolIdentifiers: nonProfileConfigurableBuiltinToolIdentifiers,
@@ -903,6 +908,7 @@ const AgentTool = memo<AgentToolProps>(
? visible
: visible.filter((id) => allSkillIdentifiers.has(id) === (kind === 'skills'));
}, [
+ implicitToolIds,
config?.plugins,
agentConnectorIdentifiers,
nonProfileConfigurableBuiltinToolIdentifiers,
diff --git a/src/helpers/toolEngineering/index.test.ts b/src/helpers/toolEngineering/index.test.ts
index ab09c91658a..5c27ca10c8e 100644
--- a/src/helpers/toolEngineering/index.test.ts
+++ b/src/helpers/toolEngineering/index.test.ts
@@ -624,10 +624,6 @@ describe('toolEngineering', () => {
skipDefaultTools: true,
toolIds: ['lobe-agent'],
};
- expect(
- createAgentToolsEngine(model).generateToolsDetailed(activation).enabledToolIds,
- ).toEqual([]);
- mockCurrentAgentAutoPlugins = ['lobe-agent'];
const engine = createAgentToolsEngine(model);
expect(engine.generateToolsDetailed({ ...model, toolIds: [] }).enabledToolIds).not.toContain(
@@ -661,7 +657,7 @@ describe('toolEngineering', () => {
expect(result.enabledToolIds).toEqual([]);
expect(result.filteredTools).toContainEqual({
id: 'lobe-agent',
- reason: 'not_found',
+ reason: 'incompatible',
});
expect(result.filteredTools).toContainEqual({
id: 'lobe-web-browsing',
diff --git a/src/helpers/toolEngineering/index.ts b/src/helpers/toolEngineering/index.ts
index 62a77f0b423..8fa926440a8 100644
--- a/src/helpers/toolEngineering/index.ts
+++ b/src/helpers/toolEngineering/index.ts
@@ -3,7 +3,7 @@
*/
import { AuvManifest } from '@lobechat/builtin-tool-auv';
import {
- getUnselectedBuiltinToolIds,
+ getUnavailableBuiltinToolIds,
getUserDisabledToolIds,
isOnDemandBuiltinTool,
} from '@lobechat/builtin-tools';
@@ -212,11 +212,15 @@ export const createAgentToolsEngine = (
disabledPluginIds: [
...getUserDisabledToolIds(agent.plugins, chatConfig),
...connectors.offIds,
- ...getUnselectedBuiltinToolIds([
- ...getOptedInPluginIds(agent.plugins),
- ...(options.runAgent?.enabledPluginIds ?? []),
- ...(pluginIds ?? []),
- ]),
+ ...getUnavailableBuiltinToolIds(
+ [
+ ...getOptedInPluginIds(agent.plugins),
+ ...(options.runAgent?.enabledPluginIds ?? []),
+ ...(pluginIds ?? []),
+ ],
+ chatConfig,
+ getToolStoreState().uninstalledBuiltinTools,
+ ),
...getFeatureDisabledToolIds(getServerConfigStoreState()?.featureFlags),
// This engine serves runs the browser executes; server-only tools have nothing to run here.
...serverOnlyToolIds,
diff --git a/src/services/chat/chat.test.ts b/src/services/chat/chat.test.ts
index ffa0b276d38..208a5b8739f 100644
--- a/src/services/chat/chat.test.ts
+++ b/src/services/chat/chat.test.ts
@@ -54,7 +54,7 @@ const mockCreateHeaderWithAuth = vi.hoisted(() =>
// Helper to compute expected date content from SystemDateProvider
const getCurrentDateContent = () => {
- const tz = 'UTC';
+ const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
const today = new Date();
const year = today.toLocaleString('en-US', { timeZone: tz, year: 'numeric' });
const month = today.toLocaleString('en-US', { month: '2-digit', timeZone: tz });
diff --git a/src/services/chat/index.ts b/src/services/chat/index.ts
index c81e32ccdba..355983a119e 100644
--- a/src/services/chat/index.ts
+++ b/src/services/chat/index.ts
@@ -1,5 +1,5 @@
import { stripAssistantReasoningForReplay } from '@lobechat/agent-runtime';
-import { getUnselectedBuiltinToolIds, getUserDisabledToolIds } from '@lobechat/builtin-tools';
+import { getUnavailableBuiltinToolIds, getUserDisabledToolIds } from '@lobechat/builtin-tools';
import {
REQUEST_AGENT_ID_HEADER,
REQUEST_OPERATION_ID_HEADER,
@@ -35,6 +35,7 @@ import { oneShotRelay } from '@/services/llmRelay';
import { getAgentStoreState } from '@/store/agent';
import { agentChatConfigSelectors, agentSelectors } from '@/store/agent/selectors';
import { aiProviderSelectors, getAiInfraStoreState } from '@/store/aiInfra';
+import { getToolStoreState } from '@/store/tool';
import { getUserStoreState, useUserStore } from '@/store/user';
import {
settingsSelectors,
@@ -240,10 +241,11 @@ class ChatService {
// discovery list too; one this turn already enabled (an @-mention) stays.
disabledPluginIds: [
...getUserDisabledToolIds(agentConfig.plugins, chatConfig),
- ...getUnselectedBuiltinToolIds([
- ...getOptedInPluginIds(agentConfig.plugins),
- ...(enabledToolIds ?? []),
- ]),
+ ...getUnavailableBuiltinToolIds(
+ [...getOptedInPluginIds(agentConfig.plugins), ...(enabledToolIds ?? [])],
+ chatConfig,
+ getToolStoreState().uninstalledBuiltinTools,
+ ),
...resolveAgentConnectorActivation(
{ chatConfig, plugins: agentConfig.plugins },
enabledToolIds,
diff --git a/src/store/tool/slices/builtin/projection.ts b/src/store/tool/slices/builtin/projection.ts
index 666edccb1e4..8b99e073fa7 100644
--- a/src/store/tool/slices/builtin/projection.ts
+++ b/src/store/tool/slices/builtin/projection.ts
@@ -1,7 +1,7 @@
-import { defaultUninstalledBuiltinTools } from '@lobechat/builtin-tools';
-
import { defineReplica } from '@/libs/replica';
+export { resolveUninstalledBuiltinTools } from '@lobechat/builtin-tools';
+
/**
* The uninstalled-builtin list is one entry: the active identity
* (`${userId}:${workspaceId ?? 'personal'}`) already partitions memory and
@@ -35,34 +35,3 @@ export const uninstalledBuiltinToolsResource = defineReplica<
storage: 'indexedDB',
version: 1,
});
-
-/**
- * Minimal view of `settings.tool` covering just the builtin-tool install slots.
- * Typed locally so the helpers accept the loosened shape returned by
- * `getUserState()` while still spreading the rest of `tool` through at runtime.
- */
-export interface UninstalledBuiltinToolsScope {
- uninstalledBuiltinTools?: string[];
- uninstalledBuiltinToolsByWorkspace?: Record<string, string[] | undefined>;
-}
-
-/**
- * Resolve the uninstalled-builtin-tools list for the active scope.
- *
- * - Personal context (`workspaceId == null`) β†’ the user's personal list.
- * - Workspace context β†’ the per-workspace list; a workspace with no stored
- * entry falls back to the default seed (a clean default state), never the
- * user's personal customization.
- *
- * `undefined` (never configured) maps to the default seed in both scopes.
- */
-export const resolveUninstalledBuiltinTools = (
- tool: UninstalledBuiltinToolsScope | undefined,
- workspaceId: string | null,
-): string[] => {
- const stored = workspaceId
- ? tool?.uninstalledBuiltinToolsByWorkspace?.[workspaceId]
- : tool?.uninstalledBuiltinTools;
-
- return stored === undefined ? defaultUninstalledBuiltinTools : stored;
-};