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.

♻️ refactor(agent-management): retire legacy callAgent runAsTask async invocation (#20354)

Arvin Xu705a8c72b64b
diff --git a/apps/server/src/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts b/apps/server/src/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts
index 7d88af0117d..b0a492f7e68 100644
--- a/apps/server/src/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts
+++ b/apps/server/src/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts
@@ -6752,7 +6752,6 @@ describe('RuntimeExecutors', { timeout: 60_000 }, () => {
arguments: JSON.stringify({
agentId: 'target-agent-id',
instruction: 'Do something',
- runAsTask: true,
}),
id: 'tool-call-1',
identifier: 'lobe-agent-management',
@@ -6813,7 +6812,6 @@ describe('RuntimeExecutors', { timeout: 60_000 }, () => {
arguments: JSON.stringify({
agentId: 'target-agent-id',
instruction: 'Do something useful',
- runAsTask: true,
}),
id: 'tool-call-1',
identifier: 'lobe-agent-management',
diff --git a/apps/server/src/routers/lambda/__tests__/integration/aiAgent/serverCallAgent.integration.test.ts b/apps/server/src/routers/lambda/__tests__/integration/aiAgent/serverCallAgent.integration.test.ts
index 36b4f34235b..70ee485d871 100644
--- a/apps/server/src/routers/lambda/__tests__/integration/aiAgent/serverCallAgent.integration.test.ts
+++ b/apps/server/src/routers/lambda/__tests__/integration/aiAgent/serverCallAgent.integration.test.ts
@@ -63,9 +63,6 @@ const createCallAgentResponse = () => {
arguments: JSON.stringify({
agentId: targetAgentId,
instruction: 'Handle the delegated backend integration task.',
- runAsTask: true,
- taskTitle: 'Delegated backend integration task',
- timeout: 30_000,
}),
call_id: callId,
name: 'lobe-agent-management____callAgent',
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentManagement.test.ts b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentManagement.test.ts
index c01dd147f80..6d4e38d80e1 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentManagement.test.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentManagement.test.ts
@@ -147,7 +147,6 @@ describe('agentManagementRuntime', () => {
{
agentId: 'agent-target',
instruction: 'Do delegated work',
- runAsTask: true,
},
{ toolManifestMap: {} },
);
@@ -168,9 +167,6 @@ describe('agentManagementRuntime', () => {
{
agentId: 'agent-target',
instruction: 'Do delegated work',
- runAsTask: true,
- taskTitle: 'Delegated task',
- timeout: 1234,
},
{
subAgent: { run },
@@ -180,9 +176,9 @@ describe('agentManagementRuntime', () => {
expect(run).toHaveBeenCalledWith({
agentId: 'agent-target',
- description: 'Delegated task',
+ description: 'Call agent agent-target',
instruction: 'Do delegated work',
- timeout: 1234,
+ timeout: 1_800_000,
});
expect(result).toMatchObject({
content: '',
@@ -208,7 +204,6 @@ describe('agentManagementRuntime', () => {
{
agentId: 'agent-target',
instruction: 'Do delegated work',
- runAsTask: true,
},
{
subAgent: { run },
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/agentManagement.ts b/apps/server/src/services/toolExecution/serverRuntimes/agentManagement.ts
index a266c90eb65..a110691d3be 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/agentManagement.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/agentManagement.ts
@@ -66,7 +66,7 @@ export const agentManagementRuntime: ServerRuntimeRegistration = {
params: CallAgentParams,
ctx: ToolExecutionContext,
): Promise<ToolExecutionResult> => {
- const { agentId, instruction, taskTitle, timeout } = params;
+ const { agentId, instruction } = params;
if (ctx.isSubAgent) {
return {
@@ -95,12 +95,11 @@ export const agentManagementRuntime: ServerRuntimeRegistration = {
};
}
- const description = taskTitle || `Call agent ${agentId}`;
const { started, error, subOperationId, threadId } = await ctx.subAgent.run({
agentId,
- description,
+ description: `Call agent ${agentId}`,
instruction,
- timeout: timeout || 1_800_000,
+ timeout: 1_800_000,
});
if (!started) {
diff --git a/locales/en-US/plugin.json b/locales/en-US/plugin.json
index 602c957110f..491c4462fc1 100644
--- a/locales/en-US/plugin.json
+++ b/locales/en-US/plugin.json
@@ -132,7 +132,6 @@
"builtins.lobe-agent-management.apiName.updateAgent": "Update agent",
"builtins.lobe-agent-management.apiName.updatePrompt": "Update prompt",
"builtins.lobe-agent-management.inspector.callAgent.sync": "Calling:",
- "builtins.lobe-agent-management.inspector.callAgent.task": "Assigning task to:",
"builtins.lobe-agent-management.inspector.createAgent.title": "Creating agent:",
"builtins.lobe-agent-management.inspector.duplicateAgent.title": "Duplicating agent:",
"builtins.lobe-agent-management.inspector.getAgentDetail.title": "Getting details:",
diff --git a/locales/zh-CN/plugin.json b/locales/zh-CN/plugin.json
index 1e42929b0ee..db88b733b49 100644
--- a/locales/zh-CN/plugin.json
+++ b/locales/zh-CN/plugin.json
@@ -132,7 +132,6 @@
"builtins.lobe-agent-management.apiName.updateAgent": "更新代理",
"builtins.lobe-agent-management.apiName.updatePrompt": "更新提示词",
"builtins.lobe-agent-management.inspector.callAgent.sync": "正在呼叫:",
- "builtins.lobe-agent-management.inspector.callAgent.task": "分配任务给:",
"builtins.lobe-agent-management.inspector.createAgent.title": "正在创建代理:",
"builtins.lobe-agent-management.inspector.duplicateAgent.title": "正在复制代理:",
"builtins.lobe-agent-management.inspector.getAgentDetail.title": "正在获取详情:",
diff --git a/packages/agent-runtime/src/agents/GeneralChatAgent.ts b/packages/agent-runtime/src/agents/GeneralChatAgent.ts
index b54a46b2f7b..6b2c24a1efa 100644
--- a/packages/agent-runtime/src/agents/GeneralChatAgent.ts
+++ b/packages/agent-runtime/src/agents/GeneralChatAgent.ts
@@ -881,39 +881,7 @@ export class GeneralChatAgent implements Agent {
}
case 'tool_result': {
- const { data, parentMessageId, stop } =
- context.payload as GeneralAgentCallToolResultPayload;
-
- // Legacy async agent invocation path. `callAgent({ runAsTask: true })`
- // emits state.type=execSubAgent* with stop=true so the runtime can fork
- // a background agent run after the tool call is persisted.
- if (stop && data?.state) {
- const stateType = data.state.type;
-
- // Server-side legacy agent invocation (single)
- if (stateType === 'execSubAgent') {
- const { parentMessageId: execParentId, task } = data.state as {
- parentMessageId: string;
- task: any;
- };
- return {
- payload: { parentMessageId: execParentId, task },
- type: 'exec_sub_agent',
- };
- }
-
- // Server-side legacy agent invocations (multiple)
- if (stateType === 'execSubAgents') {
- const { parentMessageId: execParentId, tasks } = data.state as {
- parentMessageId: string;
- tasks: any[];
- };
- return {
- payload: { parentMessageId: execParentId, tasks },
- type: 'exec_sub_agents',
- };
- }
- }
+ const { parentMessageId } = context.payload as GeneralAgentCallToolResultPayload;
// Scope pending check to the current assistant turn so stale
// `pending` rows from prior turns can never block the loop.
diff --git a/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.test.ts b/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.test.ts
index 8d2883c37c2..408bc128f9b 100644
--- a/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.test.ts
+++ b/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.test.ts
@@ -982,152 +982,6 @@ describe('GeneralChatAgent', () => {
});
describe('tool_result phase', () => {
- describe('Lobe Agent sub-agents (execSubAgent state)', () => {
- it('should return exec_sub_agent for single sub-agent (execSubAgent)', async () => {
- const agent = new GeneralChatAgent({
- agentConfig: { maxSteps: 100 },
- operationId: 'test-session',
- modelRuntimeConfig: mockModelRuntimeConfig,
- });
-
- const state = createMockState();
- const context = createMockContext('tool_result', {
- parentMessageId: 'tool-msg-1',
- stop: true,
- data: {
- state: {
- type: 'execSubAgent',
- parentMessageId: 'exec-parent-msg',
- task: { instruction: 'Do something async', timeout: 30000 },
- },
- },
- });
-
- const result = await agent.runner(context, state);
-
- expect(result).toEqual({
- type: 'exec_sub_agent',
- payload: {
- parentMessageId: 'exec-parent-msg',
- task: { instruction: 'Do something async', timeout: 30000 },
- },
- });
- });
-
- it('should return exec_sub_agents for multiple sub-agents (execSubAgents)', async () => {
- const agent = new GeneralChatAgent({
- agentConfig: { maxSteps: 100 },
- operationId: 'test-session',
- modelRuntimeConfig: mockModelRuntimeConfig,
- });
-
- const state = createMockState();
- const tasks = [
- { instruction: 'Task 1', timeout: 30000 },
- { instruction: 'Task 2', timeout: 30000 },
- ];
- const context = createMockContext('tool_result', {
- parentMessageId: 'tool-msg-1',
- stop: true,
- data: {
- state: {
- type: 'execSubAgents',
- parentMessageId: 'exec-parent-msg',
- tasks,
- },
- },
- });
-
- const result = await agent.runner(context, state);
-
- expect(result).toEqual({
- type: 'exec_sub_agents',
- payload: {
- parentMessageId: 'exec-parent-msg',
- tasks,
- },
- });
- });
-
- it('should not trigger exec_sub_agent when stop is false', async () => {
- const agent = new GeneralChatAgent({
- agentConfig: { maxSteps: 100 },
- operationId: 'test-session',
- modelRuntimeConfig: mockModelRuntimeConfig,
- });
-
- const state = createMockState({
- messages: [
- { role: 'user', content: 'Hello' },
- { role: 'assistant', content: '' },
- { role: 'tool', content: 'Result', tool_call_id: 'call-1' },
- ] as any,
- });
- const context = createMockContext('tool_result', {
- parentMessageId: 'tool-msg-1',
- stop: false, // stop is false, should not trigger exec_sub_agent
- data: {
- state: {
- type: 'execSubAgent',
- parentMessageId: 'exec-parent-msg',
- task: { instruction: 'Do something async' },
- },
- },
- });
-
- const result = await agent.runner(context, state);
-
- // Should return call_llm instead of exec_sub_agent
- expect(result).toEqual({
- type: 'call_llm',
- payload: {
- assistantMessageId: undefined,
- messages: state.messages,
- model: 'gpt-4o-mini',
- parentMessageId: 'tool-msg-1',
- provider: 'openai',
- tools: undefined,
- },
- });
- });
-
- it('should not trigger exec_sub_agent when data.state is undefined', async () => {
- const agent = new GeneralChatAgent({
- agentConfig: { maxSteps: 100 },
- operationId: 'test-session',
- modelRuntimeConfig: mockModelRuntimeConfig,
- });
-
- const state = createMockState({
- messages: [
- { role: 'user', content: 'Hello' },
- { role: 'assistant', content: '' },
- { role: 'tool', content: 'Result', tool_call_id: 'call-1' },
- ] as any,
- });
- const context = createMockContext('tool_result', {
- parentMessageId: 'tool-msg-1',
- stop: true,
- data: {}, // No state property
- });
-
- const result = await agent.runner(context, state);
-
- // Should return call_llm instead of exec_sub_agent
- expect(result).toEqual({
- type: 'call_llm',
- payload: {
- assistantMessageId: undefined,
- messages: state.messages,
- model: 'gpt-4o-mini',
- parentMessageId: 'tool-msg-1',
- provider: 'openai',
- tools: undefined,
- },
- });
- });
- });
-
it('should return call_llm when no pending tools', async () => {
const agent = new GeneralChatAgent({
agentConfig: { maxSteps: 100 },
diff --git a/packages/builtin-tool-agent-management/src/callAgentManifest.ts b/packages/builtin-tool-agent-management/src/callAgentManifest.ts
index bc925dc9713..e23c1128395 100644
--- a/packages/builtin-tool-agent-management/src/callAgentManifest.ts
+++ b/packages/builtin-tool-agent-management/src/callAgentManifest.ts
@@ -6,12 +6,8 @@ import { AgentManagementApiName, AgentManagementIdentifier } from './types';
const callAgentSystemRole = `You have a callAgent tool to delegate tasks to other AI agents.
<execution_guide>
-### Synchronous Call (default)
+### Synchronous Call
callAgent(agentId, instruction) — agent responds directly in conversation.
-
-### Asynchronous Task
-callAgent(agentId, instruction, runAsTask: true, taskTitle: "...") — agent works in background.
-Use runAsTask for complex/long operations that shouldn't block conversation.
</execution_guide>`;
/**
diff --git a/packages/builtin-tool-agent-management/src/client/Inspector/CallAgent/index.tsx b/packages/builtin-tool-agent-management/src/client/Inspector/CallAgent/index.tsx
index 06cdbc53d50..29c4f3f31ba 100644
--- a/packages/builtin-tool-agent-management/src/client/Inspector/CallAgent/index.tsx
+++ b/packages/builtin-tool-agent-management/src/client/Inspector/CallAgent/index.tsx
@@ -34,7 +34,6 @@ export const CallAgentInspector = memo<BuiltinInspectorProps<CallAgentParams>>(
const theme = useTheme();
const agentId = args?.agentId || partialArgs?.agentId;
- const runAsTask = args?.runAsTask || partialArgs?.runAsTask;
// Get agent meta from store
const agentMeta = useAgentStore((s) =>
@@ -51,16 +50,12 @@ export const CallAgentInspector = memo<BuiltinInspectorProps<CallAgentParams>>(
);
}
- const titleKey = runAsTask
- ? 'builtins.lobe-agent-management.inspector.callAgent.task'
- : 'builtins.lobe-agent-management.inspector.callAgent.sync';
-
const agentName = agentMeta?.title || agentId;
return (
<Flexbox horizontal align={'center'} className={styles.root} gap={8}>
<span className={cx(styles.title, isArgumentsStreaming && shinyTextStyles.shinyText)}>
- {t(titleKey)}
+ {t('builtins.lobe-agent-management.inspector.callAgent.sync')}
</span>
{agentMeta && (
<Avatar
diff --git a/packages/builtin-tool-agent-management/src/executor.ts b/packages/builtin-tool-agent-management/src/executor.ts
index 19cc5c36ce3..b0fce897af2 100644
--- a/packages/builtin-tool-agent-management/src/executor.ts
+++ b/packages/builtin-tool-agent-management/src/executor.ts
@@ -109,56 +109,7 @@ class AgentManagementExecutor extends BaseExecutor<typeof AgentManagementApiName
params: CallAgentParams,
ctx: BuiltinToolContext,
): Promise<BuiltinToolResult> => {
- const {
- agentId,
- instruction,
- runAsTask,
- taskTitle,
- timeout,
- skipCallSupervisor = false,
- } = params;
-
- if (runAsTask) {
- // Dispatch as a legacy async agent invocation.
- // Pre-load target agent config to ensure it exists
- const targetAgentExists = useAgentStore.getState().agentMap[agentId];
- if (!targetAgentExists) {
- try {
- const config = await agentService.getAgentConfigById(agentId);
- if (!config) {
- return {
- content: `Agent "${agentId}" not found in your workspace. Please check the agent ID and try again.`,
- success: false,
- };
- }
- useAgentStore.getState().internal_dispatchAgentMap(agentId, config);
- } catch (error) {
- console.error('[callAgent] Failed to load agent config:', error);
- return {
- content: `Failed to load agent "${agentId}": ${(error as Error).message}`,
- success: false,
- };
- }
- }
-
- // Return special state recognized by AgentRuntime's exec_sub_agent executor.
- // callAgent keeps this alias until it is redesigned as an explicit agent invocation.
- return {
- content: `🚀 Triggered async task to call agent "${agentId}"${taskTitle ? `: ${taskTitle}` : ''}`,
- state: {
- parentMessageId: ctx.messageId,
- task: {
- description: taskTitle || `Call agent ${agentId}`,
- instruction,
- targetAgentId: agentId, // Special field for callAgent - indicates target agent
- timeout: timeout || 1_800_000,
- },
- type: 'execSubAgent',
- },
- stop: true,
- success: true,
- };
- }
+ const { agentId, instruction, skipCallSupervisor = false } = params;
// Execute as synchronous speak
// Two modes: Group vs Agents
diff --git a/packages/builtin-tool-agent-management/src/manifest.ts b/packages/builtin-tool-agent-management/src/manifest.ts
index b78818f5047..ffdb31c41a8 100644
--- a/packages/builtin-tool-agent-management/src/manifest.ts
+++ b/packages/builtin-tool-agent-management/src/manifest.ts
@@ -280,8 +280,7 @@ export const AgentManagementManifest: BuiltinToolManifest = {
// ==================== Execution ====================
{
- description:
- 'Call an agent to handle a specific task or respond to an instruction. Can run synchronously (immediate response) or as a background task for longer operations.',
+ description: 'Call an agent to handle a specific task or respond to an instruction.',
name: AgentManagementApiName.callAgent,
parameters: {
properties: {
@@ -294,22 +293,6 @@ export const AgentManagementManifest: BuiltinToolManifest = {
'The instruction or task for the agent to execute. Be specific about expected deliverables.',
type: 'string',
},
- runAsTask: {
- default: false,
- description:
- 'If true, run as a background task for longer operations. The agent will work asynchronously and return results upon completion.',
- type: 'boolean',
- },
- taskTitle: {
- description: 'Brief title for the task (shown in UI). Required when runAsTask is true.',
- type: 'string',
- },
- timeout: {
- default: 1_800_000,
- description:
- 'Maximum time in milliseconds to wait for task completion (default: 1800000 = 30 minutes). Only applies when runAsTask is true.',
- type: 'number',
- },
skipCallSupervisor: {
default: false,
description:
diff --git a/packages/builtin-tool-agent-management/src/resolveManifest.test.ts b/packages/builtin-tool-agent-management/src/resolveManifest.test.ts
index 1c8d868d8b5..d0c424dc128 100644
--- a/packages/builtin-tool-agent-management/src/resolveManifest.test.ts
+++ b/packages/builtin-tool-agent-management/src/resolveManifest.test.ts
@@ -21,6 +21,22 @@ describe('resolveAgentManagementManifest', () => {
expect(resolveAgentManagementManifest({})).toBe(AgentManagementManifest);
});
+ it('advertises only the callAgent params every runtime honors', () => {
+ const callAgent = AgentManagementManifest.api.find(
+ (api) => api.name === AgentManagementApiName.callAgent,
+ )!;
+
+ // The manifest is shared with the client runtime, whose inline `callAgent`
+ // path has no thread title or per-call timeout to honor. Advertising
+ // `taskTitle` / `timeout` would promise behavior only the server deferred
+ // path keeps, so they must not appear in the shared schema.
+ expect(Object.keys(callAgent.parameters.properties ?? {}).sort()).toEqual([
+ 'agentId',
+ 'instruction',
+ 'skipCallSupervisor',
+ ]);
+ });
+
it('hides callAgent in both api and systemRole inside a sub-agent run', () => {
const result = resolveAgentManagementManifest({ isSubAgent: true, scope: 'main' })!;
diff --git a/packages/builtin-tool-agent-management/src/systemRole.ts b/packages/builtin-tool-agent-management/src/systemRole.ts
index 8100fff4321..130b8c0ded8 100644
--- a/packages/builtin-tool-agent-management/src/systemRole.ts
+++ b/packages/builtin-tool-agent-management/src/systemRole.ts
@@ -152,25 +152,12 @@ const executionGuideSection = `
<execution_guide>
## Calling Agents
-### Synchronous Call (default)
+### Synchronous Call
For quick responses in the conversation context:
\`\`\`
callAgent(agentId, instruction)
\`\`\`
The agent will respond directly in the current conversation.
-
-### Asynchronous Task
-For longer operations that benefit from focused execution:
-\`\`\`
-callAgent(agentId, instruction, runAsTask: true, taskTitle: "Brief description")
-\`\`\`
-The agent will work in the background and return results upon completion.
-
-**When to use runAsTask:**
-- Complex multi-step operations
-- Tasks requiring extended processing time
-- Work that shouldn't block the conversation flow
-- Operations that benefit from isolated execution context
</execution_guide>`;
const subAgentContextSection = `
@@ -207,7 +194,7 @@ export const buildSystemPrompt = (
? `
**Execution:**
-- **callAgent**: Invoke an agent to handle a task (synchronously or as async background task)`
+- **callAgent**: Invoke an agent to handle a task`
: ''
}
</core_capabilities>
diff --git a/packages/builtin-tool-agent-management/src/types.ts b/packages/builtin-tool-agent-management/src/types.ts
index 352f414d267..14b754ce98a 100644
--- a/packages/builtin-tool-agent-management/src/types.ts
+++ b/packages/builtin-tool-agent-management/src/types.ts
@@ -284,23 +284,11 @@ export interface CallAgentParams {
* Instruction or task for the agent to execute
*/
instruction: string;
- /**
- * If true, execute as an async background task
- */
- runAsTask?: boolean;
/**
* If true (and in a group context), skip calling supervisor after agent responds.
* Only relevant when used within agent groups. Default: false
*/
skipCallSupervisor?: boolean;
- /**
- * Task title (required when runAsTask is true)
- */
- taskTitle?: string;
- /**
- * Timeout in milliseconds for task execution (default: 1800000 = 30 minutes)
- */
- timeout?: number;
}
// ==================== Get Agent Detail ====================
diff --git a/packages/locales/src/default/plugin.ts b/packages/locales/src/default/plugin.ts
index d5666adf5b5..4d969f6d048 100644
--- a/packages/locales/src/default/plugin.ts
+++ b/packages/locales/src/default/plugin.ts
@@ -67,7 +67,6 @@ export default {
'builtins.lobe-agent-management.apiName.updateAgent': 'Update agent',
'builtins.lobe-agent-management.apiName.updatePrompt': 'Update prompt',
'builtins.lobe-agent-management.inspector.callAgent.sync': 'Calling:',
- 'builtins.lobe-agent-management.inspector.callAgent.task': 'Assigning task to:',
'builtins.lobe-agent-management.inspector.createAgent.title': 'Creating agent:',
'builtins.lobe-agent-management.inspector.duplicateAgent.title': 'Duplicating agent:',
'builtins.lobe-agent-management.inspector.getAgentDetail.title': 'Getting details:',