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.

πŸ› fix(group): hide member anchors and show per-member progress for parallel tasks (#22282)

Arvin Xuedf871086418
diff --git a/apps/server/src/modules/AgentRuntime/__tests__/executorHelpers.groupMember.test.ts b/apps/server/src/modules/AgentRuntime/__tests__/executorHelpers.groupMember.test.ts
index 3a71c9111f6..ab0701c210d 100644
--- a/apps/server/src/modules/AgentRuntime/__tests__/executorHelpers.groupMember.test.ts
+++ b/apps/server/src/modules/AgentRuntime/__tests__/executorHelpers.groupMember.test.ts
@@ -211,4 +211,70 @@ describe('buildServerAgentMemberRunner', () => {
}),
);
});
+
+ // Unmarked anchors under an isolated executeAgentTasks call rendered as
+ // duplicate orphan skill calls, each carrying the full task list. The tool
+ // card also needs each running member's thread to show its progress.
+ it('marks each member anchor with its agent, task index and thread', async () => {
+ const rows: Record<string, any>[] = [];
+ const messageModel = {
+ create: vi.fn(async (value) => {
+ const row = { ...value, id: `row-${rows.length}` };
+ rows.push(row);
+ return row;
+ }),
+ updatePluginState: vi.fn().mockResolvedValue(undefined),
+ updateToolMessage: vi.fn(),
+ };
+ const runner = buildServerAgentMemberRunner(
+ {
+ execGroupMember: vi.fn(async ({ agentId }) => ({
+ operationId: `op-${agentId}`,
+ started: true,
+ threadId: `thd-${agentId}`,
+ })),
+ messageModel,
+ operationId: 'op-sup',
+ topicId: 'topic-1',
+ } as unknown as RuntimeExecutorContext,
+ {
+ origin: {
+ agentId: 'agt_sup',
+ groupId: 'group-1',
+ topicId: 'topic-1',
+ },
+ world: { group: { agentMap: { agt_eng: { name: 'Engineer' } } } },
+ } as unknown as AgentState,
+ {
+ apiName: 'executeAgentTasks',
+ arguments: '{}',
+ id: 'call_1',
+ identifier: 'lobe-group-management',
+ type: 'builtin',
+ },
+ 'sup-msg-1',
+ );
+
+ await runner!.run({
+ members: [
+ { agentId: 'agt_pm', instruction: 'draft' },
+ { agentId: 'Engineer', instruction: 'review' },
+ ],
+ mode: 'isolated',
+ onComplete: 'resume',
+ });
+
+ const [groupTool, ...anchors] = rows;
+ expect(groupTool.metadata?.groupMemberAnchor).toBeUndefined();
+ expect(anchors.map((row) => [row.parentId, row.tool_call_id, row.metadata])).toEqual([
+ ['row-0', 'call_1::m0', { groupMemberAnchor: { agentId: 'agt_pm', index: 0 } }],
+ ['row-0', 'call_1::m1', { groupMemberAnchor: { agentId: 'agt_eng', index: 1 } }],
+ ]);
+ expect(messageModel.updatePluginState.mock.calls).toEqual(
+ expect.arrayContaining([
+ ['row-1', { threadId: 'thd-agt_pm' }],
+ ['row-2', { threadId: 'thd-agt_eng' }],
+ ]),
+ );
+ });
});
diff --git a/apps/server/src/modules/AgentRuntime/executorHelpers.ts b/apps/server/src/modules/AgentRuntime/executorHelpers.ts
index c8421b4154e..8147e8942db 100644
--- a/apps/server/src/modules/AgentRuntime/executorHelpers.ts
+++ b/apps/server/src/modules/AgentRuntime/executorHelpers.ts
@@ -526,6 +526,8 @@ export const buildServerAgentMemberRunner = (
agentId,
content: '',
groupId,
+ // Lets the reader hide the anchor and the tool card show this member's progress.
+ metadata: { groupMemberAnchor: { agentId: resolvedMembers[i].agentId, index: i } },
parentId: groupTool.id,
plugin: { ...(chatToolPayload as any), id: memberToolCallId },
pluginState: { status: 'pending' },
@@ -566,6 +568,19 @@ export const buildServerAgentMemberRunner = (
});
if (result?.started) {
startedCount += 1;
+ // The tool card follows an isolated member's progress by polling
+ // its thread, which it can only find through the anchor until the
+ // member finishes. Best-effort: the run proceeds either way.
+ if (result.threadId) {
+ await ctx.messageModel
+ .updatePluginState(anchorMessageId, { threadId: result.threadId })
+ .catch((error) =>
+ log(
+ 'buildServerAgentMemberRunner: failed to stamp thread on anchor: %O',
+ error,
+ ),
+ );
+ }
return;
}
if (result?.error) startErrors.push(result.error);
diff --git a/packages/builtin-tool-group-management/src/client/MemberProgress/index.tsx b/packages/builtin-tool-group-management/src/client/MemberProgress/index.tsx
new file mode 100644
index 00000000000..218ce3e0a02
--- /dev/null
+++ b/packages/builtin-tool-group-management/src/client/MemberProgress/index.tsx
@@ -0,0 +1,102 @@
+'use client';
+
+import type { UIChatMessage } from '@lobechat/types';
+import { Flexbox, Markdown } from '@lobehub/ui';
+import isEqual from 'fast-deep-equal';
+import { memo, type ReactNode } from 'react';
+
+import {
+ MetricsDisplay,
+ type TaskMetrics,
+ TaskStatusIndicator,
+} from '@/features/Conversation/Messages/GroupTasks/TaskItem/TaskTitle';
+import { isProcessingStatus, TaskContent } from '@/features/Conversation/Messages/Tasks/shared';
+import { useConversationStore } from '@/features/Conversation/store';
+import { useChatStore } from '@/store/chat';
+import { threadSelectors } from '@/store/chat/selectors';
+
+import { resolveMemberStatus, resolveMemberThreadId, selectMemberAnchors } from './memberAnchor';
+
+/** Member anchors of a server-run multi-member call, keyed by task index. */
+export const useMemberAnchors = (toolCallId?: string) =>
+ useConversationStore((s) => selectMemberAnchors(s.dbMessages, toolCallId), isEqual);
+
+/**
+ * Live status of one member. While it runs, poll its isolation thread: the
+ * anchor itself is only written when the member finishes. A finished member is
+ * not polled β€” the status endpoint stamps a never-polled thread's duration at
+ * request time, so a late fetch would show a wrong run time.
+ */
+const useMemberProgress = (anchor: UIChatMessage) => {
+ const status = resolveMemberStatus(anchor);
+ const sourceThreadId = useChatStore(
+ (s) => threadSelectors.getIsolationThreadBySourceMsgId(anchor.id)(s)?.id,
+ );
+ const threadId = resolveMemberThreadId(anchor) ?? sourceThreadId;
+ const useEnablePollingTaskStatus = useChatStore((s) => s.useEnablePollingTaskStatus);
+ useEnablePollingTaskStatus(threadId, anchor.id, isProcessingStatus(status));
+
+ return { status, threadId };
+};
+
+interface MemberTaskTitleProps {
+ anchor?: UIChatMessage;
+ children: ReactNode;
+}
+
+/** A task title with its member's status icon and run metrics once the member is running. */
+export const MemberTaskTitle = memo<MemberTaskTitleProps>(({ anchor, children }) => {
+ if (!anchor) return children;
+
+ return <MemberTaskTitleWithProgress anchor={anchor}>{children}</MemberTaskTitleWithProgress>;
+});
+
+MemberTaskTitle.displayName = 'MemberTaskTitle';
+
+const MemberTaskTitleWithProgress = memo<Required<MemberTaskTitleProps>>(({ anchor, children }) => {
+ const { status } = useMemberProgress(anchor);
+ const detail = anchor.taskDetail;
+ const metrics: TaskMetrics = {
+ duration: detail?.duration,
+ llmCalls: detail?.totalSteps,
+ startTime: detail?.startedAt ? new Date(detail.startedAt).getTime() : undefined,
+ toolCalls: detail?.totalToolCalls,
+ };
+
+ return (
+ <Flexbox horizontal align={'center'} gap={8} style={{ minWidth: 0 }}>
+ <TaskStatusIndicator status={status} />
+ {children}
+ <MetricsDisplay metrics={metrics} status={status} />
+ </Flexbox>
+ );
+});
+
+MemberTaskTitleWithProgress.displayName = 'MemberTaskTitleWithProgress';
+
+/**
+ * What one member is doing or did. While it runs, show its live thread; once it
+ * finishes, its anchor holds the final answer (or the failure reason). The
+ * thread's own messages live in another bucket, so the conversation blocks
+ * cannot render a finished thread's text here.
+ */
+export const MemberTaskDetail = memo<{ anchor: UIChatMessage }>(({ anchor }) => {
+ const { status, threadId } = useMemberProgress(anchor);
+
+ if (!isProcessingStatus(status) || !threadId) {
+ return anchor.content ? <Markdown variant={'chat'}>{anchor.content}</Markdown> : null;
+ }
+
+ return (
+ <TaskContent
+ id={anchor.id}
+ isError={false}
+ messages={anchor.tasks}
+ status={status}
+ taskDetail={anchor.taskDetail}
+ threadId={threadId}
+ />
+ );
+});
+
+MemberTaskDetail.displayName = 'MemberTaskDetail';
diff --git a/packages/builtin-tool-group-management/src/client/MemberProgress/memberAnchor.test.ts b/packages/builtin-tool-group-management/src/client/MemberProgress/memberAnchor.test.ts
new file mode 100644
index 00000000000..ea39fc94520
--- /dev/null
+++ b/packages/builtin-tool-group-management/src/client/MemberProgress/memberAnchor.test.ts
@@ -0,0 +1,81 @@
+import { ThreadStatus, type UIChatMessage } from '@lobechat/types';
+import { describe, expect, it } from 'vitest';
+
+import { resolveMemberStatus, resolveMemberThreadId, selectMemberAnchors } from './memberAnchor';
+
+const row = (message: Partial<UIChatMessage>) => message as UIChatMessage;
+
+const messages = [
+ row({ id: 'supervisor', role: 'assistant' }),
+ row({ id: 'group-tool', parentId: 'supervisor', role: 'tool', tool_call_id: 'call_1' }),
+ row({
+ id: 'anchor-1',
+ metadata: { groupMemberAnchor: { agentId: 'eng', index: 1 } },
+ parentId: 'group-tool',
+ role: 'tool',
+ tool_call_id: 'call_1::m1',
+ }),
+ // Legacy anchor without the marker.
+ row({ id: 'anchor-0', parentId: 'group-tool', role: 'tool', tool_call_id: 'call_1::m0' }),
+ // The supervisor's continuation after the call resumes is not an anchor.
+ row({ id: 'summary', parentId: 'group-tool', role: 'assistant' }),
+];
+
+describe('selectMemberAnchors', () => {
+ it('keys marked and legacy anchors by task index', () => {
+ const anchors = selectMemberAnchors(messages, 'call_1');
+
+ expect(Object.keys(anchors)).toEqual(['0', '1']);
+ expect(anchors[0].id).toBe('anchor-0');
+ expect(anchors[1].id).toBe('anchor-1');
+ });
+
+ it('returns nothing for a call the server did not fan out', () => {
+ expect(selectMemberAnchors(messages, 'call_other')).toEqual({});
+ expect(selectMemberAnchors(messages, undefined)).toEqual({});
+ });
+});
+
+describe('resolveMemberStatus', () => {
+ it('treats a fresh anchor as running', () => {
+ expect(resolveMemberStatus(row({ pluginState: { status: 'pending' } }))).toBe(
+ ThreadStatus.Processing,
+ );
+ });
+
+ it('follows the polled thread while the anchor is still pending', () => {
+ const anchor = row({
+ pluginState: { status: 'pending' },
+ taskDetail: { status: ThreadStatus.Completed, threadId: 'thd_1' },
+ });
+
+ expect(resolveMemberStatus(anchor)).toBe(ThreadStatus.Completed);
+ });
+
+ it('lets the backfilled anchor outcome win', () => {
+ const anchor = row({
+ pluginState: { status: 'error', threadId: 'thd_1' },
+ taskDetail: { status: ThreadStatus.Processing, threadId: 'thd_1' },
+ });
+
+ expect(resolveMemberStatus(anchor)).toBe(ThreadStatus.Failed);
+ expect(resolveMemberStatus(row({ pluginState: { status: 'completed' } }))).toBe(
+ ThreadStatus.Completed,
+ );
+ });
+});
+
+describe('resolveMemberThreadId', () => {
+ it('reads the thread from polling first, then from the backfill', () => {
+ expect(
+ resolveMemberThreadId(
+ row({
+ pluginState: { threadId: 'thd_b' },
+ taskDetail: { status: ThreadStatus.Processing, threadId: 'thd_a' },
+ }),
+ ),
+ ).toBe('thd_a');
+ expect(resolveMemberThreadId(row({ pluginState: { threadId: 'thd_b' } }))).toBe('thd_b');
+ expect(resolveMemberThreadId(row({}))).toBeUndefined();
+ });
+});
diff --git a/packages/builtin-tool-group-management/src/client/MemberProgress/memberAnchor.ts b/packages/builtin-tool-group-management/src/client/MemberProgress/memberAnchor.ts
new file mode 100644
index 00000000000..593d80f1f34
--- /dev/null
+++ b/packages/builtin-tool-group-management/src/client/MemberProgress/memberAnchor.ts
@@ -0,0 +1,46 @@
+import { getGroupMemberAnchorIndex, ThreadStatus, type UIChatMessage } from '@lobechat/types';
+
+interface MemberAnchorState {
+ status?: string;
+ threadId?: string;
+}
+
+const anchorState = (anchor: UIChatMessage) => anchor.pluginState as MemberAnchorState | undefined;
+
+/**
+ * Member anchors under the group tool call `toolCallId`, keyed by task index.
+ * Only server-run multi-member calls write anchors; a client-run call has none.
+ */
+export const selectMemberAnchors = (
+ messages: UIChatMessage[],
+ toolCallId: string | undefined,
+): Record<number, UIChatMessage> => {
+ const anchors: Record<number, UIChatMessage> = {};
+ if (!toolCallId) return anchors;
+
+ const groupTool = messages.find((m) => m.role === 'tool' && m.tool_call_id === toolCallId);
+ if (!groupTool) return anchors;
+
+ for (const message of messages) {
+ if (message.parentId !== groupTool.id) continue;
+ const index = getGroupMemberAnchorIndex(message, 'tool');
+ if (index !== undefined) anchors[index] = message;
+ }
+ return anchors;
+};
+
+/**
+ * The server's backfill on the anchor is final. Until it lands, the polled
+ * thread status (`taskDetail`) is the live progress; an anchor with neither has
+ * just started.
+ */
+export const resolveMemberStatus = (anchor: UIChatMessage): ThreadStatus => {
+ const status = anchorState(anchor)?.status;
+ if (status === 'completed') return ThreadStatus.Completed;
+ if (status === 'error') return ThreadStatus.Failed;
+ return anchor.taskDetail?.status ?? ThreadStatus.Processing;
+};
+
+/** The member's isolation thread, once polled or backfilled onto the anchor. */
+export const resolveMemberThreadId = (anchor: UIChatMessage): string | undefined =>
+ anchor.taskDetail?.threadId ?? anchorState(anchor)?.threadId;
diff --git a/packages/builtin-tool-group-management/src/client/Render/ExecuteTasks/index.tsx b/packages/builtin-tool-group-management/src/client/Render/ExecuteTasks/index.tsx
index 427049723d7..f2659471853 100644
--- a/packages/builtin-tool-group-management/src/client/Render/ExecuteTasks/index.tsx
+++ b/packages/builtin-tool-group-management/src/client/Render/ExecuteTasks/index.tsx
@@ -18,6 +18,7 @@ import { useAgentGroupStore } from '@/store/agentGroup';
import { agentGroupSelectors } from '@/store/agentGroup/selectors';
import type { ExecuteTasksParams } from '../../../types';
+import { MemberTaskDetail, MemberTaskTitle, useMemberAnchors } from '../../MemberProgress';
const styles = createStaticStyles(({ css, cssVar }) => ({
assignee: css`
@@ -64,10 +65,12 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
/**
* ExecuteTasks Render component for Group Management tool
- * Accordion-style task list with expandable instruction and assignee on the right
+ * Accordion-style task list with expandable instruction and assignee on the right.
+ * A server-run call also shows each member's status, and expanding a task shows
+ * what that member did in its own thread.
*/
const ExecuteTasksRender = memo<BuiltinRenderProps<ExecuteTasksParams, unknown, string>>(
- ({ args, content }) => {
+ ({ args, content, toolCallId }) => {
const { t } = useTranslation('tool');
const theme = useTheme();
const { tasks } = args || {};
@@ -89,6 +92,8 @@ const ExecuteTasksRender = memo<BuiltinRenderProps<ExecuteTasksParams, unknown,
}));
}, [tasks, groupAgents]);
+ const anchors = useMemberAnchors(toolCallId);
+
if (!tasksWithAgents.length && !resultContent) return null;
return (
@@ -113,18 +118,25 @@ const ExecuteTasksRender = memo<BuiltinRenderProps<ExecuteTasksParams, unknown,
</div>
),
alwaysShowAction: true,
- children: task.instruction && (
- <Block padding={12} style={{ marginTop: 8 }} variant={'filled'}>
- <Text className={styles.instruction}>{task.instruction}</Text>
- </Block>
+ children: (task.instruction || anchors[index]) && (
+ <Flexbox gap={12} style={{ marginTop: 8 }}>
+ {task.instruction && (
+ <Block padding={12} variant={'filled'}>
+ <Text className={styles.instruction}>{task.instruction}</Text>
+ </Block>
+ )}
+ {anchors[index] && <MemberTaskDetail anchor={anchors[index]} />}
+ </Flexbox>
),
key: task.agentId || String(index),
title: (
<Flexbox horizontal align={'center'} gap={8} style={{ minWidth: 0 }}>
<span className={styles.index}>{index + 1}.</span>
- <Text className={styles.taskTitle} weight={500}>
- {task.title || 'Task'}
- </Text>
+ <MemberTaskTitle anchor={anchors[index]}>
+ <Text className={styles.taskTitle} weight={500}>
+ {task.title || 'Task'}
+ </Text>
+ </MemberTaskTitle>
</Flexbox>
),
}))}
diff --git a/packages/builtin-tool-group-management/src/client/Streaming/ExecuteTasks/index.tsx b/packages/builtin-tool-group-management/src/client/Streaming/ExecuteTasks/index.tsx
index c9b6ab85d87..ca8eaa57b98 100644
--- a/packages/builtin-tool-group-management/src/client/Streaming/ExecuteTasks/index.tsx
+++ b/packages/builtin-tool-group-management/src/client/Streaming/ExecuteTasks/index.tsx
@@ -9,6 +9,7 @@ import { useAgentGroupStore } from '@/store/agentGroup';
import { agentGroupSelectors } from '@/store/agentGroup/selectors';
import type { ExecuteTasksParams } from '../../../types';
+import { MemberTaskTitle, useMemberAnchors } from '../../MemberProgress';
const styles = createStaticStyles(({ css, cssVar }) => ({
container: css`
@@ -32,56 +33,65 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
`,
}));
-export const ExecuteTasksStreaming = memo<BuiltinStreamingProps<ExecuteTasksParams>>(({ args }) => {
- const { tasks } = args || {};
- const theme = useTheme();
+export const ExecuteTasksStreaming = memo<BuiltinStreamingProps<ExecuteTasksParams>>(
+ ({ args, toolCallId }) => {
+ const { tasks } = args || {};
+ // Once the server parks on the call, each member's live status rides on its anchor.
+ const anchors = useMemberAnchors(toolCallId);
+ const theme = useTheme();
- // Get active group ID and agents from store
- const activeGroupId = useAgentGroupStore(agentGroupSelectors.activeGroupId);
- const groupAgents = useAgentGroupStore((s) =>
- activeGroupId ? agentGroupSelectors.getGroupAgents(activeGroupId)(s) : [],
- );
+ // Get active group ID and agents from store
+ const activeGroupId = useAgentGroupStore(agentGroupSelectors.activeGroupId);
+ const groupAgents = useAgentGroupStore((s) =>
+ activeGroupId ? agentGroupSelectors.getGroupAgents(activeGroupId)(s) : [],
+ );
- // Get agent details for each task
- const tasksWithAgents = useMemo(() => {
- if (!tasks?.length || !groupAgents.length) return [];
- return tasks.map((task) => ({
- ...task,
- agent: groupAgents.find((agent) => agent.id === task.agentId) as AgentGroupMember | undefined,
- }));
- }, [tasks, groupAgents]);
+ // Get agent details for each task
+ const tasksWithAgents = useMemo(() => {
+ if (!tasks?.length || !groupAgents.length) return [];
+ return tasks.map((task) => ({
+ ...task,
+ agent: groupAgents.find((agent) => agent.id === task.agentId) as
+ AgentGroupMember | undefined,
+ }));
+ }, [tasks, groupAgents]);
- if (!tasksWithAgents.length) return null;
+ if (!tasksWithAgents.length) return null;
- return (
- <div className={styles.container}>
- {tasksWithAgents.map((task, index) => (
- <div className={styles.taskCard} key={task.agentId || index}>
- <Flexbox gap={8}>
- <Flexbox horizontal align={'center'} gap={8}>
- <AgentAvatar
- agentId={task.agentId}
- avatar={task.agent?.avatar}
- background={task.agent?.backgroundColor || theme.colorBgContainer}
- name={task.agent?.title}
- shape={'square'}
- size={20}
- />
- <span className={styles.taskTitle}>{task.title || task.agent?.title || 'Task'}</span>
+ return (
+ <div className={styles.container}>
+ {tasksWithAgents.map((task, index) => (
+ <div className={styles.taskCard} key={task.agentId || index}>
+ <Flexbox gap={8}>
+ <Flexbox horizontal align={'center'} gap={8}>
+ <AgentAvatar
+ agentId={task.agentId}
+ avatar={task.agent?.avatar}
+ background={task.agent?.backgroundColor || theme.colorBgContainer}
+ name={task.agent?.title}
+ shape={'square'}
+ size={20}
+ />
+ <MemberTaskTitle anchor={anchors[index]}>
+ <span className={styles.taskTitle}>
+ {task.title || task.agent?.title || 'Task'}
+ </span>
+ </MemberTaskTitle>
+ </Flexbox>
+ {task.instruction && (
+ <div className={styles.instruction}>
+ <Markdown animated variant={'chat'}>
+ {task.instruction}
+ </Markdown>
+ </div>
+ )}
</Flexbox>
- {task.instruction && (
- <div className={styles.instruction}>
- <Markdown animated variant={'chat'}>
- {task.instruction}
- </Markdown>
- </div>
- )}
- </Flexbox>
- </div>
- ))}
- </div>
- );
-});
+ </div>
+ ))}
+ </div>
+ );
+ },
+);
ExecuteTasksStreaming.displayName = 'ExecuteTasksStreaming';
diff --git a/packages/conversation-flow/src/__tests__/groupMemberAnchor.test.ts b/packages/conversation-flow/src/__tests__/groupMemberAnchor.test.ts
new file mode 100644
index 00000000000..601af9928c0
--- /dev/null
+++ b/packages/conversation-flow/src/__tests__/groupMemberAnchor.test.ts
@@ -0,0 +1,112 @@
+import { describe, expect, it } from 'vitest';
+
+import { parse } from '../parse';
+import type { Message } from '../types';
+
+/**
+ * Server-side `executeAgentTasks` runs each member in an isolation thread and
+ * writes one `role: 'tool'` completion anchor per member under the group tool
+ * message. No assistant lists those anchors in `tools[]`, so they rendered as
+ * duplicate orphan skill calls (each carrying the whole task list) right under
+ * the still-running supervisor turn.
+ */
+const message = (
+ id: string,
+ role: Message['role'],
+ parentId: string | null,
+ createdAt: number,
+ extra: Partial<Message> = {},
+): Message =>
+ ({
+ agentId: 'supervisor',
+ content: '',
+ createdAt,
+ id,
+ parentId,
+ role,
+ updatedAt: createdAt,
+ ...extra,
+ }) as Message;
+
+const plugin = {
+ apiName: 'executeAgentTasks',
+ arguments: '{"tasks":[{"agentId":"pm"},{"agentId":"eng"}]}',
+ identifier: 'lobe-group-management',
+ type: 'builtin',
+} as const;
+
+const anchor = (index: number, extra: Partial<Message> = {}) =>
+ message(`anchor-${index}`, 'tool', 'group-tool', 10 + index, {
+ plugin: { ...plugin, id: `call_1::m${index}` } as Message['plugin'],
+ pluginState: { status: 'pending' },
+ tool_call_id: `call_1::m${index}`,
+ ...extra,
+ });
+
+const conversation = (anchors: Message[], extra: Message[] = []): Message[] => [
+ message('user', 'user', null, 1, { content: 'Plan the interview loop' }),
+ message('supervisor', 'assistant', 'user', 2, {
+ content: 'Splitting the work',
+ metadata: { isSupervisor: true },
+ tools: [{ ...plugin, id: 'call_1', result_msg_id: 'group-tool' }],
+ }),
+ message('group-tool', 'tool', 'supervisor', 3, {
+ plugin: { ...plugin, id: 'call_1' } as Message['plugin'],
+ pluginState: { expectedMembers: 2, status: 'pending' },
+ tool_call_id: 'call_1',
+ }),
+ ...anchors,
+ ...extra,
+];
+
+const toolIds = (messages: Message[]) => {
+ const { flatList } = parse(messages);
+ return flatList.filter((item) => item.role === 'tool').map((item) => item.id);
+};
+
+describe('group-member anchors', () => {
+ it('hides marked anchors instead of rendering orphan tool calls', () => {
+ const messages = conversation([
+ anchor(0, { metadata: { groupMemberAnchor: { agentId: 'pm', index: 0 } } }),
+ anchor(1, { metadata: { groupMemberAnchor: { agentId: 'eng', index: 1 } } }),
+ ]);
+
+ const { flatList } = parse(messages);
+
+ expect(toolIds(messages)).toEqual([]);
+ expect(flatList.map((item) => item.id)).toEqual(['user', 'supervisor']);
+ });
+
+ it('hides legacy anchors written before the marker', () => {
+ expect(toolIds(conversation([anchor(0), anchor(1)]))).toEqual([]);
+ });
+
+ it('hides anchors once filled while the supervisor continues', () => {
+ const messages = conversation(
+ [
+ anchor(0, { content: 'PM draft', pluginState: { status: 'completed' } }),
+ anchor(1, { content: 'Eng bar', pluginState: { status: 'completed' } }),
+ ],
+ [message('summary', 'assistant', 'group-tool', 20, { content: 'Merged plan' })],
+ );
+
+ const { flatList } = parse(messages);
+
+ expect(toolIds(messages)).toEqual([]);
+ // The resumed reply still folds into the supervisor's turn.
+ const blocks = (flatList.at(-1) as { children?: Array<{ id: string }> }).children ?? [];
+ expect(blocks.map((block) => block.id)).toEqual(['supervisor', 'summary']);
+ });
+
+ // The legacy fallback only matches the suffix under a tool parent, so a real
+ // tool call whose id happens to end in `::m0` still renders.
+ it('keeps an assistant-owned tool row whose call id ends like an anchor', () => {
+ const messages: Message[] = [
+ message('user', 'user', null, 1),
+ message('assistant', 'assistant', 'user', 2, { content: 'thinking' }),
+ message('stray', 'tool', 'assistant', 3, { tool_call_id: 'x::m0' }),
+ ];
+
+ expect(toolIds(messages)).toEqual(['stray']);
+ });
+});
diff --git a/packages/conversation-flow/src/parse.ts b/packages/conversation-flow/src/parse.ts
index 70cf575553a..7d45ba2f61e 100644
--- a/packages/conversation-flow/src/parse.ts
+++ b/packages/conversation-flow/src/parse.ts
@@ -1,8 +1,26 @@
+import { getGroupMemberAnchorIndex } from '@lobechat/types';
+
import { buildHelperMaps } from './indexing';
import { buildIdTree } from './structuring';
import { Transformer } from './transformation';
import type { Message, MessageGroupMetadata, ParseOptions, ParseResult } from './types';
+/**
+ * Group-member anchors are server bookkeeping under a multi-member group tool
+ * call. No assistant lists them in `tools[]`, so left in they surface as orphan
+ * tool calls. The group tool's own render shows member progress from the raw rows.
+ */
+const withoutGroupMemberAnchors = (messages: Message[]): Message[] => {
+ const roleById = new Map(messages.map((message) => [message.id, message.role]));
+ const isAnchor = (message: Message) =>
+ getGroupMemberAnchorIndex(
+ message,
+ message.parentId ? roleById.get(message.parentId) : undefined,
+ ) !== undefined;
+
+ return messages.some(isAnchor) ? messages.filter((message) => !isAnchor(message)) : messages;
+};
+
/**
* Main parse function - the brain of the conversation flow engine
*
@@ -30,7 +48,7 @@ export function parse(
// This ensures FlatListBuilder and MessageCollector see the correct agentId
// and won't merge messages from different agents into the same group
// Only applies to scope: 'sub_agent' (agent-to-agent calls, not group orchestration)
- const processedMessages = messages.map((msg) => {
+ const processedMessages = withoutGroupMemberAnchors(messages).map((msg) => {
if (msg.metadata?.scope === 'sub_agent' && msg.metadata?.subAgentId) {
return { ...msg, agentId: msg.metadata.subAgentId };
}
diff --git a/packages/types/src/message/common/metadata.ts b/packages/types/src/message/common/metadata.ts
index 5f2c4018ea1..fb86f22caa2 100644
--- a/packages/types/src/message/common/metadata.ts
+++ b/packages/types/src/message/common/metadata.ts
@@ -273,6 +273,50 @@ export interface AgentDispatchMetadata {
visibility: 'internal';
}
+/**
+ * A multi-member group-management call (`executeAgentTasks`, `broadcast`) parks
+ * the supervisor on one group tool message and writes one `role: 'tool'` anchor
+ * per member under it. The server backfills an anchor when its member finishes,
+ * and the supervisor resumes once every anchor is filled. An isolated member's
+ * thread uses its anchor as `sourceMessageId`.
+ *
+ * Anchors are bookkeeping, not tool calls of their own: no assistant lists them
+ * in `tools[]`, so the reader must hide them instead of rendering orphan tool
+ * calls.
+ */
+export interface GroupMemberAnchorMetadata {
+ /** The member's agent id. */
+ agentId: string;
+ /** Position of the member in the call's `tasks` / `agentIds`. */
+ index: number;
+}
+
+/** Legacy anchors (written before the marker) only carry this tool_call_id suffix. */
+const LEGACY_GROUP_MEMBER_ANCHOR_CALL_ID = /::m(\d+)$/;
+
+interface GroupMemberAnchorCandidate {
+ metadata?: { groupMemberAnchor?: GroupMemberAnchorMetadata } | null;
+ role: string;
+ tool_call_id?: string | null;
+}
+
+/**
+ * Member index of a group-member anchor row, or `undefined` when the row is not
+ * one. Rows written before the `groupMemberAnchor` marker are recognized by
+ * their `::m<index>` tool_call_id suffix under a `role: 'tool'` parent.
+ */
+export const getGroupMemberAnchorIndex = (
+ message: GroupMemberAnchorCandidate,
+ parentRole?: string,
+): number | undefined => {
+ if (message.role !== 'tool') return;
+ const marker = message.metadata?.groupMemberAnchor;
+ if (marker) return marker.index;
+ if (parentRole !== 'tool') return;
+ const legacy = message.tool_call_id?.match(LEGACY_GROUP_MEMBER_ANCHOR_CALL_ID);
+ return legacy ? Number(legacy[1]) : undefined;
+};
+
/**
* The agent that authored a user turn on another agent's behalf (agent β†’ agent
* dispatch: a sibling agent calling `lh agent run`). Such rows are persisted
@@ -571,6 +615,11 @@ export interface MessageMetadata {
*/
externalOrigin?: ExternalOriginMetadata;
finishType?: string;
+ /**
+ * Marks a `role: 'tool'` row as one member's completion anchor under a
+ * multi-member group-management tool call. See {@link GroupMemberAnchorMetadata}.
+ */
+ groupMemberAnchor?: GroupMemberAnchorMetadata;
/** Operation owning the durable heterogeneous tool-state watermark. */
heterogeneousToolStateOperationId?: string;
/** Last persisted replace-snapshot sequence for this tool message. */
diff --git a/src/features/Conversation/Messages/GroupTasks/TaskItem/TaskTitle.tsx b/src/features/Conversation/Messages/GroupTasks/TaskItem/TaskTitle.tsx
index f8d6f7ddd8d..4e20f09a46f 100644
--- a/src/features/Conversation/Messages/GroupTasks/TaskItem/TaskTitle.tsx
+++ b/src/features/Conversation/Messages/GroupTasks/TaskItem/TaskTitle.tsx
@@ -36,7 +36,7 @@ interface TaskTitleProps {
title?: string;
}
-const TaskStatusIndicator = memo<{ status?: ThreadStatus }>(({ status }) => {
+export const TaskStatusIndicator = memo<{ status?: ThreadStatus }>(({ status }) => {
const isCompleted = status === ThreadStatus.Completed;
const isError = status === ThreadStatus.Failed || status === ThreadStatus.Cancel;
const isProcessing = status ? isProcessingStatus(status) : false;
@@ -80,7 +80,7 @@ interface MetricsDisplayProps {
status?: ThreadStatus;
}
-const MetricsDisplay = memo<MetricsDisplayProps>(({ metrics, status }) => {
+export const MetricsDisplay = memo<MetricsDisplayProps>(({ metrics, status }) => {
const { t } = useTranslation('chat');
const { llmCalls, toolCalls, startTime, duration, isLoading } = metrics;
const [elapsedTime, setElapsedTime] = useState(0);