Skip to content

Commit c9341e4

Browse files
committed
Fix up what's included in formatPrompt
1 parent be7bd3d commit c9341e4

File tree

2 files changed

+28
-53
lines changed

2 files changed

+28
-53
lines changed

packages/agent-runtime/src/templates/strings.ts

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,6 @@ export async function formatPrompt(
142142
}
143143
type StringField = 'systemPrompt' | 'instructionsPrompt' | 'stepPrompt'
144144

145-
export async function collectParentInstructions(params: {
146-
agentType: string
147-
agentTemplates: Record<string, AgentTemplate>
148-
}): Promise<string[]> {
149-
const { agentType, agentTemplates } = params
150-
const instructions: string[] = []
151-
152-
for (const template of Object.values(agentTemplates)) {
153-
if (template.parentInstructions) {
154-
const instruction = template.parentInstructions[agentType]
155-
if (instruction) {
156-
instructions.push(instruction)
157-
}
158-
}
159-
}
160-
161-
return instructions
162-
}
163-
164145
const additionalPlaceholders = {
165146
systemPrompt: [PLACEHOLDER.TOOLS_PROMPT, PLACEHOLDER.AGENTS_PROMPT],
166147
instructionsPrompt: [],
@@ -189,11 +170,9 @@ export async function getAgentPrompt<T extends StringField>(
189170
const {
190171
agentTemplate,
191172
promptType,
192-
fileContext,
193173
agentState,
194174
agentTemplates,
195175
additionalToolDefinitions,
196-
logger,
197176
} = params
198177

199178
let promptValue = agentTemplate[promptType.type]
@@ -203,21 +182,13 @@ export async function getAgentPrompt<T extends StringField>(
203182
}
204183
}
205184

206-
if (promptValue === undefined) {
207-
return undefined
208-
}
209-
210185
let prompt = await formatPrompt({
211186
...params,
212187
prompt: promptValue,
213188
tools: agentTemplate.toolNames,
214189
spawnableAgents: agentTemplate.spawnableAgents,
215190
})
216191

217-
if (prompt.trim() === '') {
218-
return undefined
219-
}
220-
221192
let addendum = ''
222193

223194
if (promptType.type === 'stepPrompt' && agentState.agentType && prompt) {
@@ -227,36 +198,21 @@ export async function getAgentPrompt<T extends StringField>(
227198

228199
// Add tool instructions, spawnable agents, and output schema prompts to instructionsPrompt
229200
if (promptType.type === 'instructionsPrompt' && agentState.agentType) {
230-
const hasTools = agentTemplate.toolNames.length > 0
231201
const toolsInstructions = agentTemplate.inheritParentSystemPrompt
232202
? fullToolList(agentTemplate.toolNames, await additionalToolDefinitions())
233203
: getShortToolInstructions(
234204
agentTemplate.toolNames,
235205
await additionalToolDefinitions(),
236206
)
237-
const hasSpawnableAgents = agentTemplate.spawnableAgents.length > 0
238207
addendum +=
239-
(hasTools ? '\n\n' + toolsInstructions : '') +
240-
(hasSpawnableAgents
241-
? '\n\n' +
242-
(await buildSpawnableAgentsDescription({
243-
...params,
244-
spawnableAgents: agentTemplate.spawnableAgents,
245-
agentTemplates,
246-
}))
247-
: '')
248-
249-
const parentInstructions = await collectParentInstructions({
250-
agentType: agentState.agentType,
251-
agentTemplates,
252-
})
253-
254-
if (parentInstructions.length > 0) {
255-
addendum += '\n\n## Additional Instructions for Spawning Agents\n\n'
256-
addendum += parentInstructions
257-
.map((instruction) => `- ${instruction}`)
258-
.join('\n')
259-
}
208+
'\n\n' +
209+
toolsInstructions +
210+
'\n\n' +
211+
(await buildSpawnableAgentsDescription({
212+
...params,
213+
spawnableAgents: agentTemplate.spawnableAgents,
214+
agentTemplates,
215+
}))
260216

261217
// Add output schema information if defined
262218
if (agentTemplate.outputSchema) {
@@ -283,5 +239,10 @@ export async function getAgentPrompt<T extends StringField>(
283239
}
284240
}
285241

286-
return prompt + addendum
242+
const combinedPrompt = (prompt + addendum).trim()
243+
if (combinedPrompt === '') {
244+
return undefined
245+
}
246+
247+
return combinedPrompt
287248
}

packages/agent-runtime/src/tools/prompts.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ export const fullToolList = (
204204
toolNames: readonly string[],
205205
additionalToolDefinitions: z.infer<typeof customToolDefinitionsSchema>,
206206
) => {
207+
if (
208+
toolNames.length === 0 &&
209+
Object.keys(additionalToolDefinitions).length === 0
210+
) {
211+
return ''
212+
}
213+
207214
return `## List of Tools
208215
209216
These are the only tools that you (Buffy) can use. The user cannot see these descriptions, so you should not reference any tool names, parameters, or descriptions. Do not try to use any other tools -- even if referenced earlier in the conversation, they are not available to you, instead they may have been previously used by other agents.
@@ -231,6 +238,13 @@ export const getShortToolInstructions = (
231238
toolNames: readonly string[],
232239
additionalToolDefinitions: z.infer<typeof customToolDefinitionsSchema>,
233240
) => {
241+
if (
242+
toolNames.length === 0 &&
243+
Object.keys(additionalToolDefinitions).length === 0
244+
) {
245+
return ''
246+
}
247+
234248
const toolDescriptions = [
235249
...(
236250
toolNames.filter(

0 commit comments

Comments
 (0)