You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Tool Hook: Exposes context_pruning tool to AI (if configured)
216
+
*/
217
+
tool: config.strategies.onTool.length>0 ? {
218
+
context_pruning: tool({
219
+
description: `Performs semantic pruning on session tool outputs that are no longer relevant to the current task. Use this to declutter the conversation context and filter signal from noise when you notice the context is getting cluttered with outdated information.
220
+
221
+
## When to Use This Tool
222
+
223
+
- After completing a debugging session or fixing a bug
224
+
- When switching focus to a new task or feature
225
+
- After exploring multiple files that didn't lead to changes
226
+
- When you've been iterating on a difficult problem and some approaches didn't pan out
227
+
- When old file reads, greps, or bash outputs are no longer relevant
228
+
229
+
## Examples
230
+
231
+
<example>
232
+
Working through a list of bugs to fix:
233
+
User: Please fix these 5 type errors in the codebase.
234
+
Assistant: I'll work through each error. [Fixes first error]
235
+
First error fixed. Let me prune the debugging context before moving to the next one.
236
+
[Uses context_pruning with reason: "first bug fixed, moving to next task"]
237
+
</example>
238
+
239
+
<example>
240
+
After exploring the codebase to understand it:
241
+
Assistant: I've reviewed the relevant files. Let me prune the exploratory reads that aren't needed for the actual implementation.
242
+
[Uses context_pruning with reason: "exploration complete, pruning unrelated file reads"]
243
+
</example>
244
+
245
+
<example>
246
+
After trying multiple approaches that didn't work:
247
+
Assistant: I've been trying several approaches to fix this issue. Let me prune the failed attempts to keep focus on the working solution.
248
+
[Uses context_pruning with reason: "pruning failed iteration attempts, keeping working solution context"]
249
+
</example>`,
250
+
args: {
251
+
reason: tool.schema.string().optional().describe(
252
+
"Brief reason for triggering pruning (e.g., 'task complete', 'switching focus')"
253
+
),
254
+
},
255
+
asyncexecute(args,ctx){
256
+
constresult=awaitjanitor.runForTool(
257
+
ctx.sessionID,
258
+
config.strategies.onTool,
259
+
args.reason
260
+
)
261
+
262
+
if(!result||result.prunedCount===0){
263
+
return"No prunable tool outputs found. Context is already optimized."
0 commit comments