π€― 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
π fix(agent-group): inject orchestration tools when a user agent runs as group supervisor (#16346)
Arvin Xuf2380466031a
diff --git a/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts b/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.tsindex 8fc761a9b2f..b7b5c3526f3 100644--- a/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts+++ b/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts@@ -1,4 +1,6 @@// @vitest-environment node+import { GroupAgentBuilderManifest } from '@lobechat/builtin-tool-group-agent-builder';+import { GroupManagementManifest } from '@lobechat/builtin-tool-group-management';import { KnowledgeBaseManifest } from '@lobechat/builtin-tool-knowledge-base';import { LobeAgentManifest } from '@lobechat/builtin-tool-lobe-agent';import { LocalSystemManifest } from '@lobechat/builtin-tool-local-system';@@ -323,6 +325,48 @@ describe('createServerAgentToolsEngine', () => {expect(result.enabledToolIds).not.toContain(KnowledgeBaseManifest.identifier);});+ it('should auto-enable group orchestration tools when isGroupSupervisor is true', () => {+ const context = createMockContext();+ const engine = createServerAgentToolsEngine(context, {+ // Supervisor agent does not declare the group tools itself β they ship+ // only with the builtin group-supervisor, so the engine must inject them.+ agentConfig: { plugins: [] },+ isGroupSupervisor: true,+ model: 'gpt-4',+ provider: 'openai',+ });++ const result = engine.generateToolsDetailed({+ toolIds: [],+ model: 'gpt-4',+ provider: 'openai',+ });++ expect(result.enabledToolIds).toContain(GroupManagementManifest.identifier);+ // group-agent-builder has no server runtime, so it is deliberately NOT+ // advertised on a server-side supervisor run (it would throw if called).+ expect(result.enabledToolIds).not.toContain(GroupAgentBuilderManifest.identifier);+ });++ it('should not enable group orchestration tools for a non-supervisor run', () => {+ const context = createMockContext();+ const engine = createServerAgentToolsEngine(context, {+ agentConfig: { plugins: [] },+ isGroupSupervisor: false,+ model: 'gpt-4',+ provider: 'openai',+ });++ const result = engine.generateToolsDetailed({+ toolIds: [],+ model: 'gpt-4',+ provider: 'openai',+ });++ expect(result.enabledToolIds).not.toContain(GroupManagementManifest.identifier);+ expect(result.enabledToolIds).not.toContain(GroupAgentBuilderManifest.identifier);+ });+it('should include default tools (WebBrowsing, KnowledgeBase)', () => {const context = createMockContext();const engine = createServerAgentToolsEngine(context, {diff --git a/apps/server/src/modules/Mecha/AgentToolsEngine/index.ts b/apps/server/src/modules/Mecha/AgentToolsEngine/index.tsindex e0549cecf63..98e4718b013 100644--- a/apps/server/src/modules/Mecha/AgentToolsEngine/index.ts+++ b/apps/server/src/modules/Mecha/AgentToolsEngine/index.ts@@ -21,6 +21,7 @@ import {builtinTools,chatModeAllowedToolIds,defaultToolIds,+ groupSupervisorToolIds,} from '@lobechat/builtin-tools';import { createEnableChecker, type LobeToolManifest } from '@lobechat/context-engine';import { ToolsEngine } from '@lobechat/context-engine';@@ -136,6 +137,7 @@ export const createServerAgentToolsEngine = (globalMemoryEnabled = false,hasEnabledKnowledgeBases = false,isBotConversation = false,+ isGroupSupervisor = false,model,provider,} = params;@@ -230,6 +232,10 @@ export const createServerAgentToolsEngine = ([MemoryManifest.identifier]: globalMemoryEnabled,// Only auto-enable in bot conversations; otherwise let user's plugin selection take effect...(isBotConversation && { [MessageManifest.identifier]: true }),+ // Group supervisor: enable the orchestration toolset (see+ // `groupSupervisorToolIds`). The same list also feeds the candidate set+ // below, so the bundle has a single source of truth.+ ...(isGroupSupervisor && Object.fromEntries(groupSupervisorToolIds.map((id) => [id, true]))),// Remote-device proxy: shown only for device-capable targets when the// server has a proxy, no specific device is auto-activated yet, AND the// user has NOT explicitly selected a device. Once a device is explicitly@@ -258,11 +264,16 @@ export const createServerAgentToolsEngine = (builtinTools: buildAllowedBuiltinTools({ canUseDevice, disableLocalSystem }),// Add default tools based on configuration. Custom mode = exactly the// agent's plugins; chat mode = strict allow-list; agent mode = full defaults.+ // Agent mode: the supervisor's orchestration tools are neither in the+ // agent's plugins nor in `defaultToolIds`, so add them to the candidate set+ // here (the `agentModeRules` above then enable them). Enabling a tool that+ // isn't a candidate is a no-op β the checker only filters+ // `union(toolIds, defaultToolIds)`.defaultToolIds: isCustomMode? (agentConfig.plugins ?? []): isChatMode? chatModeAllowedToolIds- : defaultToolIds,+ : [...defaultToolIds, ...(isGroupSupervisor ? groupSupervisorToolIds : [])],// Post-merge wall: a plugin or Skill/Composio manifest claiming a// device identifier survives `buildAllowedBuiltinTools` (which only// filters the builtin source). Excluding the identifiers here dropsdiff --git a/apps/server/src/modules/Mecha/AgentToolsEngine/types.ts b/apps/server/src/modules/Mecha/AgentToolsEngine/types.tsindex a91f8a22e5d..cb4f59bae88 100644--- a/apps/server/src/modules/Mecha/AgentToolsEngine/types.ts+++ b/apps/server/src/modules/Mecha/AgentToolsEngine/types.ts@@ -105,6 +105,14 @@ export interface ServerCreateAgentToolsEngineParams {hasEnabledKnowledgeBases?: boolean;/** Whether the request originates from a bot conversation (auto-enables message tool) */isBotConversation?: boolean;+ /**+ * Whether this run is the group's supervisor (orchestrationRole === 'supervisor').+ * The group-orchestration tools ship only with the builtin group-supervisor+ * agent, so a user agent acting as supervisor would otherwise have no tool to+ * dispatch members and would silently degrade to a single-agent monologue.+ * When true the engine auto-enables the group-management + agent-builder tools.+ */+ isGroupSupervisor?: boolean;/** Model name for function calling compatibility check */model: string;/** Provider name for function calling compatibility check */diff --git a/apps/server/src/services/aiAgent/index.ts b/apps/server/src/services/aiAgent/index.tsindex 938f4a2bc45..d0454a95a94 100644--- a/apps/server/src/services/aiAgent/index.ts+++ b/apps/server/src/services/aiAgent/index.ts@@ -51,6 +51,7 @@ import { AgentModel } from '@/database/models/agent';import { AgentOperationModel } from '@/database/models/agentOperation';import { AgentSkillModel } from '@/database/models/agentSkill';import { AiModelModel } from '@/database/models/aiModel';+import { ChatGroupModel } from '@/database/models/chatGroup';import { ConnectorModel } from '@/database/models/connector';import { ConnectorToolModel } from '@/database/models/connectorTool';import { DeviceModel } from '@/database/models/device';@@ -2199,6 +2200,31 @@ export class AiAgentService {activeDeviceId ?? 'none',);+ // `appContext.orchestrationRole` is client-supplied (the execAgent /+ // execAgents schema accepts it, and execGroupAgent stamps it for whatever+ // agentId the caller passed), so it must NOT alone authorize the+ // group-orchestration toolset β otherwise any run marked+ // `{ orchestrationRole: 'supervisor', groupId }` could dispatch group+ // members. Verify against the persisted, ownership-scoped membership that+ // the executing agent really is this group's supervisor.+ let isGroupSupervisor = false;+ if (appContext?.orchestrationRole === 'supervisor' && appContext?.groupId) {+ const groupAgents = await new ChatGroupModel(+ this.db,+ this.userId,+ this.workspaceId,+ ).getGroupAgents(appContext.groupId);+ isGroupSupervisor = groupAgents.some(+ (member) => member.agentId === resolvedAgentId && member.role === 'supervisor',+ );+ if (!isGroupSupervisor)+ log(+ 'execAgent: orchestrationRole=supervisor but agent %s is not the supervisor of group %s β denying group tools',+ resolvedAgentId,+ appContext.groupId,+ );+ }+const toolsEngine = createServerAgentToolsEngine(toolsContext, {additionalManifests: [...lobehubSkillManifests,@@ -2223,6 +2249,7 @@ export class AiAgentService {globalMemoryEnabled,hasEnabledKnowledgeBases,isBotConversation,+ isGroupSupervisor,model,provider,});diff --git a/packages/builtin-tools/src/index.ts b/packages/builtin-tools/src/index.tsindex a3b191df82b..62e061fff78 100644--- a/packages/builtin-tools/src/index.ts+++ b/packages/builtin-tools/src/index.ts@@ -104,6 +104,27 @@ export const chatModeAllowedToolIds = [WebBrowsingManifest.identifier,];+/**+ * Tool IDs that make up the group supervisor's orchestration toolset:+ * dispatching members (speak / broadcast / delegate / executeAgentTask).+ *+ * These ship only with the builtin `group-supervisor` agent, but a group can+ * run a user's own agent as supervisor (`execGroupAgent` passes the configured+ * supervisor agentId, not the builtin slug). Such a run is verified as the+ * group's supervisor, and the tools engine uses this list β the single source+ * of truth β to both add these tools to the agent-mode candidate set and enable+ * them. Without it the supervisor has no way to dispatch members and degrades+ * to a single-agent monologue.+ *+ * NOTE: `lobe-group-agent-builder` (member CRUD: searchAgent / inviteAgent /+ * createAgent) is deliberately excluded β it has no server runtime registered+ * (`apps/server/.../serverRuntimes`), so advertising it on a server-side+ * supervisor run would throw `Builtin tool "lobe-group-agent-builder" is not+ * implemented` the moment the model called it. Add it back here once a server+ * runtime exists.+ */+export const groupSupervisorToolIds = [GroupManagementManifest.identifier];+/*** Tool IDs whose enabled state is decided by runtime / system conditions* (e.g. cloud runtime, agent has documents attached, knowledge base configured,diff --git a/packages/model-runtime/src/providers/aihubmix/index.ts b/packages/model-runtime/src/providers/aihubmix/index.tsindex 0a74b51b332..b29a47b2464 100644--- a/packages/model-runtime/src/providers/aihubmix/index.ts+++ b/packages/model-runtime/src/providers/aihubmix/index.ts@@ -148,7 +148,7 @@ const DEFAULT_BASE_URL = 'https://aihubmix.com';// Resolve the gateway for a request from the configured baseURL (default// DEFAULT_BASE_URL), stripping a trailing version suffix (e.g. /v1) so the// per-route suffixes below aren't doubled (β¦/v1/v1, β¦/v1/gemini).-const resolveBaseURL = (options: { baseURL?: string }) =>+const resolveBaseURL = (options: { baseURL?: string | null }) =>options.baseURL?.trim().replace(/\/v\d+[a-z]*\/?$/, '') || DEFAULT_BASE_URL;export const params: CreateRouterRuntimeOptions = {