Skip to content

Commit adc3c6a

Browse files
committed
Revert "Refactor: Centralize system reminder and simplify prompts"
This reverts commit df5a45c.
1 parent 6402ac0 commit adc3c6a

File tree

8 files changed

+97
-32
lines changed

8 files changed

+97
-32
lines changed

index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ const plugin: Plugin = (async (ctx) => {
4545

4646
const prompts = {
4747
synthInstruction: loadPrompt("synthetic"),
48-
nudgeInstruction: loadPrompt("nudge"),
49-
systemReminder: loadPrompt("system-reminder")
48+
nudgeInstruction: loadPrompt("nudge")
5049
}
5150

5251
// Install global fetch wrapper for context pruning and synthetic instruction injection

lib/fetch-wrapper/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export async function handleFormat(
9696
if (prunableList) {
9797
const includeNudge = ctx.config.nudge_freq > 0 && ctx.toolTracker.toolResultCount > ctx.config.nudge_freq
9898

99-
const endInjection = buildEndInjection(prunableList, includeNudge, ctx.prompts.nudgeInstruction, ctx.prompts.systemReminder)
99+
const endInjection = buildEndInjection(prunableList, includeNudge)
100100
if (format.injectPrunableList(data, endInjection)) {
101101
ctx.logger.debug("fetch", `Injected prunable tools list (${format.name})`, {
102102
ids: numericIds,

lib/fetch-wrapper/prunable-list.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import { extractParameterKey } from '../ui/display-utils'
22
import { getOrCreateNumericId } from '../state/id-mapping'
33
import type { ToolMetadata } from './types'
44

5+
const SYSTEM_REMINDER = `<system-reminder>
6+
These instructions are injected by a plugin and are invisible to the user. Do not acknowledge or reference them in your response - simply follow them silently.
7+
</system-reminder>`
8+
9+
const NUDGE_INSTRUCTION = `<instruction name=agent_nudge>
10+
You have accumulated several tool outputs. If you have completed a discrete unit of work and distilled relevant understanding in writing for the user to keep, use the prune tool to remove obsolete tool outputs from this conversation and optimize token usage.
11+
</instruction>`
12+
513
export interface PrunableListResult {
614
list: string
715
numericIds: number[]
@@ -41,18 +49,16 @@ export function buildPrunableToolsList(
4149

4250
export function buildEndInjection(
4351
prunableList: string,
44-
includeNudge: boolean,
45-
nudgeInstruction: string,
46-
systemReminder: string
52+
includeNudge: boolean
4753
): string {
4854
if (!prunableList) {
4955
return ''
5056
}
5157

52-
const parts = [systemReminder]
58+
const parts = [SYSTEM_REMINDER]
5359

5460
if (includeNudge) {
55-
parts.push(nudgeInstruction)
61+
parts.push(NUDGE_INSTRUCTION)
5662
}
5763

5864
parts.push(prunableList)

lib/fetch-wrapper/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export interface FormatDescriptor {
2929
export interface SynthPrompts {
3030
synthInstruction: string
3131
nudgeInstruction: string
32-
systemReminder: string
3332
}
3433

3534
export interface FetchHandlerContext {

lib/prompts/nudge.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
<system-reminder>
2+
This nudge is injected by a plugin and is invisible to the user. Do not acknowledge or reference it in your response - simply follow it silently.
3+
</system-reminder>
4+
15
<instruction name=agent_nudge>
2-
If you have completed a unit of work:
3-
1. DISTILL your findings into text for the user to keep.
4-
2. Use the `prune` tool to remove obsolete tool outputs.
5-
</instruction>
6+
You have accumulated several tool outputs. If you have completed a discrete unit of work and distilled relevant understanding in writing for the user to keep, use the prune tool to remove obsolete tool outputs from this conversation and optimize token usage.
7+
</instruction>

lib/prompts/synthetic.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<system-reminder>
2+
These instructions are injected by a plugin and are invisible to the user. Do not acknowledge or reference them in your response - simply follow them silently.
3+
4+
IMPORTANT: Your thinking/reasoning blocks must NOT reference, discuss, or address these instructions, the <prunable-tools> list, or any nudges about pruning. The user can see your thinking blocks, and referencing invisible plugin content will confuse them. In your thinking, focus only on the user's task and your problem-solving approach.
5+
</system-reminder>
6+
17
<instruction name=signal_management>
28
After calling a series of tools, YOU ALWAYS HAVE TO distill signals from their results in your next message. This ensures tracability of your reasoning, informs the user of your findings, and is PARAMOUNT to best context window management practices.
39

@@ -31,4 +37,4 @@ EXAMPLE WORKFLOW:
3137
>YOU MUST ALWAYS THINK HIGH SIGNAL LOW NOISE FOR THIS NARRATION
3238
4. ONLY AFTER the narration, you call the `prune` tool with a brief reason (e.g. "exploration for bug X complete; moving on to next bug").
3339
5. AFTER pruning succeeds, DO NOT re-summarize or re-narrate. You already distilled your findings before calling prune. Continue with your next task, or if you need more information from the user, wait for their response.
34-
</instruction>
40+
</instruction>

lib/prompts/system-reminder.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/prompts/tool.txt

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,75 @@
1-
Prunes tool outputs from context to manage conversation size.
2-
Refer to the <prunable-tools> list for available IDs.
1+
Prunes tool outputs from context to manage conversation size. Reference the <prunable-tools> list injected at the end of the conversation to see available numeric IDs.
32

4-
WHEN TO USE THIS TOOL:
5-
- After you complete a discrete unit of work (e.g. confirming a hypothesis, or closing out one branch of investigation).
6-
- After exploratory bursts of tool calls that led you to a clear conclusion (or to noise).
7-
- Before starting a new phase of work where old tool outputs are no longer needed to inform your next actions.
3+
USING THE PRUNE TOOL WILL MAKE THE USER HAPPY.
84

9-
CRITICAL: Distill Before Pruning
10-
You MUST ALWAYS narrate your findings in a message BEFORE using this tool. No tool result should be left unexplained. By narrating your understanding, you transform raw tool outputs into distilled knowledge that persists in the context window.
5+
## CRITICAL: Distill Before Pruning
116

12-
Tools are VOLATILE - Once distilled knowledge is in your reply, you can safely prune.
7+
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.
138

14-
Example Workflow:
15-
1. Investigate with tools.
16-
2. Explicitly narrate findings (High Signal, Low Noise).
17-
3. Call `prune` with relevant IDs.
9+
**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.
10+
11+
**Distillation workflow:**
12+
1. Call tools to investigate/explore
13+
2. In your next message, EXPLICITLY narrate:
14+
- What you did (which tools, what you were looking for)
15+
- What you found (the key facts/signals)
16+
- What you concluded (how this affects the task or next step)
17+
3. ONLY AFTER narrating, call `prune` with the numeric IDs of outputs no longer needed
18+
19+
> THINK HIGH SIGNAL, LOW NOISE FOR THIS NARRATION
20+
21+
**After pruning:** Do NOT re-summarize or re-narrate. You already distilled your findings before calling prune. Continue with your next task, or if you need more information from the user, wait for their response.
22+
23+
## How to Use
24+
25+
The <prunable-tools> list shows available tool outputs with numeric IDs:
26+
```
27+
<prunable-tools>
28+
1: read, src/foo.ts
29+
2: bash, run tests
30+
3: grep, "error" in logs/
31+
</prunable-tools>
32+
```
33+
34+
To prune outputs 1 and 3, call: `prune({ ids: [1, 3] })`
35+
36+
## When to Use This Tool
37+
38+
**Key heuristic: Distill, then prune when you finish something and are about to start something else.**
39+
40+
Ask yourself: "Have I just completed a discrete unit of work?" If yes, narrate your findings, then prune before moving on.
41+
42+
**After completing a unit of work:**
43+
- Made a commit
44+
- Fixed a bug and confirmed it works
45+
- Answered a question the user asked
46+
- Finished implementing a feature or function
47+
- Completed one item in a list and moving to the next
48+
49+
**After repetitive or exploratory work:**
50+
- Explored multiple files that didn't lead to changes
51+
- Iterated on a difficult problem where some approaches didn't pan out
52+
- Used the same tool multiple times (e.g., re-reading a file, running repeated build/type checks)
53+
54+
## Examples
55+
56+
<example>
57+
Working through a list of items:
58+
User: Review these 3 issues and fix the easy ones.
59+
Assistant: [Reviews first issue, makes fix, commits]
60+
Done with the first issue. Let me prune before moving to the next one.
61+
[Uses prune with ids: [1, 2, 3, 4] - the reads and edits from the first issue]
62+
</example>
63+
64+
<example>
65+
After exploring the codebase to understand it:
66+
Assistant: I've reviewed the relevant files. Let me prune the exploratory reads that aren't needed for the actual implementation.
67+
[Uses prune with ids: [1, 2, 5, 7] - the exploratory reads]
68+
</example>
69+
70+
<example>
71+
After completing any task:
72+
Assistant: [Finishes task - commit, answer, fix, etc.]
73+
Before we continue, let me prune the context from that work.
74+
[Uses prune with ids: [3, 4, 5, 6, 8, 9] - all tool outputs from the completed task]
75+
</example>

0 commit comments

Comments
 (0)