@@ -157,6 +157,10 @@ export const taskTool = createTool({
157157 . describe (
158158 'Optional agent ID to resume from. If provided, the agent will continue from the previous execution transcript.'
159159 ) ,
160+ subagent_session_id : z
161+ . string ( )
162+ . optional ( )
163+ . describe ( 'Internal subagent session id for tracking' ) ,
160164 } ) ,
161165
162166 // 工具描述
@@ -202,8 +206,15 @@ export const taskTool = createTool({
202206 prompt,
203207 run_in_background = false ,
204208 resume,
209+ subagent_session_id,
205210 } = params ;
206211 const { updateOutput } = context ;
212+ const subagentSessionId =
213+ typeof subagent_session_id === 'string' && subagent_session_id . length > 0
214+ ? subagent_session_id
215+ : typeof resume === 'string' && resume . length > 0
216+ ? resume
217+ : nanoid ( ) ;
207218
208219 try {
209220 // 1. 获取 subagent 配置
@@ -229,7 +240,13 @@ export const taskTool = createTool({
229240
230241 // 3. 处理后台执行模式
231242 if ( run_in_background ) {
232- return handleBackgroundExecution ( subagentConfig , description , prompt , context ) ;
243+ return handleBackgroundExecution (
244+ subagentConfig ,
245+ description ,
246+ prompt ,
247+ context ,
248+ subagentSessionId
249+ ) ;
233250 }
234251
235252 // 4. 同步执行模式(原有逻辑)
@@ -249,6 +266,7 @@ export const taskTool = createTool({
249266 prompt,
250267 parentSessionId : context . sessionId ,
251268 permissionMode : context . permissionMode , // 继承父 Agent 的权限模式
269+ subagentSessionId,
252270 onToolStart : ( toolName ) => {
253271 vanillaStore . getState ( ) . app . actions . updateSubagentTool ( toolName ) ;
254272 } ,
@@ -330,7 +348,7 @@ export const taskTool = createTool({
330348 description,
331349 duration,
332350 stats : result . stats ,
333- subagentSessionId : result . agentId ,
351+ subagentSessionId,
334352 subagentType : subagent_type ,
335353 subagentStatus : 'completed' as const ,
336354 subagentSummary : result . message . slice ( 0 , 500 ) ,
@@ -352,7 +370,7 @@ export const taskTool = createTool({
352370 message : result . error || 'Unknown error' ,
353371 } ,
354372 metadata : {
355- subagentSessionId : result . agentId ,
373+ subagentSessionId,
356374 subagentType : subagent_type ,
357375 subagentStatus : 'failed' as const ,
358376 } ,
@@ -398,7 +416,8 @@ function handleBackgroundExecution(
398416 } ,
399417 description : string ,
400418 prompt : string ,
401- context : ExecutionContext
419+ context : ExecutionContext ,
420+ subagentSessionId : string
402421) : ToolResult {
403422 const manager = BackgroundAgentManager . getInstance ( ) ;
404423
@@ -409,6 +428,7 @@ function handleBackgroundExecution(
409428 prompt,
410429 parentSessionId : context . sessionId ,
411430 permissionMode : context . permissionMode ,
431+ agentId : subagentSessionId ,
412432 } ) ;
413433
414434 return {
0 commit comments