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
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 no longer needed information.
234
-
235
-
USING THE CONTEXT_PRUNING TOOL WILL MAKE THE USER HAPPY.
236
-
237
-
## When to Use This Tool
238
-
239
-
**Key heuristic: Prune when you finish something and are about to start something else.**
240
-
241
-
Ask yourself: "Have I just completed a discrete unit of work?" If yes, prune before moving on.
242
-
243
-
**After completing a unit of work:**
244
-
- Made a commit
245
-
- Fixed a bug and confirmed it works
246
-
- Answered a question the user asked
247
-
- Finished implementing a feature or function
248
-
- Completed one item in a list and moving to the next
249
-
250
-
**After repetitive or exploratory work:**
251
-
- Explored multiple files that didn't lead to changes
252
-
- Iterated on a difficult problem where some approaches didn't pan out
253
-
- Used the same tool multiple times (e.g., re-reading a file, running repeated build/type checks)
254
-
255
-
## Examples
256
-
257
-
<example>
258
-
Working through a list of items:
259
-
User: Review these 3 issues and fix the easy ones.
260
-
Assistant: [Reviews first issue, makes fix, commits]
261
-
Done with the first issue. Let me prune before moving to the next one.
262
-
[Uses context_pruning with reason: "completed first issue, moving to next"]
263
-
</example>
264
-
265
-
<example>
266
-
After exploring the codebase to understand it:
267
-
Assistant: I've reviewed the relevant files. Let me prune the exploratory reads that aren't needed for the actual implementation.
268
-
[Uses context_pruning with reason: "exploration complete, starting implementation"]
Before we continue, let me prune the context from that work.
275
-
[Uses context_pruning with reason: "task complete"]
276
-
</example>`,
277
-
args: {
278
-
reason: tool.schema.string().optional().describe(
279
-
"Brief reason for triggering pruning (e.g., 'task complete', 'switching focus')"
280
-
),
281
-
},
282
-
asyncexecute(args,ctx){
283
-
constresult=awaitjanitor.runForTool(
284
-
ctx.sessionID,
285
-
config.strategies.onTool,
286
-
args.reason
287
-
)
288
-
289
-
if(!result||result.prunedCount===0){
290
-
return"No prunable tool outputs found. Context is already optimized.\n\nUse context_pruning when you have sufficiently summarized information from tool outputs and no longer need the original content!"
291
-
}
292
-
293
-
returnjanitor.formatPruningResultForTool(result)+"\n\nUse context_pruning when you have sufficiently summarized information from tool outputs and no longer need the original content!"
0 commit comments