@@ -285,6 +285,7 @@ export async function handleToolEvent(
285285) : Promise < void > {
286286 const isSubagent = scope === 'subagent'
287287 const parentToolCallId = isSubagent ? getScopedParentToolCallId ( event , context ) : undefined
288+ const agentId = event . scope ?. agentId ?? 'main'
288289
289290 if ( isSubagent && ! parentToolCallId ) return
290291
@@ -332,6 +333,7 @@ export async function handleToolEvent(
332333 options ,
333334 parentToolCallId ,
334335 scope ,
336+ agentId ,
335337 getScopedSpanIdentity ( event )
336338 )
337339}
@@ -409,13 +411,15 @@ async function handleCallPhase(
409411 options : OrchestratorOptions ,
410412 parentToolCallId : string | undefined ,
411413 scope : ToolScope ,
414+ agentId : string ,
412415 spanIdentity : { spanId ?: string ; parentSpanId ?: string }
413416) : Promise < void > {
414417 const { toolCallId, toolName } = data
415418 const args = data . arguments
416419 const isGenerating = data . status === TOOL_CALL_STATUS . generating
417420 const isPartial = data . partial === true || isGenerating
418421 const existing = context . toolCalls . get ( toolCallId )
422+ if ( existing ) existing . agentId ??= agentId
419423 const isSubagent = scope === 'subagent'
420424 const ui = getToolCallUI ( data )
421425
@@ -459,12 +463,13 @@ async function handleCallPhase(
459463 toolName ,
460464 args ,
461465 parentToolCallId ! ,
466+ agentId ,
462467 ui ,
463468 spanIdentity ,
464469 ! isPartial
465470 )
466471 } else {
467- registerMainToolCall ( context , toolCallId , toolName , args , existing , ui , ! isPartial )
472+ registerMainToolCall ( context , toolCallId , toolName , args , existing , agentId , ui , ! isPartial )
468473 }
469474
470475 if ( isPartial ) return
@@ -554,6 +559,7 @@ function registerSubagentToolCall(
554559 toolName : string ,
555560 args : Record < string , unknown > | undefined ,
556561 parentToolCallId : string ,
562+ agentId : string ,
557563 ui : { title ?: string ; phaseLabel ?: string ; hidden ?: boolean } ,
558564 spanIdentity : { spanId ?: string ; parentSpanId ?: string } ,
559565 finalized : boolean
@@ -574,6 +580,7 @@ function registerSubagentToolCall(
574580 id : toolCallId ,
575581 name : toolName ,
576582 status : 'pending' ,
583+ agentId,
577584 params : args ,
578585 startTime : Date . now ( ) ,
579586 }
@@ -594,6 +601,7 @@ function registerSubagentToolCall(
594601 const subagentToolCalls = context . subAgentToolCalls [ parentToolCallId ]
595602 const existingSubagentToolCall = subagentToolCalls . find ( ( tc ) => tc . id === toolCallId )
596603 if ( existingSubagentToolCall ) {
604+ existingSubagentToolCall . agentId ??= agentId
597605 if ( ! rebindResolvedIntegrationCall ( existingSubagentToolCall , toolName , args ) ) {
598606 updateToolCallFromFrame ( existingSubagentToolCall , toolName , args , finalized )
599607 }
@@ -609,6 +617,7 @@ function registerMainToolCall(
609617 toolName : string ,
610618 args : Record < string , unknown > | undefined ,
611619 existing : ToolCallState | undefined ,
620+ agentId : string ,
612621 ui : { title ?: string ; phaseLabel ?: string ; hidden ?: boolean } ,
613622 finalized : boolean
614623) : void {
@@ -633,6 +642,7 @@ function registerMainToolCall(
633642 id : toolCallId ,
634643 name : toolName ,
635644 status : 'pending' ,
645+ agentId,
636646 params : args ,
637647 startTime : Date . now ( ) ,
638648 }
0 commit comments