852
*/
853
private _handleSubagentStarted(
855
>
toolCallId: string,
856
>
agentName: string,
857
>
agentDisplayName: string,
858
>
agentDescription?: string,
859
>
taskPrompt?: string,
860
>
spawningToolParentId?: string,
861
>
): void {
862
>
const parentSessionUri = parseRequiredSessionUriFromChatUri(chatURI);
863
>
const subagentChatUri = buildSubagentChatUri(parentSessionUri, toolCallId);
864
>
865
>
// Already tracking this subagent
866
>
if (this._subagentChats.get(chatURI, toolCallId)) {
867
return;
868
}
870
>
this._logService.info(`[AgentSideEffects] Starting subagent turn: ${subagentChatUri} (parent=${chatURI}, toolCallId=${toolCallId})`);
871
>
872
>
// The spawning tool call lives in the immediate parent chat (top-level, or the parent subagent chat when nested).
873
>
const contentChatUri = spawningToolParentId
874
? this._subagentChats.get(chatURI, spawningToolParentId)?.chatUri ?? chatURI
876
>
877
>
// Seed the subagent's opening request with the delegated task prompt,
878
>
// supplied by the provider on the `subagent_started` signal.
879
>
const turnId = generateUuid();
880
>
this._stateManager.dispatchServerAction(subagentChatUri, {
881
>
type: ActionType.ChatTurnStarted,
882
>
turnId,
883
>
startedAt: new Date().toISOString(),
884
>
message: { text: taskPrompt ?? '', origin: { kind: MessageKind.User } },
885
>
});
886
>
887
>
this._subagentChats.set({ parentChatUri: chatURI, toolCallId, sessionUri: parentSessionUri, chatUri: subagentChatUri, turnStopWatch: StopWatch.create(false) }, chatURI, toolCallId);
888
>
889
>
// Dispatch the discovery content on the spawning tool call's own chat; the top-level chat is a no-op when nested.
890
>
const parentTurnId = this._stateManager.getActiveTurnId(contentChatUri);
891
>
if (parentTurnId) {
892
>
const parentState = this._stateManager.getSessionState(contentChatUri);
893
>
const existingContent = this._getRunningToolCallContent(parentState, parentTurnId, toolCallId);
894
>
this._stateManager.dispatchServerAction(contentChatUri, {
895
>
type: ActionType.ChatToolCallContentChanged,
896
>
turnId: parentTurnId,
897
>
toolCallId,
898
>
content: [
899
>
...existingContent,
900
>
{
901
>
type: ToolResultContentType.Subagent,
902
>
resource: subagentChatUri,
903
>
title: agentDisplayName,
904
>
agentName,
905
>
description: agentDescription,
906
>
},
907
>
],
908
>
});
909
>
}
910
>
}
911
912
/**