(
params: {
agentTemplate: AgentTemplate
promptType: { type: T }
fileContext: ProjectFileContext
agentState: AgentState
agentTemplates: Record<string, AgentTemplate>
additionalToolDefinitions: () => Promise<CustomToolDefinitions>
logger: Logger
useParentTools?: boolean
} & ParamsExcluding<
typeof formatPrompt,
'prompt' | 'tools' | 'spawnableAgents'
> &
ParamsExcluding<
typeof buildFullSpawnableAgentsSpec,
'spawnableAgents' | 'agentTemplates'
>,
)
| 152 | type StringField = 'systemPrompt' | 'instructionsPrompt' | 'stepPrompt' |
| 153 | |
| 154 | export async function getAgentPrompt<T extends StringField>( |
| 155 | params: { |
| 156 | agentTemplate: AgentTemplate |
| 157 | promptType: { type: T } |
| 158 | fileContext: ProjectFileContext |
| 159 | agentState: AgentState |
| 160 | agentTemplates: Record<string, AgentTemplate> |
| 161 | additionalToolDefinitions: () => Promise<CustomToolDefinitions> |
| 162 | logger: Logger |
| 163 | useParentTools?: boolean |
| 164 | } & ParamsExcluding< |
| 165 | typeof formatPrompt, |
| 166 | 'prompt' | 'tools' | 'spawnableAgents' |
| 167 | > & |
| 168 | ParamsExcluding< |
| 169 | typeof buildFullSpawnableAgentsSpec, |
| 170 | 'spawnableAgents' | 'agentTemplates' |
| 171 | >, |
| 172 | ): Promise<string | undefined> { |
| 173 | const { |
| 174 | agentTemplate, |
| 175 | promptType, |
| 176 | agentState, |
| 177 | agentTemplates, |
| 178 | additionalToolDefinitions: _additionalToolDefinitions, |
| 179 | useParentTools, |
| 180 | } = params |
| 181 | |
| 182 | const { toolNames, spawnableAgents, outputSchema } = agentTemplate |
| 183 | const promptValue = agentTemplate[promptType.type] |
| 184 | |
| 185 | let prompt = await formatPrompt({ |
| 186 | ...params, |
| 187 | prompt: promptValue, |
| 188 | tools: toolNames, |
| 189 | spawnableAgents, |
| 190 | }) |
| 191 | |
| 192 | let addendum = '' |
| 193 | |
| 194 | if (promptType.type === 'stepPrompt' && agentState.agentType && prompt) { |
| 195 | // Put step prompt within a system_reminder tag so agent doesn't think the user just spoke again. |
| 196 | prompt = `<system_reminder>${prompt}</system_reminder>` |
| 197 | } |
| 198 | |
| 199 | // Add tool instructions, spawnable agents, and output schema prompts to instructionsPrompt |
| 200 | if (promptType.type === 'instructionsPrompt' && agentState.agentType) { |
| 201 | // Add subagent tools message when using parent's tools for prompt caching |
| 202 | if (useParentTools) { |
| 203 | addendum += `\n\nYou are a subagent that only has access to the following tools: ${toolNames.length > 0 ? toolNames.join(', ') : 'none'}. Previously referenced tools in the conversation may have only been available to the parent agent. Do not attempt to use any other tools besides these listed here. You will only get tool errors if you do.` |
| 204 | |
| 205 | // For subagents with inheritSystemPrompt, include full spawnable agents spec |
| 206 | // since the parent's system prompt may not have these agents listed |
| 207 | if (spawnableAgents.length > 0) { |
| 208 | const spawnableAgentsSpec = await buildFullSpawnableAgentsSpec({ |
| 209 | ...params, |
| 210 | spawnableAgents, |
| 211 | agentTemplates, |
no test coverage detected