@@ -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