🤯 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: fix multi tasks no summary issue (#11685)
Arvin Xu26ce3173135d
diff --git a/packages/conversation-flow/src/__tests__/fixtures/inputs/tasks/index.ts b/packages/conversation-flow/src/__tests__/fixtures/inputs/tasks/index.tsindex 3db7a8c210c..1b6545dad05 100644--- a/packages/conversation-flow/src/__tests__/fixtures/inputs/tasks/index.ts+++ b/packages/conversation-flow/src/__tests__/fixtures/inputs/tasks/index.ts@@ -1,8 +1,10 @@import type { Message } from '../../../../types';+import multiTasksWithSummary from './multi-tasks-with-summary.json';import simple from './simple.json';import withSummary from './with-summary.json';export const tasks = {+ multiTasksWithSummary: multiTasksWithSummary as Message[],simple: simple as Message[],withSummary: withSummary as Message[],};diff --git a/packages/conversation-flow/src/__tests__/fixtures/inputs/tasks/multi-tasks-with-summary.json b/packages/conversation-flow/src/__tests__/fixtures/inputs/tasks/multi-tasks-with-summary.jsonnew file mode 100644index 00000000000..492dc19362c--- /dev/null+++ b/packages/conversation-flow/src/__tests__/fixtures/inputs/tasks/multi-tasks-with-summary.json@@ -0,0 +1,234 @@+[+ {+ "id": "msg-user-1",+ "role": "user",+ "content": "Process these files in 10 parallel tasks and give me a summary.",+ "parentId": null,+ "createdAt": 1735526559382,+ "updatedAt": 1735526559382+ },+ {+ "id": "msg-assistant-1",+ "role": "assistant",+ "content": "I'll process these files in 10 parallel tasks.",+ "parentId": "msg-user-1",+ "createdAt": 1735526560163,+ "updatedAt": 1735526585550,+ "model": "gpt-4",+ "provider": "openai",+ "tools": [+ {+ "id": "call_exec_tasks_1",+ "type": "builtin",+ "apiName": "execTasks",+ "arguments": "{\"tasks\": [{\"description\": \"Task 1\"}, {\"description\": \"Task 2\"}, {\"description\": \"Task 3\"}, {\"description\": \"Task 4\"}, {\"description\": \"Task 5\"}, {\"description\": \"Task 6\"}, {\"description\": \"Task 7\"}, {\"description\": \"Task 8\"}, {\"description\": \"Task 9\"}, {\"description\": \"Task 10\"}]}",+ "identifier": "lobe-gtd"+ }+ ]+ },+ {+ "id": "msg-tool-1",+ "role": "tool",+ "content": "Triggered 10 async tasks",+ "parentId": "msg-assistant-1",+ "tool_call_id": "call_exec_tasks_1",+ "createdAt": 1735526588116,+ "updatedAt": 1735526591337,+ "pluginState": {+ "type": "execTasks",+ "tasks": [+ { "description": "Task 1" },+ { "description": "Task 2" },+ { "description": "Task 3" },+ { "description": "Task 4" },+ { "description": "Task 5" },+ { "description": "Task 6" },+ { "description": "Task 7" },+ { "description": "Task 8" },+ { "description": "Task 9" },+ { "description": "Task 10" }+ ],+ "parentMessageId": "msg-tool-1"+ }+ },+ {+ "id": "msg-task-1",+ "role": "task",+ "content": "Task 1 completed with results...",+ "parentId": "msg-tool-1",+ "createdAt": 1735526594643,+ "updatedAt": 1735526756262,+ "taskDetail": {+ "duration": 120000,+ "status": "completed",+ "threadId": "thd_task_1",+ "title": "Task 1",+ "totalCost": 0.015,+ "totalMessages": 15,+ "totalTokens": 100000+ }+ },+ {+ "id": "msg-task-2",+ "role": "task",+ "content": "Task 2 completed with results...",+ "parentId": "msg-tool-1",+ "createdAt": 1735526595000,+ "updatedAt": 1735526757000,+ "taskDetail": {+ "duration": 121000,+ "status": "completed",+ "threadId": "thd_task_2",+ "title": "Task 2",+ "totalCost": 0.016,+ "totalMessages": 16,+ "totalTokens": 101000+ }+ },+ {+ "id": "msg-task-3",+ "role": "task",+ "content": "Task 3 completed with results...",+ "parentId": "msg-tool-1",+ "createdAt": 1735526596000,+ "updatedAt": 1735526758000,+ "taskDetail": {+ "duration": 122000,+ "status": "completed",+ "threadId": "thd_task_3",+ "title": "Task 3",+ "totalCost": 0.017,+ "totalMessages": 17,+ "totalTokens": 102000+ }+ },+ {+ "id": "msg-task-4",+ "role": "task",+ "content": "Task 4 completed with results...",+ "parentId": "msg-tool-1",+ "createdAt": 1735526597000,+ "updatedAt": 1735526759000,+ "taskDetail": {+ "duration": 123000,+ "status": "completed",+ "threadId": "thd_task_4",+ "title": "Task 4",+ "totalCost": 0.018,+ "totalMessages": 18,+ "totalTokens": 103000+ }+ },+ {+ "id": "msg-task-5",+ "role": "task",+ "content": "Task 5 completed with results...",+ "parentId": "msg-tool-1",+ "createdAt": 1735526598000,+ "updatedAt": 1735526760000,+ "taskDetail": {+ "duration": 124000,+ "status": "completed",+ "threadId": "thd_task_5",+ "title": "Task 5",+ "totalCost": 0.019,+ "totalMessages": 19,+ "totalTokens": 104000+ }+ },+ {+ "id": "msg-task-6",+ "role": "task",+ "content": "Task 6 completed with results...",+ "parentId": "msg-tool-1",+ "createdAt": 1735526599000,+ "updatedAt": 1735526761000,+ "taskDetail": {+ "duration": 125000,+ "status": "completed",+ "threadId": "thd_task_6",+ "title": "Task 6",+ "totalCost": 0.02,+ "totalMessages": 20,+ "totalTokens": 105000+ }+ },+ {+ "id": "msg-task-7",+ "role": "task",+ "content": "Task 7 completed with results...",+ "parentId": "msg-tool-1",+ "createdAt": 1735526600000,+ "updatedAt": 1735526762000,+ "taskDetail": {+ "duration": 126000,+ "status": "completed",+ "threadId": "thd_task_7",+ "title": "Task 7",+ "totalCost": 0.021,+ "totalMessages": 21,+ "totalTokens": 106000+ }+ },+ {+ "id": "msg-task-8",+ "role": "task",+ "content": "Task 8 completed with results...",+ "parentId": "msg-tool-1",+ "createdAt": 1735526601000,+ "updatedAt": 1735526763000,+ "taskDetail": {+ "duration": 127000,+ "status": "completed",+ "threadId": "thd_task_8",+ "title": "Task 8",+ "totalCost": 0.022,+ "totalMessages": 22,+ "totalTokens": 107000+ }+ },+ {+ "id": "msg-task-9",+ "role": "task",+ "content": "Task 9 completed with results...",+ "parentId": "msg-tool-1",+ "createdAt": 1735526602000,+ "updatedAt": 1735526764000,+ "taskDetail": {+ "duration": 128000,+ "status": "completed",+ "threadId": "thd_task_9",+ "title": "Task 9",+ "totalCost": 0.023,+ "totalMessages": 23,+ "totalTokens": 108000+ }+ },+ {+ "id": "msg-task-10",+ "role": "task",+ "content": "Task 10 completed with results...",+ "parentId": "msg-tool-1",+ "createdAt": 1735526603000,+ "updatedAt": 1735526765000,+ "taskDetail": {+ "duration": 129000,+ "status": "completed",+ "threadId": "thd_task_10",+ "title": "Task 10",+ "totalCost": 0.024,+ "totalMessages": 24,+ "totalTokens": 109000+ }+ },+ {+ "id": "msg-assistant-summary",+ "role": "assistant",+ "content": "All 10 tasks completed successfully! Here's the comprehensive summary...",+ "parentId": "msg-task-10",+ "createdAt": 1735526810000,+ "updatedAt": 1735526820000,+ "model": "gpt-4",+ "provider": "openai"+ }+]diff --git a/packages/conversation-flow/src/__tests__/parse.test.ts b/packages/conversation-flow/src/__tests__/parse.test.tsindex fd2f588e47a..62ff80d0aa8 100644--- a/packages/conversation-flow/src/__tests__/parse.test.ts+++ b/packages/conversation-flow/src/__tests__/parse.test.ts@@ -194,6 +194,31 @@ describe('parse', () => {expect(serializeParseResult(result)).toEqual(outputs.tasks.withSummary);});++ it('should handle 10 parallel tasks with summary as task child', () => {+ const result = parse(inputs.tasks.multiTasksWithSummary);++ // The critical assertions:+ // 1. flatList should have 4 items: user, assistantGroup(+tool), tasks(10 tasks), assistant-summary+ expect(result.flatList).toHaveLength(4);+ expect(result.flatList[0].role).toBe('user');+ expect(result.flatList[1].role).toBe('assistantGroup');+ expect(result.flatList[2].role).toBe('tasks');+ expect(result.flatList[3].role).toBe('assistant');++ // 2. tasks virtual message should have 10 task messages+ expect((result.flatList[2] as any).tasks).toHaveLength(10);++ // 3. Verify all tasks are completed+ const tasks = (result.flatList[2] as any).tasks;+ for (const task of tasks) {+ expect(task.taskDetail.status).toBe('completed');+ }++ // 4. The summary message should be present and accessible+ expect(result.flatList[3].id).toBe('msg-assistant-summary');+ expect(result.flatList[3].content).toContain('All 10 tasks completed');+ });});describe('Performance', () => {diff --git a/packages/conversation-flow/src/transformation/ContextTreeBuilder.ts b/packages/conversation-flow/src/transformation/ContextTreeBuilder.tsindex e5901709440..e5b8c88eb64 100644--- a/packages/conversation-flow/src/transformation/ContextTreeBuilder.ts+++ b/packages/conversation-flow/src/transformation/ContextTreeBuilder.ts@@ -125,6 +125,21 @@ export class ContextTreeBuilder {for (const nonTaskChild of nonTaskChildren) {this.transformToLinear(nonTaskChild, contextTree);}++ // Also check for children of task messages (e.g., summary as child of last task)+ const taskChildren = idNode.children.filter((child) => {+ const childMsg = this.messageMap.get(child.id);+ return childMsg?.role === 'task';+ });++ for (const taskChild of taskChildren) {+ for (const taskGrandchild of taskChild.children) {+ const taskGrandchildMsg = this.messageMap.get(taskGrandchild.id);+ if (taskGrandchildMsg && taskGrandchildMsg.role !== 'task') {+ this.transformToLinear(taskGrandchild, contextTree);+ }+ }+ }return;}diff --git a/packages/conversation-flow/src/transformation/FlatListBuilder.ts b/packages/conversation-flow/src/transformation/FlatListBuilder.tsindex a4fccd9cafb..d86b84931f8 100644--- a/packages/conversation-flow/src/transformation/FlatListBuilder.ts+++ b/packages/conversation-flow/src/transformation/FlatListBuilder.ts@@ -113,6 +113,26 @@ export class FlatListBuilder {}}}++ // Also check for children of task messages (e.g., summary as child of last task)+ for (const taskChildId of taskChildren) {+ const taskChildrenIds = this.childrenMap.get(taskChildId) ?? [];+ for (const taskGrandchildId of taskChildrenIds) {+ if (!processedIds.has(taskGrandchildId)) {+ const taskGrandchild = this.messageMap.get(taskGrandchildId);+ if (taskGrandchild && taskGrandchild.role !== 'task') {+ flatList.push(taskGrandchild);+ processedIds.add(taskGrandchildId);+ this.buildFlatListRecursive(+ taskGrandchildId,+ flatList,+ processedIds,+ allMessages,+ );+ }+ }+ }+ }return;}}