SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat(ai-assistant): collapse thinking + tool-call steps into one row (#11361)
Vishal Sharma22d6d5248ff6
diff --git a/frontend/src/container/AIAssistant/components/ActivityGroup/ActivityGroup.module.scss b/frontend/src/container/AIAssistant/components/ActivityGroup/ActivityGroup.module.scssnew file mode 100644index 0000000000..10f92ee54c--- /dev/null+++ b/frontend/src/container/AIAssistant/components/ActivityGroup/ActivityGroup.module.scss@@ -0,0 +1,64 @@+// Collapsed activity summary — one row that hides the underlying+// thinking + tool-call steps. Reuses the same quiet treatment as+// ThinkingStep / ToolCallStep so it sits flush in the assistant bubble.+.activityGroup {+ width: 100%;+ font-size: 12px;+}++.activityHeader {+ display: flex;+ align-items: center;+ gap: 8px;+ padding: 4px 0;+ background: transparent;+ border: none;+ cursor: pointer;+ color: var(--l3-foreground);+ user-select: none;+ transition: color 0.12s ease;+ width: 100%;+ text-align: left;++ &:hover {+ color: var(--l1-foreground);+ }+}++.sparkleIcon {+ flex-shrink: 0;+ color: var(--accent-primary);++ &.iconPulsing {+ animation: activityGroupPulse 1.4s ease-in-out infinite;+ }+}++@keyframes activityGroupPulse {+ 0%,+ 100% {+ opacity: 0.55;+ }+ 50% {+ opacity: 1;+ }+}++.activitySummary {+ flex: 1;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ font-weight: 400;+}++.toggleChevron {+ flex-shrink: 0;+ color: inherit;+}++.activityBody {+ display: flex;+ flex-direction: column;+ padding: 2px 0 4px;+}diff --git a/frontend/src/container/AIAssistant/components/ActivityGroup/ActivityGroup.tsx b/frontend/src/container/AIAssistant/components/ActivityGroup/ActivityGroup.tsxnew file mode 100644index 0000000000..c305bf86ff--- /dev/null+++ b/frontend/src/container/AIAssistant/components/ActivityGroup/ActivityGroup.tsx@@ -0,0 +1,148 @@+import { useEffect, useRef, useState } from 'react';+import cx from 'classnames';+import { ChevronDown, ChevronRight, Sparkles } from '@signozhq/icons';++import { formatTime } from 'utils/timeUtils';++import { StreamingToolCall } from '../../types';+import ThinkingStep, { ThinkingContent, thinkingLabel } from '../ThinkingStep';+import ToolCallStep, {+ getToolDisplayLabel,+ ToolCallContent,+} from '../ToolCallStep';++import styles from './ActivityGroup.module.scss';++export type ActivityItem =+ | { id: string; kind: 'thinking'; content: string }+ | { id: string; kind: 'tool'; toolCall: StreamingToolCall };++interface ActivityGroupProps {+ items: ActivityItem[];+ /**+ * True only for the trailing activity group of an active stream — drives+ * the live "Working…" label and the elapsed-time tick (which re-stamps on+ * approval/clarification resume so wait time isn't counted).+ */+ isLive?: boolean;+}++/**+ * Single-item groups get a step-specific summary so the user doesn't see a+ * pointless "Worked through 1 step". Multi-item groups roll up into the+ * generic "Working… / Worked through N steps" treatment.+ */+function buildSummary(+ items: ActivityItem[],+ isLive: boolean,+ elapsed: number,+): string {+ if (items.length === 1) {+ const [only] = items;+ if (only.kind === 'thinking') {+ return thinkingLabel(isLive);+ }+ return getToolDisplayLabel(only.toolCall);+ }+ const stepLabel = `${items.length} steps`;+ if (!isLive) {+ return `Worked through ${stepLabel}`;+ }+ // Suppress the elapsed token until ≥ 1s — the first tick fires after+ // 1s anyway, and showing "0s" or "<1s" briefly adds noise.+ return elapsed >= 1000+ ? `Working… · ${formatTime(elapsed / 1000)} · ${stepLabel}`+ : `Working… · ${stepLabel}`;+}++/**+ * Single collapsed summary row that hides a run of thinking + tool-call steps.+ * Expands to show each underlying step inline. Used for every activity row+ * (including single-item ones) so all "what the agent did" rows share a+ * consistent ✨-led visual contract.+ */+export default function ActivityGroup({+ items,+ isLive = false,+}: ActivityGroupProps): JSX.Element {+ const [expanded, setExpanded] = useState(false);++ // Captures the moment this live phase started. Re-stamped on every+ // false→true transition so a stream that pauses on+ // approval/clarification and resumes doesn't roll the user's wait time+ // into the elapsed counter.+ const startedAtRef = useRef<number>(Date.now());+ const wasLiveRef = useRef<boolean>(isLive);+ const [elapsed, setElapsed] = useState(0);++ useEffect(() => {+ if (isLive && !wasLiveRef.current) {+ startedAtRef.current = Date.now();+ setElapsed(0);+ }+ wasLiveRef.current = isLive;++ if (!isLive) {+ return undefined;+ }+ // Tick once per second — the display is integer-second precision, so+ // faster ticks would just re-render the bubble for no visible change.+ const id = window.setInterval(() => {+ setElapsed(Date.now() - startedAtRef.current);+ }, 1000);+ return (): void => window.clearInterval(id);+ }, [isLive]);++ const summary = buildSummary(items, isLive, elapsed);+ const isSingle = items.length === 1;++ const toggle = (): void => setExpanded((v) => !v);++ return (+ <div className={styles.activityGroup}>+ <div className={styles.activityHeader} onClick={toggle}>+ <Sparkles+ size={12}+ className={cx(styles.sparkleIcon, { [styles.iconPulsing]: isLive })}+ />+ <span className={styles.activitySummary}>{summary}</span>+ {expanded ? (+ <ChevronDown size={12} className={styles.toggleChevron} />+ ) : (+ <ChevronRight size={12} className={styles.toggleChevron} />+ )}+ </div>++ {expanded && (+ <div className={styles.activityBody}>+ {isSingle ? (+ // Single-item: the outer chevron already provides disclosure,+ // so render the underlying content directly instead of wrapping+ // it in a second collapsible step row.+ items[0].kind === 'thinking' ? (+ <ThinkingContent content={items[0].content} />+ ) : (+ <ToolCallContent toolCall={items[0].toolCall} />+ )+ ) : (+ items.map((item, i) => {+ // A thinking step is live only while it's the trailing item+ // in a trailing live group — once any later event (text or+ // tool) arrives, the pass is done.+ const isLastItem = i === items.length - 1;+ return item.kind === 'thinking' ? (+ <ThinkingStep+ key={item.id}+ content={item.content}+ isLive={isLive && isLastItem}+ />+ ) : (+ <ToolCallStep key={item.id} toolCall={item.toolCall} />+ );+ })+ )}+ </div>+ )}+ </div>+ );+}diff --git a/frontend/src/container/AIAssistant/components/ActivityGroup/index.ts b/frontend/src/container/AIAssistant/components/ActivityGroup/index.tsnew file mode 100644index 0000000000..3cee4bbcc4--- /dev/null+++ b/frontend/src/container/AIAssistant/components/ActivityGroup/index.ts@@ -0,0 +1,2 @@+export { default } from './ActivityGroup';+export type { ActivityItem } from './ActivityGroup';diff --git a/frontend/src/container/AIAssistant/components/MessageBubble/MessageBubble.tsx b/frontend/src/container/AIAssistant/components/MessageBubble/MessageBubble.tsxindex 56367a66be..dedfcc85f8 100644--- a/frontend/src/container/AIAssistant/components/MessageBubble/MessageBubble.tsx+++ b/frontend/src/container/AIAssistant/components/MessageBubble/MessageBubble.tsx@@ -1,4 +1,4 @@-import React from 'react';+import React, { useMemo } from 'react';import cx from 'classnames';import ReactMarkdown from 'react-markdown';import remarkGfm from 'remark-gfm';@@ -9,11 +9,10 @@ import '../blocks';import { useVariant } from '../../VariantContext';import { Message, MessageBlock } from '../../types';import ActionsSection from '../ActionsSection';+import ActivityGroup, { ActivityItem } from '../ActivityGroup';import { RichCodeBlock } from '../blocks';import { MessageContext } from '../MessageContext';import MessageFeedback from '../MessageFeedback';-import ThinkingStep from '../ThinkingStep';-import ToolCallStep from '../ToolCallStep';import UserMessageActions from '../UserMessageActions';import styles from './MessageBubble.module.scss';@@ -40,38 +39,61 @@ function SmartPre({ children }: { children?: React.ReactNode }): JSX.Element {const MD_PLUGINS = [remarkGfm];const MD_COMPONENTS = { code: RichCodeBlock, pre: SmartPre };-/** Renders a single MessageBlock by type. */-function renderBlock(block: MessageBlock, index: number): JSX.Element {- switch (block.type) {- case 'thinking':- return <ThinkingStep key={index} content={block.content} />;- case 'tool_call':- // Blocks in a persisted message are always complete — done is always true.- return (- <ToolCallStep- key={index}- toolCall={{- toolName: block.toolName,- input: block.toolInput,- result: block.result,- done: true,- displayText: block.displayText,- }}- />- );- case 'text':- default:- return (- <ReactMarkdown- key={index}- className={styles.markdown}- remarkPlugins={MD_PLUGINS}- components={MD_COMPONENTS}- >- {block.content}- </ReactMarkdown>- );+type RenderGroup =+ | { kind: 'text'; id: string; content: string }+ | { kind: 'activity'; id: string; items: ActivityItem[] };++/**+ * Partition message blocks into render groups so consecutive thinking and+ * tool_call blocks collapse into a single ActivityGroup row. Text blocks+ * stand alone, mirroring the streaming view.+ */+function groupBlocks(blocks: MessageBlock[]): RenderGroup[] {+ const groups: RenderGroup[] = [];+ blocks.forEach((block, i) => {+ if (block.type === 'text') {+ groups.push({ kind: 'text', id: `text-${i}`, content: block.content });+ return;+ }+ const item: ActivityItem =+ block.type === 'thinking'+ ? { id: `t-${i}`, kind: 'thinking', content: block.content }+ : {+ id: `c-${block.toolCallId}`,+ kind: 'tool',+ // Persisted blocks are always complete.+ toolCall: {+ toolName: block.toolName,+ input: block.toolInput,+ result: block.result,+ done: true,+ displayText: block.displayText,+ },+ };+ const last = groups[groups.length - 1];+ if (last?.kind === 'activity') {+ last.items.push(item);+ } else {+ groups.push({ kind: 'activity', id: `a-${i}`, items: [item] });+ }+ });+ return groups;+}++function renderGroup(group: RenderGroup): JSX.Element {+ if (group.kind === 'text') {+ return (+ <ReactMarkdown+ key={group.id}+ className={styles.markdown}+ remarkPlugins={MD_PLUGINS}+ components={MD_COMPONENTS}+ >+ {group.content}+ </ReactMarkdown>+ );}+ return <ActivityGroup key={group.id} items={group.items} />;}interface MessageBubbleProps {@@ -90,6 +112,14 @@ export default function MessageBubble({const isUser = message.role === 'user';const hasBlocks = !isUser && message.blocks && message.blocks.length > 0;+ // Recompute groups only when the blocks array identity changes — store+ // updates that don't touch this message's blocks should not re-render the+ // underlying ThinkingStep/ToolCallStep children.+ const groups = useMemo(+ () => (hasBlocks ? groupBlocks(message.blocks!) : []),+ [hasBlocks, message.blocks],+ );+const messageClass = cx(styles.message,isUser ? styles.user : styles.assistant,@@ -128,8 +158,7 @@ export default function MessageBubble({<p className={styles.text}>{message.content}</p>) : hasBlocks ? (<MessageContext.Provider value={{ messageId: message.id }}>- {/* eslint-disable-next-line react/no-array-index-key */}- {message.blocks!.map((block, i) => renderBlock(block, i))}+ {groups.map((g) => renderGroup(g))}</MessageContext.Provider>) : (<MessageContext.Provider value={{ messageId: message.id }}>diff --git a/frontend/src/container/AIAssistant/components/StreamingMessage/StreamingMessage.tsx b/frontend/src/container/AIAssistant/components/StreamingMessage/StreamingMessage.tsxindex 4738b4c638..22f9274947 100644--- a/frontend/src/container/AIAssistant/components/StreamingMessage/StreamingMessage.tsx+++ b/frontend/src/container/AIAssistant/components/StreamingMessage/StreamingMessage.tsx@@ -1,4 +1,4 @@-import React from 'react';+import React, { useMemo } from 'react';import cx from 'classnames';import ReactMarkdown from 'react-markdown';import remarkGfm from 'remark-gfm';@@ -10,11 +10,10 @@ import type {import { useVariant } from '../../VariantContext';import { StreamingEventItem } from '../../types';+import ActivityGroup, { ActivityItem } from '../ActivityGroup';import ApprovalCard from '../ApprovalCard';import { RichCodeBlock } from '../blocks';import ClarificationForm from '../ClarificationForm';-import ThinkingStep from '../ThinkingStep';-import ToolCallStep from '../ToolCallStep';import messageStyles from '../MessageBubble/MessageBubble.module.scss';import styles from './StreamingMessage.module.scss';@@ -33,6 +32,59 @@ function SmartPre({ children }: { children?: React.ReactNode }): JSX.Element {const MD_PLUGINS = [remarkGfm];const MD_COMPONENTS = { code: RichCodeBlock, pre: SmartPre };+type RenderGroup =+ | { kind: 'text'; id: string; content: string }+ | {+ kind: 'activity';+ id: string;+ items: ActivityItem[];+ isTrailing: boolean;+ };++/**+ * Partition the streaming event timeline into render groups: runs of+ * consecutive thinking/tool events fold into a single activity group, text+ * events stay standalone. The last group is flagged as trailing so the+ * caller can drive a "live" indicator on it.+ *+ * Invariant relied on by the ActivityGroup elapsed-time timer: once a+ * group exists at a given array index, later events only extend its+ * `items` — they never shrink the array or re-key existing groups. That+ * keeps each ActivityGroup React instance stable across re-renders so the+ * timer's `wasLive` → `isLive` re-stamp captures the right transition.+ * The id fields below piggyback on that invariant: each event's position in+ * `events` is stable, so the derived id stays stable across re-renders.+ */+function groupStreamingEvents(events: StreamingEventItem[]): RenderGroup[] {+ const groups: RenderGroup[] = [];+ events.forEach((event, i) => {+ if (event.kind === 'text') {+ groups.push({ kind: 'text', id: `text-${i}`, content: event.content });+ return;+ }+ const item: ActivityItem =+ event.kind === 'thinking'+ ? { id: `t-${i}`, kind: 'thinking', content: event.content }+ : { id: `c-${i}`, kind: 'tool', toolCall: event.toolCall };+ const last = groups[groups.length - 1];+ if (last?.kind === 'activity') {+ last.items.push(item);+ } else {+ groups.push({+ kind: 'activity',+ id: `a-${i}`,+ items: [item],+ isTrailing: false,+ });+ }+ });+ const last = groups[groups.length - 1];+ if (last?.kind === 'activity') {+ last.isTrailing = true;+ }+ return groups;+}+/** Human-readable labels for execution status codes shown before any events arrive. */const STATUS_LABEL: Record<string, string> = {queued: 'Queued…',@@ -79,6 +131,11 @@ export default function StreamingMessage({[messageStyles.compact]: isCompact,});+ // Recompute groups only when the events array identity changes. The+ // streaming reducer pushes new entries into the same array reference+ // once per tick, so this naturally invalidates as events arrive.+ const groups = useMemo(() => groupStreamingEvents(events), [events]);+return (<div className={messageClass}><div className={messageStyles.bubble}>@@ -88,27 +145,28 @@ export default function StreamingMessage({)}{isEmpty && !statusLabel && <TypingDots />}- {/* eslint-disable react/no-array-index-key */}- {/* Events rendered in arrival order: text, thinking, and tool calls interleaved */}- {events.map((event, i) => {- if (event.kind === 'tool') {- return <ToolCallStep key={i} toolCall={event.toolCall} />;- }- if (event.kind === 'thinking') {- return <ThinkingStep key={i} content={event.content} />;+ {/* Runs of consecutive thinking + tool events collapse into a+ single ActivityGroup; text events render inline between+ them. The trailing group is "live" while streaming is+ active and not blocked on the user. */}+ {groups.map((group) => {+ if (group.kind === 'text') {+ return (+ <ReactMarkdown+ key={group.id}+ className={messageStyles.markdown}+ remarkPlugins={MD_PLUGINS}+ components={MD_COMPONENTS}+ >+ {group.content}+ </ReactMarkdown>+ );}+ const groupIsLive = group.isTrailing && !isWaitingOnUser;return (- <ReactMarkdown- key={i}- className={messageStyles.markdown}- remarkPlugins={MD_PLUGINS}- components={MD_COMPONENTS}- >- {event.content}- </ReactMarkdown>+ <ActivityGroup key={group.id} items={group.items} isLive={groupIsLive} />);})}- {/* eslint-enable react/no-array-index-key */}{/* While events are still streaming, append the typing dots so theuser has a clear "more is coming" signal. Hidden when the agentdiff --git a/frontend/src/container/AIAssistant/components/ThinkingStep/ThinkingStep.tsx b/frontend/src/container/AIAssistant/components/ThinkingStep/ThinkingStep.tsxindex 67deb984f2..4b914aaf0f 100644--- a/frontend/src/container/AIAssistant/components/ThinkingStep/ThinkingStep.tsx+++ b/frontend/src/container/AIAssistant/components/ThinkingStep/ThinkingStep.tsx@@ -5,11 +5,31 @@ import styles from './ThinkingStep.module.scss';interface ThinkingStepProps {content: string;+ /**+ * When false, label reads "Thought for a few seconds" — intentionally+ * vague because the API doesn't persist precise timing, so showing+ * seconds would be inconsistent between fresh and reloaded threads.+ */+ isLive?: boolean;+}++/** Body of a thinking step — extracted so ActivityGroup can render it directly. */+export function ThinkingContent({ content }: { content: string }): JSX.Element {+ return (+ <div className={styles.body}>+ <p className={styles.content}>{content}</p>+ </div>+ );+}++export function thinkingLabel(isLive: boolean): string {+ return isLive ? 'Thinking…' : 'Thought for a few seconds';}/** Collapsible thinking row — chevron + label, content in the expanded body. */export default function ThinkingStep({content,+ isLive = false,}: ThinkingStepProps): JSX.Element {const [expanded, setExpanded] = useState(false);@@ -23,14 +43,10 @@ export default function ThinkingStep({) : (<ChevronRight size={12} className={styles.chevron} />)}- <span className={styles.label}>Thinking</span>+ <span className={styles.label}>{thinkingLabel(isLive)}</span></div>- {expanded && (- <div className={styles.body}>- <p className={styles.content}>{content}</p>- </div>- )}+ {expanded && <ThinkingContent content={content} />}</div>);}diff --git a/frontend/src/container/AIAssistant/components/ToolCallStep/ToolCallStep.tsx b/frontend/src/container/AIAssistant/components/ToolCallStep/ToolCallStep.tsxindex 5049f4bb1f..8835d10736 100644--- a/frontend/src/container/AIAssistant/components/ToolCallStep/ToolCallStep.tsx+++ b/frontend/src/container/AIAssistant/components/ToolCallStep/ToolCallStep.tsx@@ -10,24 +10,58 @@ interface ToolCallStepProps {toolCall: StreamingToolCall;}+/**+ * Server-supplied `displayText` is the human-friendly title the backend+ * wants surfaced. Falls back to a derived label+ * ("signoz_get_dashboard" → "Get Dashboard") when missing.+ */+export function getToolDisplayLabel(toolCall: StreamingToolCall): string {+ const { toolName, displayText } = toolCall;+ if (displayText && displayText.trim().length > 0) {+ return displayText;+ }+ return toolName+ .replace(/^[a-z]+_/, '') // strip prefix like "signoz_"+ .replace(/_/g, ' ')+ .replace(/\b\w/g, (c) => c.toUpperCase());+}++/** Body of a tool-call step — extracted so ActivityGroup can render it directly. */+export function ToolCallContent({+ toolCall,+}: {+ toolCall: StreamingToolCall;+}): JSX.Element {+ const { toolName, input, result, done } = toolCall;+ return (+ <div className={styles.body}>+ <div className={styles.section}>+ <span className={styles.sectionLabel}>Tool</span>+ <span className={styles.toolName}>{toolName}</span>+ </div>+ <div className={styles.section}>+ <span className={styles.sectionLabel}>Input</span>+ <pre className={styles.json}>{JSON.stringify(input, null, 2)}</pre>+ </div>+ {done && result !== undefined && (+ <div className={styles.section}>+ <span className={styles.sectionLabel}>Output</span>+ <pre className={styles.json}>+ {typeof result === 'string' ? result : JSON.stringify(result, null, 2)}+ </pre>+ </div>+ )}+ </div>+ );+}+/** Collapsible tool-call row — chevron + label, in/out detail in the body. */export default function ToolCallStep({toolCall,}: ToolCallStepProps): JSX.Element {const [expanded, setExpanded] = useState(false);- const { toolName, input, result, done, displayText } = toolCall;-- // Prefer the server-supplied `displayText` from `ToolCallEventDTO` —- // it's the human-friendly title the backend wants surfaced. Fall back- // to a derived label ("signoz_get_dashboard" → "Get Dashboard") when- // the field is empty / null / missing.- const label =- displayText && displayText.trim().length > 0- ? displayText- : toolName- .replace(/^[a-z]+_/, '') // strip prefix like "signoz_"- .replace(/_/g, ' ')- .replace(/\b\w/g, (c) => c.toUpperCase());+ const { done } = toolCall;+ const label = getToolDisplayLabel(toolCall);const toggle = (): void => setExpanded((v) => !v);@@ -44,26 +78,7 @@ export default function ToolCallStep({<span className={styles.label}>{label}</span></div>- {expanded && (- <div className={styles.body}>- <div className={styles.section}>- <span className={styles.sectionLabel}>Tool</span>- <span className={styles.toolName}>{toolName}</span>- </div>- <div className={styles.section}>- <span className={styles.sectionLabel}>Input</span>- <pre className={styles.json}>{JSON.stringify(input, null, 2)}</pre>- </div>- {done && result !== undefined && (- <div className={styles.section}>- <span className={styles.sectionLabel}>Output</span>- <pre className={styles.json}>- {typeof result === 'string' ? result : JSON.stringify(result, null, 2)}- </pre>- </div>- )}- </div>- )}+ {expanded && <ToolCallContent toolCall={toolCall} />}</div>);}