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(hetero-agent): persist streamed text alongside tool writes; collapse workflow summary (#13968)

Arvin Xu77fd0f13f0a4
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 148043bc3c2..258c5c31127 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -480,6 +480,9 @@
"viewMode.wideScreen": "Widescreen",
"workflow.awaitingConfirmation": "Awaiting your confirmation",
"workflow.failedSuffix": "(failed)",
+ "workflow.summaryFailed": "{{count}} failed",
+ "workflow.summaryMoreTools": "+{{count}} more",
+ "workflow.summaryTotalCalls": "{{count}} calls total",
"workflow.thoughtForDuration": "Thought for {{duration}}",
"workflow.toolDisplayName.activateDevice": "Activated device",
"workflow.toolDisplayName.activateSkill": "Activated a skill",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index c76f7bef504..bb1e470d0d7 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -480,6 +480,9 @@
"viewMode.wideScreen": "ๅฎฝๅฑ",
"workflow.awaitingConfirmation": "้œ€่ฆไฝ ็กฎ่ฎค",
"workflow.failedSuffix": "๏ผˆๅคฑ่ดฅ๏ผ‰",
+ "workflow.summaryFailed": "{{count}} ๆฌกๅคฑ่ดฅ",
+ "workflow.summaryMoreTools": "็ญ‰ {{count}} ็งๅทฅๅ…ท",
+ "workflow.summaryTotalCalls": "ๅ…ฑ {{count}} ๆฌก่ฐƒ็”จ",
"workflow.thoughtForDuration": "ๆ€่€ƒไบ† {{duration}}",
"workflow.toolDisplayName.activateDevice": "ๆฟ€ๆดปไบ†่ฎพๅค‡",
"workflow.toolDisplayName.activateSkill": "ๅฏ็”จไบ†ๆŠ€่ƒฝ",
diff --git a/packages/builtin-tool-claude-code/src/client/Inspector/Skill.tsx b/packages/builtin-tool-claude-code/src/client/Inspector/Skill.tsx
index 299b4e19f60..c81cbd20018 100644
--- a/packages/builtin-tool-claude-code/src/client/Inspector/Skill.tsx
+++ b/packages/builtin-tool-claude-code/src/client/Inspector/Skill.tsx
@@ -1,17 +1,46 @@
'use client';
-import {
- highlightTextStyles,
- inspectorTextStyles,
- shinyTextStyles,
-} from '@lobechat/shared-tool-ui/styles';
+import { inspectorTextStyles, shinyTextStyles } from '@lobechat/shared-tool-ui/styles';
import type { BuiltinInspectorProps } from '@lobechat/types';
-import { cx } from 'antd-style';
+import { SkillsIcon } from '@lobehub/ui/icons';
+import { createStaticStyles, cx } from 'antd-style';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { ClaudeCodeApiName, type SkillArgs } from '../../types';
+const styles = createStaticStyles(({ css, cssVar }) => ({
+ chip: css`
+ overflow: hidden;
+ display: inline-flex;
+ flex-shrink: 1;
+ gap: 6px;
+ align-items: center;
+
+ min-width: 0;
+ margin-inline-start: 6px;
+ padding-block: 2px;
+ padding-inline: 10px;
+ border-radius: 999px;
+
+ background: ${cssVar.colorFillTertiary};
+ `,
+ skillIcon: css`
+ flex-shrink: 0;
+ color: ${cssVar.colorTextDescription};
+ `,
+ skillName: css`
+ overflow: hidden;
+
+ min-width: 0;
+
+ font-size: 12px;
+ color: ${cssVar.colorText};
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ `,
+}));
+
export const SkillInspector = memo<BuiltinInspectorProps<SkillArgs>>(
({ args, partialArgs, isArgumentsStreaming, isLoading }) => {
const { t } = useTranslation('plugin');
@@ -31,10 +60,10 @@ export const SkillInspector = memo<BuiltinInspectorProps<SkillArgs>>(
>
<span>{label}</span>
{skillName && (
- <>
- <span>: </span>
- <span className={highlightTextStyles.primary}>{skillName}</span>
- </>
+ <span className={styles.chip}>
+ <SkillsIcon className={styles.skillIcon} size={12} />
+ <span className={styles.skillName}>{skillName}</span>
+ </span>
)}
</div>
);
diff --git a/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts b/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts
index 7b178437e7b..23315d752a7 100644
--- a/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts
@@ -384,6 +384,8 @@ export const formatReasoningDuration = (ms: number): string => {
return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
};
+const WORKFLOW_SUMMARY_TOP_N = 3;
+
export const getWorkflowSummaryText = (blocks: AssistantContentBlock[]): string => {
const tools = blocks.flatMap((b) => b.tools ?? []);
@@ -395,17 +397,58 @@ export const getWorkflowSummaryText = (blocks: AssistantContentBlock[]): string
groups.set(tool.apiName, existing);
}
- const toolParts: string[] = [];
- for (const [apiName, { count, errorCount }] of groups) {
- let part = getToolDisplayName(apiName);
- if (count > 1) part += ` (${count})`;
- if (errorCount > 0)
- part += ` ${t('workflow.failedSuffix', { defaultValue: '(failed)', ns: 'chat' })}`;
- toolParts.push(part);
+ const entries = [...groups.entries()];
+ const totalCalls = entries.reduce((sum, [, { count }]) => sum + count, 0);
+ const totalErrors = entries.reduce((sum, [, { errorCount }]) => sum + errorCount, 0);
+
+ let result: string;
+ // Few tool kinds: list each one fully (current behavior). "+1 more" reads awkwardly,
+ // so we only collapse when there are at least 2 extra kinds beyond the top N.
+ if (entries.length <= WORKFLOW_SUMMARY_TOP_N + 1) {
+ const toolParts = entries.map(([apiName, { count, errorCount }]) => {
+ let part = getToolDisplayName(apiName);
+ if (count > 1) part += ` (${count})`;
+ if (errorCount > 0)
+ part += ` ${t('workflow.failedSuffix', { defaultValue: '(failed)', ns: 'chat' })}`;
+ return part;
+ });
+ result = toolParts.join(', ');
+ } else {
+ const sorted = [...entries].sort(([, a], [, b]) => b.count - a.count);
+ const top = sorted.slice(0, WORKFLOW_SUMMARY_TOP_N);
+ const remainingKinds = sorted.length - WORKFLOW_SUMMARY_TOP_N;
+
+ const topText = top
+ .map(([apiName, { count }]) => {
+ const name = getToolDisplayName(apiName);
+ return count > 1 ? `${name} (${count})` : name;
+ })
+ .join(', ');
+
+ const segments: string[] = [
+ `${topText} ${t('workflow.summaryMoreTools', {
+ count: remainingKinds,
+ defaultValue: '+{{count}} more',
+ ns: 'chat',
+ })}`,
+ t('workflow.summaryTotalCalls', {
+ count: totalCalls,
+ defaultValue: '{{count}} calls total',
+ ns: 'chat',
+ }),
+ ];
+ if (totalErrors > 0) {
+ segments.push(
+ t('workflow.summaryFailed', {
+ count: totalErrors,
+ defaultValue: '{{count}} failed',
+ ns: 'chat',
+ }),
+ );
+ }
+ result = segments.join(' ยท ');
}
- let result = toolParts.join(', ');
-
const totalReasoningMs = blocks.reduce((sum, b) => sum + (b.reasoning?.duration ?? 0), 0);
if (totalReasoningMs > 0) {
result += ` ยท ${t('workflow.thoughtForDuration', {
diff --git a/src/features/Electron/titlebar/TabBar/TabItem.tsx b/src/features/Electron/titlebar/TabBar/TabItem.tsx
index ea2e085591b..99e549d9cea 100644
--- a/src/features/Electron/titlebar/TabBar/TabItem.tsx
+++ b/src/features/Electron/titlebar/TabBar/TabItem.tsx
@@ -1,6 +1,13 @@
'use client';
-import { ActionIcon, ContextMenuTrigger, Flexbox, type GenericItemType, Icon } from '@lobehub/ui';
+import {
+ ActionIcon,
+ Avatar,
+ ContextMenuTrigger,
+ Flexbox,
+ type GenericItemType,
+ Icon,
+} from '@lobehub/ui';
import { cx } from 'antd-style';
import { X } from 'lucide-react';
import { memo, useCallback } from 'react';
@@ -91,7 +98,17 @@ const TabItem = memo<TabItemProps>(
gap={6}
onClick={handleClick}
>
- {item.icon && <Icon className={styles.tabIcon} icon={item.icon} size="small" />}
+ {item.avatar ? (
+ <Avatar
+ emojiScaleWithBackground
+ avatar={item.avatar}
+ background={item.backgroundColor}
+ shape="square"
+ size={16}
+ />
+ ) : (
+ item.icon && <Icon className={styles.tabIcon} icon={item.icon} size="small" />
+ )}
<span className={styles.tabTitle}>{item.title}</span>
<ActionIcon
className={cx('closeIcon', styles.closeIcon)}
diff --git a/src/locales/default/chat.ts b/src/locales/default/chat.ts
index e8ac39cd89b..1187b6f306e 100644
--- a/src/locales/default/chat.ts
+++ b/src/locales/default/chat.ts
@@ -529,6 +529,9 @@ export default {
'viewMode.normal': 'Standard',
'viewMode.wideScreen': 'Widescreen',
'workflow.failedSuffix': '(failed)',
+ 'workflow.summaryFailed': '{{count}} failed',
+ 'workflow.summaryMoreTools': '+{{count}} more',
+ 'workflow.summaryTotalCalls': '{{count}} calls total',
'workflow.thoughtForDuration': 'Thought for {{duration}}',
'workflow.toolDisplayName.activateDevice': 'Activated device',
'workflow.toolDisplayName.activateSkill': 'Activated a skill',
diff --git a/src/routes/(main)/agent/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.test.tsx b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.test.tsx
index 1c473c982ad..0dec5d14caa 100644
--- a/src/routes/(main)/agent/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.test.tsx
+++ b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.test.tsx
@@ -121,7 +121,7 @@ describe('AgentDocumentsGroup', () => {
render(<AgentDocumentsGroup />);
- const item = await screen.findByText('brief.md');
+ const item = await screen.findByText('Brief');
expect(item).toBeInTheDocument();
expect(screen.getByText('A short brief')).toBeInTheDocument();
@@ -160,18 +160,18 @@ describe('AgentDocumentsGroup', () => {
render(<AgentDocumentsGroup />);
- expect(screen.getByText('brief.md')).toBeInTheDocument();
- expect(screen.getByText('example.com')).toBeInTheDocument();
+ expect(screen.getByText('Brief')).toBeInTheDocument();
+ expect(screen.getByText('Example')).toBeInTheDocument();
fireEvent.click(screen.getByText('Web'));
- expect(screen.queryByText('brief.md')).not.toBeInTheDocument();
- expect(screen.getByText('example.com')).toBeInTheDocument();
+ expect(screen.queryByText('Brief')).not.toBeInTheDocument();
+ expect(screen.getByText('Example')).toBeInTheDocument();
fireEvent.click(screen.getByText('Documents'));
- expect(screen.getByText('brief.md')).toBeInTheDocument();
- expect(screen.queryByText('example.com')).not.toBeInTheDocument();
+ expect(screen.getByText('Brief')).toBeInTheDocument();
+ expect(screen.queryByText('Example')).not.toBeInTheDocument();
});
it('renders empty state when no documents', () => {
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/heterogeneousAgentExecutor.test.ts b/src/store/chat/slices/aiChat/actions/__tests__/heterogeneousAgentExecutor.test.ts
index 8d3d50986fd..78a03ca2268 100644
--- a/src/store/chat/slices/aiChat/actions/__tests__/heterogeneousAgentExecutor.test.ts
+++ b/src/store/chat/slices/aiChat/actions/__tests__/heterogeneousAgentExecutor.test.ts
@@ -928,6 +928,41 @@ describe('heterogeneousAgentExecutor DB persistence', () => {
expect(glob1Create![0].parentId).toBe(turn5AssistantId);
expect(glob2Create![0].parentId).toBe(turn5AssistantId);
});
+
+ /**
+ * Regression: when a turn has text BEFORE tool_use under the same message.id,
+ * the tools[] write must carry the accumulated content too. Otherwise the
+ * gateway handler's `tool_end โ†’ fetchAndReplaceMessages` reads a tools-only
+ * row and clobbers the in-memory streamed text in the UI.
+ */
+ it('should persist accumulated text alongside tools when turn has text + tool_use', async () => {
+ const writes: Array<{ assistantId: string; content?: string; toolIds?: string[] }> = [];
+ mockUpdateMessage.mockImplementation(async (id: string, val: any) => {
+ if (val.tools) {
+ writes.push({
+ assistantId: id,
+ content: val.content,
+ toolIds: val.tools.map((t: any) => t.id),
+ });
+ }
+ });
+
+ await runWithEvents([
+ ccInit(),
+ // text streams first, then tool_use โ€” same msg.id
+ ccText('msg_01', 'Let me check the file...'),
+ ccToolUse('msg_01', 'toolu_read', 'Read', { file_path: '/a.ts' }),
+ ccToolResult('toolu_read', 'file content'),
+ ccResult(),
+ ]);
+
+ const toolWrites = writes.filter((w) => w.toolIds?.includes('toolu_read'));
+ expect(toolWrites.length).toBeGreaterThanOrEqual(1);
+ // Every tools[] write for this assistant must carry the accumulated text
+ for (const w of toolWrites) {
+ expect(w.content).toBe('Let me check the file...');
+ }
+ });
});
// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
diff --git a/src/store/chat/slices/aiChat/actions/heterogeneousAgentExecutor.ts b/src/store/chat/slices/aiChat/actions/heterogeneousAgentExecutor.ts
index aab0230fd28..fc6904c3bd1 100644
--- a/src/store/chat/slices/aiChat/actions/heterogeneousAgentExecutor.ts
+++ b/src/store/chat/slices/aiChat/actions/heterogeneousAgentExecutor.ts
@@ -135,12 +135,17 @@ interface ToolPersistenceState {
* - assistant.tools[].result_msg_id is set to the created tool message id, so
* the UI's parse() step can link tool messages back to the assistant turn
* (otherwise they render as orphan warnings).
+ * - Carries the latest accumulated text/reasoning into the same UPDATE, so DB
+ * stays in sync with what's been streamed. Without this, gateway handler's
+ * `tool_end โ†’ fetchAndReplaceMessages` would read a tools-only/no-content
+ * row and clobber the in-memory streamed text in the UI.
*/
const persistNewToolCalls = async (
incoming: ToolCallPayload[],
state: ToolPersistenceState,
assistantMessageId: string,
context: ConversationContext,
+ snapshot: { content: string; reasoning: string },
) => {
const freshTools = incoming.filter((t) => !state.persistedIds.has(t.id));
if (freshTools.length === 0) return;
@@ -149,6 +154,13 @@ const persistNewToolCalls = async (
// Claude Code echoing tool_use blocks) are safely deduped.
for (const tool of freshTools) state.persistedIds.add(tool.id);
+ const buildUpdate = (): Record<string, any> => {
+ const update: Record<string, any> = { tools: state.payloads };
+ if (snapshot.content) update.content = snapshot.content;
+ if (snapshot.reasoning) update.reasoning = { content: snapshot.reasoning };
+ return update;
+ };
+
// โ”€โ”€โ”€ PHASE 1: Write tools[] to assistant FIRST, WITHOUT result_msg_id โ”€โ”€โ”€
//
// LobeHub's conversation-flow parser filters tool messages by matching
@@ -161,11 +173,10 @@ const persistNewToolCalls = async (
// No orphan window.
for (const tool of freshTools) state.payloads.push({ ...tool } as ChatToolPayload);
try {
- await messageService.updateMessage(
- assistantMessageId,
- { tools: state.payloads },
- { agentId: context.agentId, topicId: context.topicId },
- );
+ await messageService.updateMessage(assistantMessageId, buildUpdate(), {
+ agentId: context.agentId,
+ topicId: context.topicId,
+ });
} catch (err) {
console.error('[HeterogeneousAgent] Failed to pre-register assistant tools:', err);
}
@@ -201,11 +212,10 @@ const persistNewToolCalls = async (
// โ”€โ”€โ”€ PHASE 3: Re-write assistant.tools[] with the result_msg_ids โ”€โ”€โ”€
// Without this, the UI can't hydrate tool results back into the inspector.
try {
- await messageService.updateMessage(
- assistantMessageId,
- { tools: state.payloads },
- { agentId: context.agentId, topicId: context.topicId },
- );
+ await messageService.updateMessage(assistantMessageId, buildUpdate(), {
+ agentId: context.agentId,
+ topicId: context.topicId,
+ });
} catch (err) {
console.error('[HeterogeneousAgent] Failed to finalize assistant tools:', err);
}
@@ -508,8 +518,23 @@ export const executeHeterogeneousAgent = async (
if (chunk?.chunkType === 'tools_calling') {
const tools = chunk.toolsCalling as ToolCallPayload[];
if (tools?.length) {
+ // Snapshot accumulators sync โ€” must travel with the same step's
+ // assistantMessageId. A late-bound getter would read NEW step's
+ // content if a step transition lands between scheduling and
+ // execution, while assistantMessageId would still be the OLD
+ // one (also captured sync) โ†’ cross-step contamination.
+ const snapshot = {
+ content: accumulatedContent,
+ reasoning: accumulatedReasoning,
+ };
persistQueue = persistQueue.then(() =>
- persistNewToolCalls(tools, toolState, currentAssistantMessageId, context),
+ persistNewToolCalls(
+ tools,
+ toolState,
+ currentAssistantMessageId,
+ context,
+ snapshot,
+ ),
);
}
}