Skip to content

Commit 780a723

Browse files
committed
Fix context pruner adding an instructions prompt message
1 parent 3117f1a commit 780a723

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.agents/context-pruner.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const definition: AgentDefinition = {
2424
},
2525
},
2626

27+
inheritParentSystemPrompt: true,
2728
includeMessageHistory: true,
2829

2930
handleSteps: function* ({ agentState, params, logger }) {
@@ -163,8 +164,14 @@ const definition: AgentDefinition = {
163164
.filter((m): m is Message => m !== null)
164165
}
165166

166-
// PASS 0: Validate and fix tool-call/tool-result pairs
167-
let currentMessages = removeOrphanedToolMessages([...messages])
167+
// PASS 0: Remove last instructions prompt message.
168+
let currentMessages = [...messages]
169+
const lastInstructionsPromptIndex = currentMessages.findLastIndex(
170+
(message) => message.tags?.includes('INSTRUCTIONS_PROMPT'),
171+
)
172+
if (lastInstructionsPromptIndex !== -1) {
173+
currentMessages.splice(lastInstructionsPromptIndex, 1)
174+
}
168175

169176
// Initial check - if already under limit, return
170177
const initialTokens = countMessagesTokens(currentMessages)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ export async function getAgentPrompt<T extends StringField>(
190190
if (promptType.type === 'instructionsPrompt' && agentState.agentType) {
191191
// Add subagent tools message when using parent's tools for prompt caching
192192
if (useParentTools) {
193-
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.`
193+
if (agentTemplate.toolNames.length > 0) {
194+
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.`
195+
} else {
196+
addendum += `\n\nYou are a subagent and do not have access to any tools specified earlier in the conversation.`
197+
}
194198

195199
// For subagents with inheritSystemPrompt, include full spawnable agents spec
196200
// since the parent's system prompt may not have these agents listed

0 commit comments

Comments
 (0)