|
1 | | -Prunes tool outputs from context to manage conversation size. |
| 1 | +Prunes tool outputs from context to manage conversation size and reduce noise. |
2 | 2 |
|
3 | 3 | ## IMPORTANT: The Prunable List |
4 | | -A list of available tool outputs (with numeric IDs) is maintained for you in the SYSTEM PROMPT at the beginning of the context. This list is always up-to-date. You can rely on it to pick tools to prune. |
| 4 | +A list of available tool outputs (with numeric IDs) is maintained for you in the SYSTEM PROMPT at the beginning of the context. This list is always up-to-date. Use these IDs to select tools to prune. |
5 | 5 |
|
6 | | -## CRITICAL: Distill Before Pruning (NON-NEGOTIABLE) |
| 6 | +## CRITICAL: When and How to Prune |
7 | 7 |
|
8 | | -You MUST ALWAYS narrate your findings in a message BEFORE using this tool. No tool result (read, bash, grep, webfetch, etc.) should be left unexplained. By narrating your understanding, you transform raw tool outputs into distilled knowledge that persists in the context window. |
| 8 | +You must use this tool in three specific scenarios. The rules for distillation (summarizing findings) differ for each. |
9 | 9 |
|
10 | | -**Signal Management:** |
11 | | -After calling a series of tools, you ALWAYS have to distill signals from their results. This ensures traceability of your reasoning and is PARAMOUNT to best context window management practices. |
| 10 | +### 1. Task Completion (Clean Up) |
| 11 | +**When:** You have successfully completed a specific unit of work (e.g., fixed a bug, wrote a file, answered a question). |
| 12 | +**Action:** Prune the tools used for that task. |
| 13 | +**Distillation:** NOT REQUIRED. Since the task is done, the raw data is no longer needed. Simply state that the task is complete. |
12 | 14 |
|
13 | | -**Distillation Workflow:** |
14 | | -1. Call tools to investigate/explore. |
15 | | -2. In your next message, EXPLICITLY narrate: |
16 | | - - What you did (which tools, what you were looking for). |
17 | | - - What you found (the key facts/signals). |
18 | | - - What you concluded (how this affects the task or next step). |
19 | | - > THINK HIGH SIGNAL, LOW NOISE FOR THIS NARRATION. |
20 | | -3. ONLY AFTER narrating, call `prune` with the numeric IDs of outputs no longer needed. |
| 15 | +### 2. Removing Noise (Garbage Collection) |
| 16 | +**When:** You have read files or run commands that turned out to be irrelevant, unhelpful, or outdated (meaning later tools have provided fresher, more valid information). |
| 17 | +**Action:** Prune these specific tool outputs immediately. |
| 18 | +**Distillation:** FORBIDDEN. Do not pollute the context by summarizing useless information. Just cut it out. |
21 | 19 |
|
22 | | -**Tools are VOLATILE** - Once distilled knowledge is in your reply, you can safely prune. Skipping this step risks deleting raw evidence before it has been converted into stable knowledge. |
| 20 | +### 3. Context Conservation (Research & Consolidation) |
| 21 | +**When:** You have gathered useful information. Prune frequently as you work (e.g., after reading a few files), rather than waiting for a "long" phase to end. |
| 22 | +**Action:** Convert raw data into distilled knowledge. This allows you to discard large outputs (like full file reads) while keeping only the specific parts you need (like a single function signature or constant). |
| 23 | +**Distillation:** MANDATORY. Before pruning, you *must* explicitly summarize the key findings from *every* tool you plan to prune. |
| 24 | + - **Extract specific value:** If you read a large file but only care about one function, record that function's details and prune the whole read. |
| 25 | + - Narrative format: "I found X in file Y..." |
| 26 | + - Capture all relevant details (function names, logic, constraints). |
| 27 | + - Once distilled into your response history, the raw tool output can be safely pruned. |
23 | 28 |
|
24 | | -**After Pruning:** |
25 | | -Do NOT re-summarize or re-narrate. You already distilled your findings before calling prune. Continue with your next task. |
26 | | - |
27 | | -## When to Use This Tool |
28 | | - |
29 | | -**Key Heuristic:** Distill, then prune when you finish something and are about to start something else. |
30 | | - |
31 | | -1. **After a discrete unit of work**: Confirming a hypothesis, closing a branch of investigation, or finishing a feature. |
32 | | -2. **After exploratory bursts**: When tool calls led to a clear conclusion (or to noise). |
33 | | -3. **Before a new phase**: When old tool outputs are no longer needed for the next actions. |
| 29 | +## Best Practices |
| 30 | +- **Don't wait too long:** Prune frequently to keep the context agile. |
| 31 | +- **Be surgical:** You can mix strategies. Prune noise without comment, while distilling useful context in the same turn. |
| 32 | +- **Verify:** Ensure you have captured what you need before deleting useful raw data. |
34 | 33 |
|
35 | 34 | ## Examples |
36 | 35 |
|
37 | | -<example> |
38 | | -User: Review these 3 issues and fix the easy ones. |
39 | | -Assistant: [Reviews first issue, makes fix, commits] |
40 | | -Done with the first issue. Let me prune before moving to the next one. |
41 | | -[Uses prune with ids: [1, 2, 3, 4]] |
42 | | -</example> |
43 | | - |
44 | | -<example> |
45 | | -Assistant: I've reviewed the relevant files. Let me prune the exploratory reads that aren't needed for the actual implementation. |
46 | | -[Uses prune with ids: [1, 2, 5, 7]] |
47 | | -</example> |
| 36 | +<example_noise> |
| 37 | +Assistant: [Reads 'wrong_file.ts'] |
| 38 | +This file isn't relevant to the auth system. I'll remove it to clear the context. |
| 39 | +[Uses prune with ids: [5]] |
| 40 | +</example_noise> |
| 41 | + |
| 42 | +<example_consolidation> |
| 43 | +Assistant: [Reads 5 different config files] |
| 44 | +I have analyzed the configuration. Here is the distillation: |
| 45 | +- 'config.ts' uses port 3000. |
| 46 | +- 'db.ts' connects to mongo:27017. |
| 47 | +- The other 3 files were defaults. |
| 48 | +I have preserved the signals above, so I am now pruning the raw reads. |
| 49 | +[Uses prune with ids: [10, 11, 12, 13, 14]] |
| 50 | +</example_consolidation> |
| 51 | + |
| 52 | +<example_completion> |
| 53 | +Assistant: [Runs tests, they pass] |
| 54 | +The tests passed. The feature is verified. |
| 55 | +[Uses prune with ids: [20, 21]] |
| 56 | +</example_completion> |
0 commit comments