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.

✨ feat(agent): enable four tools on demand for new agents (#23428)

AmAzing-a8c7521601f4
diff --git a/apps/server/src/routers/lambda/agentGroup/lifecycle.ts b/apps/server/src/routers/lambda/agentGroup/lifecycle.ts
index d02e3271fc2..be27ff9a37a 100644
--- a/apps/server/src/routers/lambda/agentGroup/lifecycle.ts
+++ b/apps/server/src/routers/lambda/agentGroup/lifecycle.ts
@@ -119,9 +119,6 @@ export const lifecycleRouter = router({
// 1. Batch create virtual member agents
const memberConfigs = input.members.map((member) => ({
...member,
- // See the `batchCreateAgentsInGroup` cast above for why this bridges
- // to `string[]` instead of failing type-check.
- plugins: member.plugins as unknown as string[] | undefined,
tags: member.tags as string[] | undefined,
virtual: true,
...(groupVisibility ? { visibility: groupVisibility } : {}),
diff --git a/apps/server/src/routers/lambda/agentGroup/members.ts b/apps/server/src/routers/lambda/agentGroup/members.ts
index f5470771e30..b500a711099 100644
--- a/apps/server/src/routers/lambda/agentGroup/members.ts
+++ b/apps/server/src/routers/lambda/agentGroup/members.ts
@@ -66,10 +66,6 @@ export const membersRouter = router({
// Batch create virtual agents
const agentConfigs = input.agents.map((agent) => ({
...agent,
- // `agentModel.batchCreate`'s config type is still `plugins?: string[]`
- // (widening deferred to the tri-state rollout's final phase); the
- // zod schema above already allows the tri-state object shape through.
- plugins: agent.plugins as unknown as string[] | undefined,
tags: agent.tags as string[] | undefined,
virtual: true,
}));
diff --git a/apps/server/src/services/agent/index.ts b/apps/server/src/services/agent/index.ts
index 11c646a81d7..a00031d01bb 100644
--- a/apps/server/src/services/agent/index.ts
+++ b/apps/server/src/services/agent/index.ts
@@ -108,7 +108,6 @@ export class AgentService {
const agent = await this.agentModel.create({
...input.config,
- plugins: input.config?.plugins as unknown as string[] | undefined,
sessionGroupId: input.groupId,
...(visibility || folderVisibility ? { visibility: visibility ?? folderVisibility } : {}),
});
@@ -439,11 +438,6 @@ export class AgentService {
}
// 1. Execute update
- // `AgentItem` here is the `@lobechat/types` domain shape (plugins:
- // AgentPluginEntry[]); `agentModel.updateConfig` takes the DB-layer
- // AgentItem, whose `plugins` column type is intentionally left as
- // `string[]` (only the domain types are widened for the tri-state
- // rollout, not the JSONB column's compile-time annotation).
await this.agentModel.updateConfig(agentId, value as any, replaceWorkingDirDeviceIds);
// 2. Query and return updated data (with default config merged)
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/groupAgentBuilder.ts b/apps/server/src/services/toolExecution/serverRuntimes/groupAgentBuilder.ts
index 9a73a6818c8..221c1388d8a 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/groupAgentBuilder.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/groupAgentBuilder.ts
@@ -402,9 +402,7 @@ export const groupAgentBuilderRuntime: ServerRuntimeRegistration = {
{
avatar: params.avatar,
description: params.description,
- // Domain tool plugins support structured entries, while the DB
- // model's JSONB column still carries its legacy string[] type.
- plugins: params.tools as unknown as string[] | undefined,
+ plugins: params.tools,
systemRole: params.systemRole,
title: params.title,
virtual: true,
@@ -449,7 +447,7 @@ export const groupAgentBuilderRuntime: ServerRuntimeRegistration = {
params.agents.map((agent) => ({
avatar: agent.avatar,
description: agent.description,
- plugins: agent.tools as unknown as string[] | undefined,
+ plugins: agent.tools,
systemRole: agent.systemRole,
title: agent.title,
virtual: true,
diff --git a/packages/database/src/models/__tests__/agent.characterization.test.ts b/packages/database/src/models/__tests__/agent.characterization.test.ts
index 3fa1af3c448..5fcf8274a6d 100644
--- a/packages/database/src/models/__tests__/agent.characterization.test.ts
+++ b/packages/database/src/models/__tests__/agent.characterization.test.ts
@@ -170,6 +170,32 @@ afterEach(async () => {
});
describe('AgentModel - characterization', () => {
+ it('persists four on-demand tools for new agents and respects an explicit tool list', async () => {
+ const model = new AgentModel(serverDB, userId);
+ const created = await model.create({ title: 'New assistant' });
+ const [ordinary, empty, configured, virtual, market] = await model.batchCreate([
+ { title: 'Second assistant' },
+ { plugins: [] },
+ { plugins: ['custom-tool'] },
+ { virtual: true },
+ { marketIdentifier: 'from-market' },
+ ]);
+
+ // Media opt-ins keep the same representation as the picker so they also work in Chat mode.
+ const expected = [
+ { identifier: 'lobe-image-generation', mode: 'pinned' },
+ { identifier: 'lobe-video-generation', mode: 'pinned' },
+ { identifier: 'lobe-agent-documents', mode: 'auto' },
+ { identifier: 'lobe-agent', mode: 'auto' },
+ ];
+ expect(created.plugins).toEqual(expected);
+ expect(ordinary.plugins).toEqual(expected);
+ expect(empty.plugins).toEqual([]);
+ expect(configured.plugins).toEqual(['custom-tool']);
+ expect(virtual.plugins).toBeNull();
+ expect(market.plugins).toBeNull();
+ });
+
describe('public surface', () => {
it('exposes the same instance methods', () => {
const model = new AgentModel(serverDB, userId);
diff --git a/packages/database/src/models/agent/create.ts b/packages/database/src/models/agent/create.ts
index 3ffbbe86fab..b119072e0c6 100644
--- a/packages/database/src/models/agent/create.ts
+++ b/packages/database/src/models/agent/create.ts
@@ -5,6 +5,7 @@ import pMap from 'p-map';
import type { AgentItem } from '../../schemas';
import { agents, agentsToSessions, sessions } from '../../schemas';
+import { getNewAgentPlugins } from '../../utils/agentConfig';
import { normalizeInboxAgentMeta } from '../../utils/inboxAgent';
import { sanitizeAgentApiConfig } from '../../utils/sanitizeAgentApiConfig';
import { buildWorkspacePayload } from '../../utils/workspace';
@@ -41,6 +42,7 @@ export const create = async (
...config,
agencyConfig,
model: typeof config.model === 'string' ? config.model : null,
+ plugins: getNewAgentPlugins(config),
},
),
])
@@ -91,6 +93,7 @@ export const batchCreate = async (
{
...config,
model: typeof config.model === 'string' ? config.model : null,
+ plugins: getNewAgentPlugins(config),
},
),
),
diff --git a/packages/database/src/models/session.ts b/packages/database/src/models/session.ts
index 3098f4a2125..895bccbf458 100644
--- a/packages/database/src/models/session.ts
+++ b/packages/database/src/models/session.ts
@@ -312,11 +312,6 @@ export class SessionModel {
if (item) return;
return await this.create({
- // `merge` returns the `@lobechat/types` LobeAgentConfig shape
- // (plugins: AgentPluginEntry[]); `create`'s `config` is the DB-layer
- // NewAgent, whose `plugins` column type is intentionally left as
- // `string[]` (only the domain types are widened for the tri-state
- // rollout, not the JSONB column's compile-time annotation).
config: merge(DEFAULT_AGENT_CONFIG, defaultAgentConfig) as Partial<NewAgent>,
slug: INBOX_SESSION_ID,
type: 'agent',
diff --git a/packages/database/src/repositories/agentGroup/index.ts b/packages/database/src/repositories/agentGroup/index.ts
index f9b74f675de..3c2f1a910bd 100644
--- a/packages/database/src/repositories/agentGroup/index.ts
+++ b/packages/database/src/repositories/agentGroup/index.ts
@@ -287,11 +287,7 @@ export class AgentGroupRepository {
description: supervisorConfig?.description,
model: supervisorConfig?.model,
params: supervisorConfig?.params,
- // The `plugins` column is still typed `string[]` at the schema layer
- // (widening deferred to the tri-state rollout's final phase) but
- // legitimately holds mixed AgentPluginEntry[] at runtime β€” JSONB has
- // no schema enforcement.
- plugins: supervisorConfig?.plugins as unknown as string[] | undefined,
+ plugins: supervisorConfig?.plugins,
provider: supervisorConfig?.provider,
systemRole: supervisorConfig?.systemRole,
tags: supervisorConfig?.tags,
diff --git a/packages/database/src/repositories/dataImporter/deprecated/index.ts b/packages/database/src/repositories/dataImporter/deprecated/index.ts
index 46f0d822f48..211edaf9741 100644
--- a/packages/database/src/repositories/dataImporter/deprecated/index.ts
+++ b/packages/database/src/repositories/dataImporter/deprecated/index.ts
@@ -152,14 +152,6 @@ export class DeprecatedDataImporterRepos {
.values(
shouldInsertSessionAgents.map(({ config, meta }) => ({
...config,
- // `config` is the `@lobechat/types` LobeAgentConfig shape
- // (plugins: AgentPluginEntry[]); the `agents` table's
- // `plugins` column is intentionally left typed `string[]`
- // (only the domain types are widened for the tri-state
- // rollout, not the JSONB column's compile-time annotation).
- // Legacy import payloads only ever contain bare strings
- // anyway.
- plugins: config.plugins as unknown as string[] | undefined,
...meta,
userId: this.userId,
workspaceId: this.workspaceId ?? null,
diff --git a/packages/database/src/schemas/agent.ts b/packages/database/src/schemas/agent.ts
index 6682b8b9416..78d42e5cd20 100644
--- a/packages/database/src/schemas/agent.ts
+++ b/packages/database/src/schemas/agent.ts
@@ -1,4 +1,5 @@
import type {
+ AgentPluginEntry,
AgentProfile,
LobeAgentAgencyConfig,
LobeAgentChatConfig,
@@ -71,7 +72,7 @@ export const agents = pgTable(
*/
societyId: text('society_id'),
- plugins: jsonb('plugins').$type<string[]>(),
+ plugins: jsonb('plugins').$type<AgentPluginEntry[]>(),
clientId: text('client_id'),
diff --git a/packages/database/src/utils/agentConfig.ts b/packages/database/src/utils/agentConfig.ts
index 9eca83c9766..ee416af1bb1 100644
--- a/packages/database/src/utils/agentConfig.ts
+++ b/packages/database/src/utils/agentConfig.ts
@@ -1,8 +1,37 @@
import { DEFAULT_AGENT_CONFIG } from '@lobechat/const';
-import type { LobeAgentConfig } from '@lobechat/types';
+import { type AgentPluginEntry, type LobeAgentConfig, resolveToolMode } from '@lobechat/types';
import { cleanObject, merge } from '@lobechat/utils';
+import { isRecord } from '@lobechat/utils/object';
import type { PartialDeep } from 'type-fest';
+import type { NewAgent } from '../schemas';
+
+/** Seed the picker's on-demand choices once, when creating an ordinary agent. */
+export const getNewAgentPlugins = (
+ config: Pick<
+ NewAgent,
+ 'agencyConfig' | 'chatConfig' | 'marketIdentifier' | 'params' | 'plugins' | 'virtual'
+ >,
+): AgentPluginEntry[] | null | undefined => {
+ if (
+ config.plugins !== undefined ||
+ config.virtual ||
+ config.marketIdentifier ||
+ (isRecord(config.params) && config.params.forkedFromIdentifier) ||
+ config.agencyConfig?.heterogeneousProvider ||
+ resolveToolMode(config.chatConfig) !== 'agent'
+ )
+ return config.plugins;
+
+ // Agent mode defers media pins too. Chat mode needs those pins when the user switches modes.
+ return [
+ { identifier: 'lobe-image-generation', mode: 'pinned' },
+ { identifier: 'lobe-video-generation', mode: 'pinned' },
+ { identifier: 'lobe-agent-documents', mode: 'auto' },
+ { identifier: 'lobe-agent', mode: 'auto' },
+ ];
+};
+
/** Shared by AgentService and execution snapshots: system β†’ server β†’ personal β†’ Agent. */
export const mergeAgentDefaultConfig = (
agent: Record<string, unknown>,
diff --git a/packages/openapi/src/routes/agents.route.test.ts b/packages/openapi/src/routes/agents.route.test.ts
index 576e28985b5..0df636d3053 100644
--- a/packages/openapi/src/routes/agents.route.test.ts
+++ b/packages/openapi/src/routes/agents.route.test.ts
@@ -68,6 +68,21 @@ describe('personal agents', () => {
expect(agent.personal).toBe(false);
});
+ it('returns the starter tools on create and keeps an explicit opt-out on subsequent reads', async () => {
+ const agent = await json(await request('/', { body: { title: 'Writer' }, method: 'POST' }));
+ expect(agent.plugins.map((plugin: { identifier: string }) => plugin.identifier)).toEqual([
+ 'lobe-image-generation',
+ 'lobe-video-generation',
+ 'lobe-agent-documents',
+ 'lobe-agent',
+ ]);
+
+ const plugins = [{ identifier: 'lobe-image-generation', mode: 'disabled' }];
+ const updated = await request(`/${agent.id}`, { body: { plugins }, method: 'PATCH' });
+ expect(updated.status).toBe(200);
+ expect((await json(await request(`/${agent.id}`))).plugins).toEqual(plugins);
+ });
+
it('filters the list by personal', async () => {
await request('/', { body: { personal: true, title: 'toby' }, method: 'POST' });
await request('/', { body: { title: 'Writer' }, method: 'POST' });
diff --git a/packages/openapi/src/services/agent.service.ts b/packages/openapi/src/services/agent.service.ts
index 44d0404daa7..863edae5617 100644
--- a/packages/openapi/src/services/agent.service.ts
+++ b/packages/openapi/src/services/agent.service.ts
@@ -4,6 +4,7 @@ import { AgentModel } from '@/database/models/agent';
import type { FileItem, KnowledgeBaseItem, NewAgent } from '@/database/schemas';
import { agents, agentsToSessions } from '@/database/schemas';
import type { LobeChatDatabase } from '@/database/type';
+import { getNewAgentPlugins } from '@/database/utils/agentConfig';
import { idGenerator, randomSlug } from '@/database/utils/idGenerator';
import { isWorkspacePrimaryOwner } from '@/server/services/workspacePermission';
@@ -130,8 +131,7 @@ export class AgentService extends BaseService {
metadata: request.personal ? { personal: true } : null,
model: request.model || null,
params: request.params ?? {},
- // JSONB accepts mixed plugin entries; the legacy DB column remains string[].
- plugins: request.plugins as unknown as string[] | undefined,
+ plugins: getNewAgentPlugins(request),
provider: request.provider || null,
slug: randomSlug(4), // Auto-generated slug
systemRole: request.systemRole || null,
@@ -232,8 +232,7 @@ export class AgentService extends BaseService {
: mergeJsonPatch(existingAgent.chatConfig, request.chatConfig);
}
if (request.description !== undefined) updateData.description = request.description ?? null;
- if (request.plugins !== undefined)
- updateData.plugins = request.plugins as unknown as string[];
+ if (request.plugins !== undefined) updateData.plugins = request.plugins;
if (request.model !== undefined) updateData.model = request.model ?? null;
if (request.provider !== undefined) updateData.provider = request.provider ?? null;
if (request.systemRole !== undefined) updateData.systemRole = request.systemRole ?? null;