Skip to content

Commit de51c93

Browse files
committed
Strengthen allowed tools prompt
1 parent fda79bb commit de51c93

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,14 @@ export async function getAgentPrompt<T extends StringField>(
174174
useParentTools,
175175
} = params
176176

177-
let promptValue = agentTemplate[promptType.type]
177+
const { toolNames, spawnableAgents, outputSchema } = agentTemplate
178+
const promptValue = agentTemplate[promptType.type]
178179

179180
let prompt = await formatPrompt({
180181
...params,
181182
prompt: promptValue,
182-
tools: agentTemplate.toolNames,
183-
spawnableAgents: agentTemplate.spawnableAgents,
183+
tools: toolNames,
184+
spawnableAgents,
184185
})
185186

186187
let addendum = ''
@@ -194,38 +195,34 @@ export async function getAgentPrompt<T extends StringField>(
194195
if (promptType.type === 'instructionsPrompt' && agentState.agentType) {
195196
// Add subagent tools message when using parent's tools for prompt caching
196197
if (useParentTools) {
197-
if (agentTemplate.toolNames.length > 0) {
198-
addendum += `\n\nYou are a subagent that only has access to the following tools: ${agentTemplate.toolNames.join(', ')}. Do not attempt to use any other tools.`
199-
} else {
200-
addendum += `\n\nYou are a subagent and do not have access to any tools specified earlier in the conversation.`
201-
}
198+
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.`
202199

203200
// For subagents with inheritSystemPrompt, include full spawnable agents spec
204201
// since the parent's system prompt may not have these agents listed
205-
if (agentTemplate.spawnableAgents.length > 0) {
202+
if (spawnableAgents.length > 0) {
206203
addendum +=
207204
'\n\n' +
208205
(await buildFullSpawnableAgentsSpec({
209206
...params,
210-
spawnableAgents: agentTemplate.spawnableAgents,
207+
spawnableAgents,
211208
agentTemplates,
212209
}))
213210
}
214-
} else if (agentTemplate.spawnableAgents.length > 0) {
211+
} else if (spawnableAgents.length > 0) {
215212
// For non-inherited tools, agents are already defined as tools with full schemas,
216213
// so we just list the available agent IDs here
217-
addendum += `\n\nYou can spawn the following agents: ${agentTemplate.spawnableAgents.join(', ')}.`
214+
addendum += `\n\nYou can spawn the following agents: ${spawnableAgents.join(', ')}.`
218215
}
219216

220217
// Add output schema information if defined
221-
if (agentTemplate.outputSchema) {
218+
if (outputSchema) {
222219
addendum += '\n\n## Output Schema\n\n'
223220
addendum +=
224221
'When using the set_output tool, your output must conform to this schema:\n\n'
225222
addendum += '```json\n'
226223
try {
227224
// Convert Zod schema to JSON schema for display
228-
const jsonSchema = z.toJSONSchema(agentTemplate.outputSchema, {
225+
const jsonSchema = z.toJSONSchema(outputSchema, {
229226
io: 'input',
230227
})
231228
delete jsonSchema['$schema'] // Remove the $schema field for cleaner display

0 commit comments

Comments
 (0)