@@ -18,6 +18,7 @@ import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
1818import type { AgentState } from '@codebuff/common/types/session-state'
1919import type { ProjectFileContext } from '@codebuff/common/util/file'
2020import type { ToolSet } from 'ai'
21+ import { mapValues } from 'lodash'
2122
2223type ToolName = 'spawn_agent_inline'
2324export const handleSpawnAgentInline = ( async (
@@ -33,7 +34,7 @@ export const handleSpawnAgentInline = (async (
3334 localAgentTemplates : Record < string , AgentTemplate >
3435 logger : Logger
3536 system : string
36- tools ? : ToolSet
37+ tools : ToolSet
3738 userId : string | undefined
3839 userInputId : string
3940 writeToClient : ( chunk : string | PrintModeEvent ) => void
@@ -60,9 +61,10 @@ export const handleSpawnAgentInline = (async (
6061 agentTemplate : parentAgentTemplate ,
6162 fingerprintId,
6263 system,
63- tools : parentTools = { } ,
64+ tools : parentTools ,
6465 userInputId,
6566 writeToClient,
67+ logger,
6668 } = params
6769 const {
6870 agent_type : agentTypeStr ,
@@ -80,17 +82,31 @@ export const handleSpawnAgentInline = (async (
8082
8183 validateAgentInput ( agentTemplate , agentType , prompt , spawnParams )
8284
85+ // Override template for inline agent to share system prompt & message history with parent
86+ const inlineTemplate = {
87+ ...agentTemplate ,
88+ includeMessageHistory : true ,
89+ inheritParentSystemPrompt : true ,
90+ }
91+
8392 // Create child agent state that shares message history with parent
84- const childAgentState : AgentState = createAgentState (
85- agentType ,
86- agentTemplate ,
87- parentAgentState ,
88- parentAgentState . agentContext ,
89- )
93+ const childAgentState : AgentState = {
94+ ...createAgentState (
95+ agentType ,
96+ inlineTemplate ,
97+ parentAgentState ,
98+ parentAgentState . agentContext ,
99+ ) ,
100+ systemPrompt : system ,
101+ toolDefinitions : mapValues ( parentTools , ( tool ) => ( {
102+ description : tool . description ,
103+ inputSchema : tool . inputSchema as { } ,
104+ } ) ) ,
105+ }
90106
91107 logAgentSpawn ( {
92108 ...params ,
93- agentTemplate,
109+ agentTemplate : inlineTemplate ,
94110 agentType,
95111 agentId : childAgentState . agentId ,
96112 parentId : childAgentState . parentId ,
@@ -104,14 +120,12 @@ export const handleSpawnAgentInline = (async (
104120 userInputId : `${ userInputId } -inline-${ agentType } ${ childAgentState . agentId } ` ,
105121 prompt : prompt || '' ,
106122 spawnParams,
107- agentTemplate,
123+ agentTemplate : inlineTemplate ,
108124 parentAgentState,
109125 agentState : childAgentState ,
110126 fingerprintId,
111127 parentSystemPrompt : system ,
112- parentTools : agentTemplate . inheritParentSystemPrompt
113- ? parentTools
114- : undefined ,
128+ parentTools,
115129 onResponseChunk : ( chunk ) => {
116130 // Inherits parent's onResponseChunk, except for context-pruner (TODO: add an option for it to be silent?)
117131 if ( agentType !== 'context-pruner' ) {
0 commit comments