@@ -381,6 +381,7 @@ export class SubAgentScope {
381381 let roundText = '' ;
382382 let lastUsage : GenerateContentResponseUsageMetadata | undefined =
383383 undefined ;
384+ let currentResponseId : string | undefined = undefined ;
384385 for await ( const streamEvent of responseStream ) {
385386 if ( abortController . signal . aborted ) {
386387 this . terminateMode = SubagentTerminateMode . CANCELLED ;
@@ -395,6 +396,10 @@ export class SubAgentScope {
395396 // Handle chunk events
396397 if ( streamEvent . type === 'chunk' ) {
397398 const resp = streamEvent . value ;
399+ // Track the response ID for tool call correlation
400+ if ( resp . responseId ) {
401+ currentResponseId = resp . responseId ;
402+ }
398403 if ( resp . functionCalls ) functionCalls . push ( ...resp . functionCalls ) ;
399404 const content = resp . candidates ?. [ 0 ] ?. content ;
400405 const parts = content ?. parts || [ ] ;
@@ -455,6 +460,7 @@ export class SubAgentScope {
455460 abortController ,
456461 promptId ,
457462 turnCounter ,
463+ currentResponseId ,
458464 ) ;
459465 } else {
460466 // No tool calls — treat this as the model's final answer.
@@ -543,6 +549,7 @@ export class SubAgentScope {
543549 * @param {FunctionCall[] } functionCalls - An array of `FunctionCall` objects to process.
544550 * @param {ToolRegistry } toolRegistry - The tool registry to look up and execute tools.
545551 * @param {AbortController } abortController - An `AbortController` to signal cancellation of tool executions.
552+ * @param {string } responseId - Optional API response ID for correlation with tool calls.
546553 * @returns {Promise<Content[]> } A promise that resolves to an array of `Content` parts representing the tool responses,
547554 * which are then used to update the chat history.
548555 */
@@ -551,6 +558,7 @@ export class SubAgentScope {
551558 abortController : AbortController ,
552559 promptId : string ,
553560 currentRound : number ,
561+ responseId ?: string ,
554562 ) : Promise < Content [ ] > {
555563 const toolResponseParts : Part [ ] = [ ] ;
556564
@@ -704,6 +712,7 @@ export class SubAgentScope {
704712 args,
705713 isClientInitiated : true ,
706714 prompt_id : promptId ,
715+ response_id : responseId ,
707716 } ;
708717
709718 const description = this . getToolDescription ( toolName , args ) ;
0 commit comments