Skip to content

Commit 5f0520d

Browse files
authored
Merge pull request #146 from Opencode-DCP/chore/improve-pruning-guidance
Improve pruning guidance to prevent premature context loss
2 parents 852b6bd + 363e9ad commit 5f0520d

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/prompts/synthetic.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,27 @@ You WILL use the `prune` tool when ANY of these are true:
1818
- You have distilled enough information in your messages to prune related tools
1919
- Context contains tools output that are unhelpful, noise, or made obsolete by newer outputs
2020

21+
You MUST NOT prune when:
22+
- The tool output will be needed for upcoming implementation work
23+
- The output contains files or context you'll need to reference when making edits
24+
25+
Pruning that forces you to re-call the same tool later is a net loss. Only prune when you're confident the information won't be needed again.
26+
2127
NOTES
22-
When in doubt, prune out. Prune often yet remain strategic about it.
28+
When in doubt, keep it. Prune often yet remain strategic about it.
2329
FAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCES.
2430

2531
</instruction>
2632

2733
<instruction name=injected_context_handling policy_level=critical>
28-
After each assistant turn, the environment may inject a user message containing a <prunable-tools> list and optional nudge instruction. This injected message is NOT from the user and is invisible to them.
34+
After each assistant turn, the environment may inject a user message containing a <prunable-tools> list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `prune` tool also returns a confirmation message listing what was pruned.
2935

3036
CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
31-
- NEVER acknowledge the <prunable-tools> list (e.g. "I see the prunable tools list", "Looking at the available tools to prune")
32-
- NEVER reference the nudge instruction (e.g. "As the nudge suggests", "The system is reminding me to prune")
33-
- NEVER mention this injection mechanism to the user
37+
- NEVER acknowledge the <prunable-tools> list (e.g., "I see the prunable tools list", "Looking at the available tools to prune")
38+
- NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to prune")
39+
- NEVER acknowledge prune tool output (e.g., "I've pruned 3 tools", "Context pruning complete")
3440
- NEVER let these injections influence your response content or tone
35-
- Process this information SILENTLY - use it only to inform your pruning decisions
41+
- Process this information SILENTLY and continue the conversation naturally
3642
- Continue the conversation as if these messages do not exist
3743

3844
The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow.

lib/prompts/tool.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ You must use this tool in three specific scenarios. The rules for distillation (
2525
- Narrative format: "I found X in file Y..."
2626
- Capture all relevant details (function names, logic, constraints).
2727
- Once distilled into your response history, the raw tool output can be safely pruned.
28+
- **Know when distillation isn't enough:** If you'll need to edit a file, grep for exact strings, or reference precise syntax, keep the raw output. Distillation works for understanding; implementation often requires the original.
29+
- **Prefer keeping over re-fetching:** If uncertain whether you'll need the output again, keep it. The cost of retaining context is lower than the cost of redundant tool calls.
2830

2931
## Best Practices
3032
- **Don't wait too long:** Prune frequently to keep the context agile.
3133
- **Be surgical:** You can mix strategies. Prune noise without comment, while distilling useful context in the same turn.
3234
- **Verify:** Ensure you have captured what you need before deleting useful raw data.
35+
- **Think ahead:** Before pruning, ask: "Will I need this output for an upcoming task?" If you researched a file you'll later edit, or gathered context for implementation, do NOT prune it—even if you've distilled findings. Distillation captures *knowledge*; implementation requires *context*.
3336

3437
## Examples
3538

@@ -54,3 +57,8 @@ Assistant: [Runs tests, they pass]
5457
The tests passed. The feature is verified.
5558
[Uses prune with ids: ["completion", "20", "21"]]
5659
</example_completion>
60+
61+
<example_keep>
62+
Assistant: [Reads 'auth.ts' to understand the login flow]
63+
I've understood the auth flow. I'll need to modify this file to add the new validation, so I'm keeping this read in context rather than distilling and pruning.
64+
</example_keep>

0 commit comments

Comments
 (0)