Skip to content

Commit bbd69d7

Browse files
committed
fix: distinguish primary from sub-agent compression in banner
1 parent b80899a commit bbd69d7

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

app/src/components/RunOutput/Compression.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState } from 'preact/hooks';
22
import type { LangfuseEvent } from '@olympian/api/langfuse/langfuse.model.js';
3-
import { IconCompress } from './Icons.tsx';
3+
import { IconBrain, IconCompress, IconRobot } from './Icons.tsx';
44
import { fmtTime, splitThinking } from './format.tsx';
55
import {
66
ChatMessages,
@@ -171,20 +171,27 @@ export function CompressionMarker({
171171
before,
172172
after,
173173
contextLength,
174+
isSubagent = false,
174175
}: {
175176
before: number;
176177
after: number;
177178
contextLength: number;
179+
isSubagent?: boolean;
178180
}) {
179181
const pct = (t: number) => Math.round((t / contextLength) * 100);
180182
const k = (t: number) => (t >= 1000 ? `${(t / 1000).toFixed(1)}k` : String(t));
181183
return (
182184
<div class="mb-3 flex items-center gap-2 sm:gap-3">
183185
<div class="h-px flex-1 bg-zinc-800" />
184-
<div class="flex shrink-0 items-center gap-2 rounded-xl border border-cyan-900/50 bg-cyan-950/30 px-3 py-1.5 text-cyan-500">
185-
<IconCompress />
186+
<div class="flex shrink-0 items-center gap-2 rounded-xl border border-zinc-700/60 bg-zinc-900/40 px-3 py-1.5 text-zinc-400">
187+
<span
188+
class="inline-flex items-center"
189+
title={isSubagent ? 'sub-agent context' : 'primary agent context'}
190+
>
191+
{isSubagent ? <IconRobot /> : <IconBrain />}
192+
</span>
186193
<span class="text-[11px] font-mono font-semibold uppercase tracking-wide">Compress</span>
187-
<span class="whitespace-nowrap text-[10px] font-mono text-cyan-600 tabular-nums">
194+
<span class="whitespace-nowrap text-[10px] font-mono text-zinc-500 tabular-nums">
188195
{k(before)}{k(after)} tok · {pct(before)}%→{pct(after)}%
189196
</span>
190197
</div>

app/src/components/RunOutput/StreamingOutput.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ export function StreamingOutput({
6666
// Compression is inferred from the input-token drop between turns (see
6767
// compressionDrops), plus any explicitly-labelled compression span.
6868
const drops = useMemo(() => compressionDrops(orderedEvents), [orderedEvents]);
69-
const compressionCount = useMemo(
70-
() => drops.size + orderedEvents.reduce((n, ev) => n + (isExplicitCompression(ev) ? 1 : 0), 0),
71-
[drops, orderedEvents],
72-
);
7369

7470
// The parent agent's trace is the first one we see; delegate_task children run as separate
7571
// traces under the same session. Anything not on the parent trace is sub-agent activity.
@@ -81,6 +77,18 @@ export function StreamingOutput({
8177
return null;
8278
}, [orderedEvents]);
8379

80+
// Count only the PRIMARY agent's compressions here — this badge sits beside the primary
81+
// context meter, so a sub-agent compressing its own (separate, much larger) context must not
82+
// inflate it. Sub-agent compressions still render inline, labelled as such.
83+
const compressionCount = useMemo(() => {
84+
const onParent = (ev: LangfuseEvent) =>
85+
parentTraceId !== null && String(ev.body.traceId ?? '') === parentTraceId;
86+
let n = 0;
87+
for (const i of drops.keys()) if (onParent(orderedEvents[i])) n++;
88+
for (const ev of orderedEvents) if (isExplicitCompression(ev) && onParent(ev)) n++;
89+
return n;
90+
}, [drops, orderedEvents, parentTraceId]);
91+
8492
const contextPct = useMemo(() => {
8593
// Track the MAIN agent's context only — the first generation's trace. A run's stream
8694
// interleaves delegate_task children (separate traces) whose small fresh contexts would
@@ -266,6 +274,7 @@ export function StreamingOutput({
266274
before={drop.before}
267275
after={drop.after}
268276
contextLength={contextLength}
277+
isSubagent={isSubagent}
269278
/>
270279
)}
271280
{showDivider && <hr class="border-zinc-800 my-4" />}

0 commit comments

Comments
 (0)