@@ -594,12 +594,17 @@ export async function loopAgentSteps(
594594 agentState . runId = runId
595595
596596 let cachedAdditionalToolDefinitions : CustomToolDefinitions | undefined
597+ // Use parent's tools for prompt caching when inheritParentSystemPrompt is true
598+ const useParentTools =
599+ agentTemplate . inheritParentSystemPrompt && parentTools !== undefined
600+
597601 // Initialize message history with user prompt and instructions on first iteration
598602 const instructionsPrompt = await getAgentPrompt ( {
599603 ...params ,
600604 agentTemplate,
601605 promptType : { type : 'instructionsPrompt' } ,
602606 agentTemplates : localAgentTemplates ,
607+ useParentTools,
603608 additionalToolDefinitions : async ( ) => {
604609 if ( ! cachedAdditionalToolDefinitions ) {
605610 cachedAdditionalToolDefinitions = await additionalToolDefinitions ( {
@@ -634,10 +639,6 @@ export async function loopAgentSteps(
634639 } ,
635640 } ) ) ?? ''
636641
637- // Use parent's tools for prompt caching when inheritParentSystemPrompt is true
638- const useParentTools =
639- agentTemplate . inheritParentSystemPrompt && parentTools !== undefined
640-
641642 const tools = useParentTools
642643 ? parentTools
643644 : await getToolSet ( {
@@ -653,26 +654,13 @@ export async function loopAgentSteps(
653654 } ,
654655 } )
655656
656- // Build a message explaining the subagent's tool access when using parent's tools
657- const subagentToolsMessage = useParentTools
658- ? `You are a subagent that only has access to the following tools: ${ agentTemplate . toolNames . join ( ', ' ) } . Do not attempt to use any other tools.`
659- : undefined
660-
661657 const hasUserMessage = Boolean (
662658 prompt || ( spawnParams && Object . keys ( spawnParams ) . length > 0 ) ,
663659 )
664660
665661 const initialMessages = buildArray < Message > (
666662 ...agentState . messageHistory ,
667663
668- // Add subagent tools message before user prompt when using parent's tools for caching
669- subagentToolsMessage &&
670- userMessage ( {
671- content : withSystemTags ( subagentToolsMessage ) ,
672- tags : [ 'SUBAGENT_TOOLS' ] ,
673- keepDuringTruncation : true ,
674- } ) ,
675-
676664 hasUserMessage && [
677665 {
678666 // Actual user message!
0 commit comments