Skip to content

Commit ff0cee5

Browse files
authored
Fix: Sandbox tool calls name with intent and tool call grouping (#857)
* Fix: Sandbox tool calls name with intent and tool call grouping * refactor: streamline timeline hover target mapping in AgentSessionEventTimelineChart
1 parent c6b78d9 commit ff0cee5

7 files changed

Lines changed: 143 additions & 28 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@truefoundry/trueforge-ui': patch
3+
---
4+
5+
Improve session timeline tooltips with sandbox tool details and grouped sub-agent tool calls.

‎packages/trueforge-ui/src/atoms/agent-details/AgentSessionEventTimelineChart.tsx‎

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,28 @@ export function AgentSessionEventTimelineChart({
205205
() => getSubAgentLanes({ subAgentSegments, threadSegments: durationSegments, minWidthMs: MARKER_PX * msPerPx }),
206206
[durationSegments, msPerPx, subAgentSegments],
207207
);
208+
const subAgentToolCallGroups = useMemo(
209+
() =>
210+
subAgentLanes.flatMap(lane =>
211+
groupOverlappingToolCalls(lane.segments.filter(segment => segment.type === 'tool_call'))
212+
.filter(group => group.segments.length > 1)
213+
.map(group => ({ group, lane: lane.lane, subAgentLabel: lane.track.description })),
214+
),
215+
[subAgentLanes],
216+
);
217+
const groupedSubAgentToolCallIds = useMemo(
218+
() => new Set(subAgentToolCallGroups.flatMap(({ group }) => group.segments.map(segment => segment.id))),
219+
[subAgentToolCallGroups],
220+
);
221+
const subAgentEventSegments = useMemo(
222+
() =>
223+
subAgentLanes.flatMap(lane =>
224+
lane.segments
225+
.filter(segment => !groupedSubAgentToolCallIds.has(segment.id))
226+
.map(segment => ({ segment, lane: lane.lane })),
227+
),
228+
[groupedSubAgentToolCallIds, subAgentLanes],
229+
);
208230
const mainCandidates = useMemo(() => {
209231
return [...durationSegments.filter(segment => segment.threadId === MAIN_THREAD_ID), ...mainSubAgents].sort(
210232
(left, right) => left.startMs - right.startMs || left.endMs - right.endMs,
@@ -242,17 +264,28 @@ export function AgentSessionEventTimelineChart({
242264
() => [
243265
...turnBars.map((bar): TimelineHoverTarget => ({ type: TIMELINE_TYPE.turn, bar })),
244266
...markerGroups.map((group): TimelineHoverTarget => ({ type: TIMELINE_TYPE.markerGroup, group })),
245-
...subAgentLanes.flatMap(lane =>
246-
lane.segments.map((segment): TimelineHoverTarget => ({ type: TIMELINE_TYPE.event, segment })),
247-
),
267+
...subAgentEventSegments.map(({ segment }): TimelineHoverTarget => ({ type: TIMELINE_TYPE.event, segment })),
268+
...subAgentToolCallGroups.map(({ group, subAgentLabel }): TimelineHoverTarget => ({
269+
type: TIMELINE_TYPE.toolCallGroup,
270+
group,
271+
subAgentLabel,
272+
})),
248273
...mainEventSegments.map((segment): TimelineHoverTarget | null => {
249274
if (segment.type !== 'sub_agent') return { type: TIMELINE_TYPE.event, segment };
250275
const group = subAgentGroups.find(candidate => candidate.barId === segment.id);
251276
return group == null ? { type: TIMELINE_TYPE.event, segment } : { type: TIMELINE_TYPE.subAgentGroup, group };
252277
}),
253278
...toolCallGroups.map((group): TimelineHoverTarget => ({ type: TIMELINE_TYPE.toolCallGroup, group })),
254279
],
255-
[mainEventSegments, markerGroups, subAgentGroups, subAgentLanes, toolCallGroups, turnBars],
280+
[
281+
mainEventSegments,
282+
markerGroups,
283+
subAgentEventSegments,
284+
subAgentGroups,
285+
subAgentToolCallGroups,
286+
toolCallGroups,
287+
turnBars,
288+
],
256289
);
257290

258291
const barDataset = ({
@@ -319,19 +352,29 @@ export function AgentSessionEventTimelineChart({
319352
order: 0,
320353
} satisfies ChartDataset<'scatter', MarkerPoint[]>;
321354
}),
322-
...subAgentLanes.flatMap(lane =>
323-
lane.segments.map(segment =>
324-
barDataset({
325-
label: `${getSessionEventLabel(segment.type)}: ${segment.title}`,
326-
range: segment,
327-
y: centers[eventRow + 1 + lane.lane] ?? 0,
328-
color: getSessionEventColor(segment.type, isDark),
329-
hover: getSessionEventHoverColor(segment.type, isDark),
330-
thickness: 12,
331-
order: eventOrder(segment.type),
332-
inflateAmount: 0.5,
333-
}),
334-
),
355+
...subAgentEventSegments.map(({ segment, lane }) =>
356+
barDataset({
357+
label: `${getSessionEventLabel(segment.type)}: ${segment.title}`,
358+
range: segment,
359+
y: centers[eventRow + 1 + lane] ?? 0,
360+
color: getSessionEventColor(segment.type, isDark),
361+
hover: getSessionEventHoverColor(segment.type, isDark),
362+
thickness: 12,
363+
order: eventOrder(segment.type),
364+
inflateAmount: 0.5,
365+
}),
366+
),
367+
...subAgentToolCallGroups.map(({ group, lane }) =>
368+
barDataset({
369+
label: 'Parallel tool calls',
370+
range: group,
371+
y: centers[eventRow + 1 + lane] ?? 0,
372+
color: getSessionEventColor('tool_call', isDark),
373+
hover: getSessionEventHoverColor('tool_call', isDark),
374+
thickness: 12,
375+
order: eventOrder('tool_call'),
376+
inflateAmount: 0.5,
377+
}),
335378
),
336379
...mainEventSegments.map(segment =>
337380
barDataset({
@@ -366,7 +409,8 @@ export function AgentSessionEventTimelineChart({
366409
mainEventSegments,
367410
markerGroups,
368411
markerRow,
369-
subAgentLanes,
412+
subAgentEventSegments,
413+
subAgentToolCallGroups,
370414
toolCallGroups,
371415
turnBars,
372416
turnFill,
@@ -512,7 +556,10 @@ export function AgentSessionEventTimelineChart({
512556
}
513557
/>
514558
) : tooltipTarget?.type === TIMELINE_TYPE.toolCallGroup ? (
515-
<SessionToolCallGroupTooltip group={tooltipTarget.group} />
559+
<SessionToolCallGroupTooltip
560+
group={tooltipTarget.group}
561+
{...(tooltipTarget.subAgentLabel == null ? {} : { subAgentLabel: tooltipTarget.subAgentLabel })}
562+
/>
516563
) : tooltipTarget?.type === TIMELINE_TYPE.markerGroup ? (
517564
<SessionMarkerGroupTooltip group={tooltipTarget.group} />
518565
) : tooltipTarget?.type === TIMELINE_TYPE.subAgentGroup ? (

‎packages/trueforge-ui/src/atoms/agent-details/AgentSessionTimelineTooltip.tsx‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,23 @@ export function SessionTurnTooltip({
102102
);
103103
}
104104

105-
export function SessionToolCallGroupTooltip({ group }: { group: TimelineToolCallGroup }) {
105+
export function SessionToolCallGroupTooltip({
106+
group,
107+
subAgentLabel,
108+
}: {
109+
group: TimelineToolCallGroup;
110+
subAgentLabel?: string;
111+
}) {
106112
return (
107113
<div className="max-h-72 w-80 max-w-full overflow-auto text-xs">
108-
<div className="flex items-center justify-between gap-3">
114+
{subAgentLabel != null ? (
115+
<div className="border-b border-border py-1.5 text-text-secondary">{`Sub-Agent: ${subAgentLabel}`}</div>
116+
) : null}
117+
<div className="flex items-center justify-between gap-3 pt-1">
109118
<span className="font-medium text-text-secondary">Tool calls</span>
110119
<span className="tabular-nums text-text-secondary">{formatTimelineDuration(group.endMs - group.startMs)}</span>
111120
</div>
112-
<div className="mt-1.5 border-t border-border pt-1.5">
121+
<div className={subAgentLabel == null ? 'mt-1.5 border-t border-border pt-1.5' : 'mt-1.5'}>
113122
{group.segments.map(segment => (
114123
<div key={segment.id} className="flex items-center justify-between gap-2 py-0.5">
115124
<span className="min-w-0 truncate font-medium text-text-primary">

‎packages/trueforge-ui/src/utils/sessionEventTimelineChart.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export type TimelineHoverTarget =
7272
| { type: typeof TIMELINE_TYPE.turn; bar: TimelineTurnBar }
7373
| { type: typeof TIMELINE_TYPE.event; segment: SessionEventTimelineSegment }
7474
| { type: typeof TIMELINE_TYPE.markerGroup; group: TimelineMarkerGroup }
75-
| { type: typeof TIMELINE_TYPE.toolCallGroup; group: TimelineToolCallGroup }
75+
| { type: typeof TIMELINE_TYPE.toolCallGroup; group: TimelineToolCallGroup; subAgentLabel?: string }
7676
| { type: typeof TIMELINE_TYPE.subAgentGroup; group: TimelineSubAgentGroup };
7777

7878
/** Stable identity used to avoid replacing tooltip state while hovering the same bar. */

‎packages/trueforge-ui/src/utils/sessionTimelineEvents.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ export function toolCallDescription(toolCall: Record<string, unknown>): string {
132132
const argumentsJson = typeof fn?.arguments === 'string' ? fn.arguments : undefined;
133133
if (SANDBOX_TOOL_NAMES.has(name) || name === 'code_sandbox') {
134134
const intent = parseSandboxArgs(argumentsJson).intent?.trim();
135-
return intent != null && intent.length > 0 ? intent : name;
135+
const sandboxTool = `Sandbox: ${name}`;
136+
return intent != null && intent.length > 0 ? `${sandboxTool} - ${intent}` : sandboxTool;
136137
}
137138
// Deferred MCP wrappers store the real tool in args; surface it like ToolCallContainer.
138139
if (MCP_META_TOOLS.has(name)) {

‎packages/trueforge-ui/test/atoms/AgentSessionEventTimelineChart.test.tsx‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,59 @@ describe('AgentSessionEventTimelineChart', () => {
152152
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
153153
});
154154

155+
it('groups overlapping tool calls within a sub-agent lane', async () => {
156+
const subAgentSegments: SessionEventTimelineSegment[] = [
157+
...segments,
158+
{
159+
id: 'sub-agent',
160+
type: 'sub_agent',
161+
title: 'thread.created',
162+
description: 'Researcher',
163+
startMs: 100,
164+
endMs: 900,
165+
turnIndex: 0,
166+
threadId: 'sub-agent-thread',
167+
},
168+
{
169+
id: 'sub-tool-1',
170+
type: 'tool_call',
171+
title: 'tool.call',
172+
description: 'search',
173+
startMs: 200,
174+
endMs: 600,
175+
turnIndex: 0,
176+
threadId: 'sub-agent-thread',
177+
},
178+
{
179+
id: 'sub-tool-2',
180+
type: 'tool_call',
181+
title: 'tool.call',
182+
description: 'fetch',
183+
startMs: 300,
184+
endMs: 700,
185+
turnIndex: 0,
186+
threadId: 'sub-agent-thread',
187+
},
188+
];
189+
render(<AgentSessionEventTimelineChart turns={turns} segments={subAgentSegments} hiddenTypes={new Set()} />);
190+
191+
const datasets = Reflect.get(capturedData ?? {}, 'datasets');
192+
if (!Array.isArray(datasets)) throw new Error('Expected chart datasets');
193+
const groupedDatasetIndex = datasets.findIndex(dataset => Reflect.get(dataset, 'label') === 'Parallel tool calls');
194+
expect(groupedDatasetIndex).toBeGreaterThanOrEqual(0);
195+
expect(datasets.some(dataset => Reflect.get(dataset, 'label') === 'Tool call: search')).toBe(false);
196+
expect(datasets.some(dataset => Reflect.get(dataset, 'label') === 'Tool call: fetch')).toBe(false);
197+
198+
const onHover = Reflect.get(capturedOptions ?? {}, 'onHover');
199+
if (typeof onHover !== 'function') throw new Error('Expected Chart.js onHover callback');
200+
act(() => onHover({ native: null }, [{ datasetIndex: groupedDatasetIndex }]));
201+
202+
expect(await screen.findByText('Sub-Agent: Researcher')).toBeInTheDocument();
203+
expect(await screen.findByText('Tool calls')).toBeInTheDocument();
204+
expect(screen.getByText('search').parentElement?.parentElement).not.toHaveClass('border-t');
205+
expect(screen.getByText('fetch')).toBeInTheDocument();
206+
});
207+
155208
it('summarizes every sub-agent represented by a shared bar', () => {
156209
render(
157210
<SessionSubAgentGroupTooltip

‎packages/trueforge-ui/test/utils/sessionTimelineEvents.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ import { describe, expect, it } from 'vitest';
33
import { toolCallDescription } from '@/utils/sessionTimelineEvents.js';
44

55
describe('toolCallDescription', () => {
6-
it('shows sandbox intent instead of the exec tool name', () => {
6+
it('shows the sandbox tool name and intent', () => {
77
expect(
88
toolCallDescription({
99
function: {
1010
name: 'exec',
1111
arguments: JSON.stringify({ command: 'ls', intent: 'List workspace files' }),
1212
},
1313
}),
14-
).toBe('List workspace files');
14+
).toBe('Sandbox: exec - List workspace files');
1515
expect(
1616
toolCallDescription({
1717
function: { name: 'sandbox_exec', arguments: '{"intent":"Generate a PDF"}' },
1818
}),
19-
).toBe('Generate a PDF');
19+
).toBe('Sandbox: sandbox_exec - Generate a PDF');
2020
});
2121

2222
it('falls back to the tool name when intent is missing', () => {
23-
expect(toolCallDescription({ function: { name: 'exec', arguments: '{"command":"ls"}' } })).toBe('exec');
23+
expect(toolCallDescription({ function: { name: 'exec', arguments: '{"command":"ls"}' } })).toBe('Sandbox: exec');
2424
expect(toolCallDescription({ function: { name: 'search', arguments: '{"q":"x"}' } })).toBe('search');
2525
});
2626

0 commit comments

Comments
 (0)