@@ -407,6 +407,83 @@ describe('Prompt Caching for Subagents with inheritParentSystemPrompt', () => {
407407 // allowing the LLM provider to cache and reuse the system prompt
408408 } )
409409
410+ it ( 'should pass parent tools and add subagent tools message when inheritParentSystemPrompt is true' , async ( ) => {
411+ const sessionState = getInitialSessionState ( mockFileContext )
412+
413+ // Create a child that inherits system prompt and has specific tools
414+ const childWithTools : AgentTemplate = {
415+ id : 'child-with-tools' ,
416+ displayName : 'Child With Tools' ,
417+ outputMode : 'last_message' ,
418+ inputSchema : { } ,
419+ spawnerPrompt : '' ,
420+ model : 'anthropic/claude-sonnet-4' ,
421+ includeMessageHistory : false ,
422+ inheritParentSystemPrompt : true ,
423+ mcpServers : { } ,
424+ toolNames : [ 'read_files' , 'code_search' ] ,
425+ spawnableAgents : [ ] ,
426+ systemPrompt : '' ,
427+ instructionsPrompt : '' ,
428+ stepPrompt : '' ,
429+ }
430+
431+ mockLocalAgentTemplates [ 'child-with-tools' ] = childWithTools
432+
433+ // Run parent agent first
434+ await loopAgentSteps ( {
435+ ...loopAgentStepsBaseParams ,
436+ userInputId : 'test-parent' ,
437+ prompt : 'Parent task' ,
438+ agentType : 'parent' ,
439+ agentState : sessionState . mainAgentState ,
440+ } )
441+
442+ const parentMessages = capturedMessages
443+ const parentSystemPrompt = ( parentMessages [ 0 ] . content [ 0 ] as TextPart ) . text
444+
445+ // Mock parent tools
446+ const parentTools = { read_files : { } , write_file : { } , code_search : { } }
447+
448+ // Run child agent with inheritParentSystemPrompt=true and parentTools
449+ capturedMessages = [ ]
450+ const childAgentState = {
451+ ...sessionState . mainAgentState ,
452+ agentId : 'child-agent' ,
453+ agentType : 'child-with-tools' as const ,
454+ messageHistory : [ ] ,
455+ }
456+
457+ await loopAgentSteps ( {
458+ ...loopAgentStepsBaseParams ,
459+ userInputId : 'test-child' ,
460+ prompt : 'Child task' ,
461+ agentType : 'child-with-tools' ,
462+ agentState : childAgentState ,
463+ parentSystemPrompt : parentSystemPrompt ,
464+ parentTools : parentTools as any ,
465+ } )
466+
467+ const childMessages = capturedMessages
468+
469+ // Verify child uses parent's system prompt
470+ expect ( childMessages [ 0 ] . role ) . toBe ( 'system' )
471+ expect ( ( childMessages [ 0 ] . content [ 0 ] as TextPart ) . text ) . toBe (
472+ parentSystemPrompt ,
473+ )
474+
475+ // Verify there's a message about subagent tools
476+ const subagentToolsMessage = childMessages . find (
477+ ( msg ) =>
478+ msg . role === 'user' &&
479+ msg . content [ 0 ] . type === 'text' &&
480+ msg . content [ 0 ] . text . includes ( 'subagent' ) &&
481+ msg . content [ 0 ] . text . includes ( 'read_files' ) &&
482+ msg . content [ 0 ] . text . includes ( 'code_search' ) ,
483+ )
484+ expect ( subagentToolsMessage ) . toBeTruthy ( )
485+ } )
486+
410487 it ( 'should support both inheritParentSystemPrompt and includeMessageHistory together' , async ( ) => {
411488 const sessionState = getInitialSessionState ( mockFileContext )
412489
0 commit comments