Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(assistant-ui): group consecutive tool calls into activity groups

Steven Enamakelc6fd629338b0
diff --git a/app/src/components/assistant-ui/activity-group.tsx b/app/src/components/assistant-ui/activity-group.tsx
index a30eb4e0ab..367dc5aa97 100644
--- a/app/src/components/assistant-ui/activity-group.tsx
+++ b/app/src/components/assistant-ui/activity-group.tsx
@@ -16,23 +16,46 @@ import {
ToolGroupTrigger,
} from '@/components/assistant-ui/elements/tool-group';
import { OpenHumanReasoningGroup } from '@/components/assistant-ui/reasoning-group';
+import { formatElapsed } from '@/components/assistant-ui/utils/task';
+import { useT } from '@/lib/i18n/I18nContext';
import { type MessagePrimitive, useAuiState } from '@assistant-ui/react';
import { type FC, type PropsWithChildren, useState } from 'react';
export type ActivityGroupPart = MessagePrimitive.GroupedParts.GroupPart;
+type Translate = (key: string) => string;
+
/**
* Trigger text for a run of reasoning and tool calls.
*
* Tool calls are what the reader counts; reasoning is either there or not, so
* it is named rather than counted. The group only exists when it holds at
* least one of the two, so the empty fallback is never shown in practice.
+ *
+ * `workedMs`, when known, turns a settled group into OpenClaw's turn receipt:
+ * "Worked for 42s · 3 tool calls".
*/
-export function activityGroupLabel(reasoningCount: number, toolCount: number): string {
- const tools = toolCount > 0 ? `${toolCount} tool ${toolCount === 1 ? 'call' : 'calls'}` : null;
- if (reasoningCount > 0 && tools) return `Reasoning · ${tools}`;
- if (reasoningCount > 0) return 'Reasoning';
- return tools ?? 'Activity';
+export function activityGroupLabel(
+ reasoningCount: number,
+ toolCount: number,
+ t: Translate,
+ workedMs?: number
+): string {
+ const tools =
+ toolCount > 0
+ ? t(toolCount === 1 ? 'chat.tools.callOne' : 'chat.tools.callOther').replace(
+ '{count}',
+ String(toolCount)
+ )
+ : null;
+ if (workedMs !== undefined && tools) {
+ return t('chat.tools.workedFor')
+ .replace('{duration}', formatElapsed(workedMs))
+ .replace('{calls}', tools);
+ }
+ if (reasoningCount > 0 && tools) return t('chat.tools.reasoningWithCalls').replace('{calls}', tools);
+ if (reasoningCount > 0) return t('chat.tools.reasoning');
+ return tools ?? t('chat.tools.activity');
}
/**
@@ -73,6 +96,17 @@ export const ActivityGroup: FC<PropsWithChildren<{ group: ActivityGroupPart }>>
const requiresAction = useAuiState(s =>
indices.some(i => s.message.parts[i]?.status?.type === 'requires-action')
);
+ // The turn's wall time (`chat_done.timing.total_ms`), credited to this group
+ // only when it holds every tool call in the message: a message with several
+ // activity groups cannot say which share of the time each one took.
+ const messageToolCount = useAuiState(
+ s => s.message.parts.filter(part => part?.type === 'tool-call').length
+ );
+ const totalStreamTime = useAuiState(
+ s => (s.message.metadata as { timing?: { totalStreamTime?: number } } | undefined)?.timing
+ ?.totalStreamTime
+ );
+ const { t } = useT();
const [userOpen, setUserOpen] = useState<boolean | null>(null);
const running = group.status.type === 'running' || isTail;
@@ -88,7 +122,12 @@ export const ActivityGroup: FC<PropsWithChildren<{ group: ActivityGroupPart }>>
<ToolGroupRoot variant="ghost" open={userOpen ?? live} onOpenChange={setUserOpen}>
<ToolGroupTrigger
count={toolCount}
- label={activityGroupLabel(reasoningCount, toolCount)}
+ label={activityGroupLabel(
+ reasoningCount,
+ toolCount,
+ t,
+ !live && toolCount === messageToolCount ? totalStreamTime : undefined
+ )}
active={running}
/>
<ToolGroupContent>{children}</ToolGroupContent>
diff --git a/app/src/components/assistant-ui/thread.activityGroup.test.tsx b/app/src/components/assistant-ui/thread.activityGroup.test.tsx
index 9e2c0ead5b..650ca00963 100644
--- a/app/src/components/assistant-ui/thread.activityGroup.test.tsx
+++ b/app/src/components/assistant-ui/thread.activityGroup.test.tsx
@@ -174,10 +174,26 @@ describe('activity group', () => {
});
describe('activityGroupLabel', () => {
+ const EN: Record<string, string> = {
+ 'chat.tools.callOne': '{count} tool call',
+ 'chat.tools.callOther': '{count} tool calls',
+ 'chat.tools.reasoningWithCalls': 'Reasoning · {calls}',
+ 'chat.tools.reasoning': 'Reasoning',
+ 'chat.tools.activity': 'Activity',
+ 'chat.tools.workedFor': 'Worked for {duration} · {calls}',
+ };
+ const t = (key: string) => EN[key] ?? key;
+
it('names reasoning and counts tool calls', () => {
- expect(activityGroupLabel(2, 1)).toBe('Reasoning · 1 tool call');
- expect(activityGroupLabel(1, 0)).toBe('Reasoning');
- expect(activityGroupLabel(0, 3)).toBe('3 tool calls');
- expect(activityGroupLabel(0, 0)).toBe('Activity');
+ expect(activityGroupLabel(2, 1, t)).toBe('Reasoning · 1 tool call');
+ expect(activityGroupLabel(1, 0, t)).toBe('Reasoning');
+ expect(activityGroupLabel(0, 3, t)).toBe('3 tool calls');
+ expect(activityGroupLabel(0, 0, t)).toBe('Activity');
+ });
+
+ it('reads as a receipt once the turn time is known', () => {
+ expect(activityGroupLabel(1, 3, t, 42_000)).toBe('Worked for 42s · 3 tool calls');
+ // Without a tool call there is nothing to credit the time to.
+ expect(activityGroupLabel(1, 0, t, 42_000)).toBe('Reasoning');
});
});