π€― 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(hetero-agent): prefer platformAgentId for OpenClaw agent selection (#18028)
AmAzing-afa1cfe48ecd
diff --git a/apps/cli/src/tools/__tests__/heteroTask.test.ts b/apps/cli/src/tools/__tests__/heteroTask.test.tsindex f25b760832b..6da743e5550 100644--- a/apps/cli/src/tools/__tests__/heteroTask.test.ts+++ b/apps/cli/src/tools/__tests__/heteroTask.test.ts@@ -103,6 +103,7 @@ describe('runHeteroTask (openclaw)', () => {});afterEach(() => {+ vi.unstubAllEnvs();vi.restoreAllMocks();});@@ -128,6 +129,43 @@ describe('runHeteroTask (openclaw)', () => {expect(messageArg).toContain('MSG_ID');});+ it.each([+ {+ environmentAgentId: 'ops-default',+ expectedAgentId: 'researcher',+ platformAgentId: ' researcher ',+ },+ {+ environmentAgentId: 'ops-default',+ expectedAgentId: 'ops-default',+ platformAgentId: undefined,+ },+ {+ environmentAgentId: 'ops-default',+ expectedAgentId: 'ops-default',+ platformAgentId: ' ',+ },+ { environmentAgentId: '', expectedAgentId: 'main', platformAgentId: undefined },+ ])(+ 'selects OpenClaw agent $expectedAgentId from platform config before environment fallback',+ async ({ environmentAgentId, expectedAgentId, platformAgentId }) => {+ vi.stubEnv('OPENCLAW_AGENT_ID', environmentAgentId);+ spawnMock.mockReturnValue(makeMockChild());++ await runHeteroTask({+ agentType: 'openclaw',+ operationId: 'op-agent-selection',+ platformAgentId,+ prompt: 'hello',+ taskId: 'task-agent-selection',+ topicId: 'topic-agent-selection',+ });++ const [, spawnArgs] = spawnMock.mock.calls[0] as [string, string[]];+ expect(spawnArgs[spawnArgs.indexOf('--agent') + 1]).toBe(expectedAgentId);+ },+ );+it('always injects protocol even on the second turn of the same session', async () => {const child1 = makeMockChild(1111);const child2 = makeMockChild(2222);diff --git a/apps/cli/src/tools/heteroTask.ts b/apps/cli/src/tools/heteroTask.tsindex af2aed0c53e..007b13ff69f 100644--- a/apps/cli/src/tools/heteroTask.ts+++ b/apps/cli/src/tools/heteroTask.ts@@ -63,6 +63,7 @@ export interface RunHeteroTaskParams {agentType: RemoteHeterogeneousAgentType;cwd?: string;operationId: string;+ platformAgentId?: string;prompt: string;taskId: string;topicId: string;@@ -163,7 +164,17 @@ function buildNotifyProtocol(lhPath: string, topicId: string): string {}export async function runHeteroTask(params: RunHeteroTaskParams): Promise<string> {- const { agentId, agentType, cwd, operationId, prompt, taskId, topicId, workspaceId } = params;+ const {+ agentId,+ agentType,+ cwd,+ operationId,+ platformAgentId,+ prompt,+ taskId,+ topicId,+ workspaceId,+ } = params;const workDir = cwd || process.cwd();const lhPath = resolveLhPath();// Propagate workspace scope into the spawned child so its own `lh notify`@@ -177,7 +188,7 @@ export async function runHeteroTask(params: RunHeteroTaskParams): Promise<string// openclaw agent --local is one-shot: each invocation processes one message and exits.// The --session-id links turns into the same conversation history on disk.// Requires the `openclaw` binary to be on PATH with Node >=22.19.- const openclawAgent = process.env.OPENCLAW_AGENT_ID ?? 'main';+ const openclawAgent = platformAgentId?.trim() || process.env.OPENCLAW_AGENT_ID || 'main';// Always inject the notify protocol so openclaw knows how to report results// back to the LobeHub UI β even if the previous turn failed and the sessiondiff --git a/apps/desktop/src/main/controllers/GatewayConnectionCtr.ts b/apps/desktop/src/main/controllers/GatewayConnectionCtr.tsindex b4cb4a78b21..ae63d69716f 100644--- a/apps/desktop/src/main/controllers/GatewayConnectionCtr.ts+++ b/apps/desktop/src/main/controllers/GatewayConnectionCtr.ts@@ -448,6 +448,7 @@ export default class GatewayConnectionCtr extends ControllerModule {agentType: string;cwd?: string;operationId: string;+ platformAgentId?: string;prompt: string;taskId: string;topicId: string;@@ -688,12 +689,23 @@ export default class GatewayConnectionCtr extends ControllerModule {agentType: string;cwd?: string;operationId: string;+ platformAgentId?: string;prompt: string;taskId: string;topicId: string;workspaceId?: string;}): Promise<string> {- const { agentId, agentType, cwd, operationId, prompt, taskId, topicId, workspaceId } = args;+ const {+ agentId,+ agentType,+ cwd,+ operationId,+ platformAgentId,+ prompt,+ taskId,+ topicId,+ workspaceId,+ } = args;const workDir = cwd || process.cwd();const [serverUrl, accessToken] = await Promise.all([@@ -719,7 +731,7 @@ export default class GatewayConnectionCtr extends ControllerModule {}if (commandStatus.resolvedPathEnv) childEnv.PATH = commandStatus.resolvedPathEnv;const lhPath = this.resolveLhPath();- const openclawAgent = process.env['OPENCLAW_AGENT_ID'] ?? 'main';+ const openclawAgent = platformAgentId?.trim() || process.env['OPENCLAW_AGENT_ID'] || 'main';// Always inject the notify protocol so openclaw knows how to report results// back to the LobeHub UI β even if the previous turn failed and the sessiondiff --git a/apps/desktop/src/main/controllers/__tests__/GatewayConnectionCtr.test.ts b/apps/desktop/src/main/controllers/__tests__/GatewayConnectionCtr.test.tsindex 54afd08d38c..7a16a9b45bc 100644--- a/apps/desktop/src/main/controllers/__tests__/GatewayConnectionCtr.test.ts+++ b/apps/desktop/src/main/controllers/__tests__/GatewayConnectionCtr.test.ts@@ -313,6 +313,7 @@ describe('GatewayConnectionCtr', () => {afterEach(() => {ctr.disconnect();+ vi.unstubAllEnvs();vi.useRealTimers();});@@ -1059,6 +1060,49 @@ describe('GatewayConnectionCtr', () => {expect(messageArg).toContain('lh notify');});+ it.each([+ {+ environmentAgentId: 'ops-default',+ expectedAgentId: 'researcher',+ platformAgentId: ' researcher ',+ },+ {+ environmentAgentId: 'ops-default',+ expectedAgentId: 'ops-default',+ platformAgentId: undefined,+ },+ {+ environmentAgentId: 'ops-default',+ expectedAgentId: 'ops-default',+ platformAgentId: ' ',+ },+ { environmentAgentId: '', expectedAgentId: 'main', platformAgentId: undefined },+ ])(+ 'selects OpenClaw agent $expectedAgentId from platform config before environment fallback',+ async ({ environmentAgentId, expectedAgentId, platformAgentId }) => {+ vi.stubEnv('OPENCLAW_AGENT_ID', environmentAgentId);+ spawnMock.mockReturnValue(makeMockChild());++ const client = await connectAndOpen();+ client.simulateToolCallRequest(+ 'runHeteroTask',+ {+ agentType: 'openclaw',+ operationId: 'op-agent-selection',+ platformAgentId,+ prompt: 'hello',+ taskId: 'task-agent-selection',+ topicId: 'topic-agent-selection',+ },+ 'req-agent-selection',+ );+ await vi.advanceTimersByTimeAsync(0);++ const [, spawnArgs] = spawnMock.mock.calls[0] as [string, string[]];+ expect(spawnArgs[spawnArgs.indexOf('--agent') + 1]).toBe(expectedAgentId);+ },+ );+it('kills an existing concurrent openclaw process for the same topicId before spawning', async () => {const killSpy = vi.spyOn(process, 'kill').mockImplementation(() => true);const notifySpy = vi.spyOn(ctr as any, 'sendNotify');diff --git a/apps/server/src/services/aiAgent/__tests__/execAgent.heteroFiles.test.ts b/apps/server/src/services/aiAgent/__tests__/execAgent.heteroFiles.test.tsindex 9bba1b0506f..e37a1e31e72 100644--- a/apps/server/src/services/aiAgent/__tests__/execAgent.heteroFiles.test.ts+++ b/apps/server/src/services/aiAgent/__tests__/execAgent.heteroFiles.test.ts@@ -745,7 +745,7 @@ describe('AiAgentService.execAgent - hetero early-exit file attachments', () =>it('keeps the conversation workspace separate from a personal platform device scope', async () => {heteroAgentConfig.agencyConfig = {executionTarget: 'local',- heterogeneousProvider: { type: 'openclaw' },+ heterogeneousProvider: { platformAgentId: 'researcher', type: 'openclaw' },} as any;(heteroAgentConfig as any).userId = userId;(heteroAgentConfig as any).visibility = 'public';@@ -774,6 +774,7 @@ describe('AiAgentService.execAgent - hetero early-exit file attachments', () =>expect(JSON.parse(toolCall.arguments)).toEqual(expect.objectContaining({agentType: 'openclaw',+ platformAgentId: 'researcher',workspaceId: 'workspace-a',}),);diff --git a/apps/server/src/services/aiAgent/index.ts b/apps/server/src/services/aiAgent/index.tsindex 6e32219ee6c..a5cb7da09d9 100644--- a/apps/server/src/services/aiAgent/index.ts+++ b/apps/server/src/services/aiAgent/index.ts@@ -2439,6 +2439,7 @@ export class AiAgentService {agentType: heteroType,cwd: undefined,operationId,+ platformAgentId: agentConfig.agencyConfig?.heterogeneousProvider?.platformAgentId,prompt,taskId: operationId,topicId,