Skip to content

Commit 7e25603

Browse files
committed
fix: prevent protected tools from being pruned
1 parent cecaff1 commit 7e25603

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

lib/messages/utils.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,24 @@ export function buildToolIdList(messages: WithParts[]): string[] {
103103
return toolIds
104104
}
105105

106-
export function getPruneToolIds(numericToolIds: number[], toolIdList: string[]): string[] {
106+
export interface GetPruneToolIdsOptions {
107+
numericToolIds: number[]
108+
toolIdList: string[]
109+
toolParameters: Map<string, { tool: string }>
110+
protectedTools: string[]
111+
}
112+
113+
export function getPruneToolIds(options: GetPruneToolIdsOptions): string[] {
114+
const { numericToolIds, toolIdList, toolParameters, protectedTools } = options
107115
const pruneToolIds: string[] = []
108116
for (const index of numericToolIds) {
109117
if (!isNaN(index) && index >= 0 && index < toolIdList.length) {
110-
pruneToolIds.push(toolIdList[index])
118+
const id = toolIdList[index]
119+
const metadata = toolParameters.get(id)
120+
if (metadata && protectedTools.includes(metadata.tool)) {
121+
continue
122+
}
123+
pruneToolIds.push(id)
111124
}
112125
}
113126
return pruneToolIds

lib/prompts/tool.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Prunes tool outputs from context to manage conversation size and reduce noise.
22

33
## IMPORTANT: The Prunable List
4-
A `<prunable-tools>` list is injected into user messages showing available tool outputs you can prune. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). Use these numeric IDs to select which tools to prune.
4+
A `<prunable-tools>` list is injected into user messages showing available tool outputs you can prune. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to prune.
55

66
## CRITICAL: When and How to Prune
77

lib/strategies/prune-tool.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ export function createPruneTool(
7070

7171
const currentAgent: string | undefined = findCurrentAgent(messages)
7272
const toolIdList: string[] = buildToolIdList(messages)
73-
const pruneToolIds: string[] = getPruneToolIds(numericToolIds, toolIdList)
73+
const pruneToolIds: string[] = getPruneToolIds({
74+
numericToolIds,
75+
toolIdList,
76+
toolParameters: state.toolParameters,
77+
protectedTools: config.strategies.pruneTool.protectedTools
78+
})
7479
state.prune.toolIds.push(...pruneToolIds)
7580

7681
const toolMetadata = new Map<string, ToolParameterEntry>()

0 commit comments

Comments
 (0)