Skip to content

Commit b635b3c

Browse files
committed
Improve janitor prompt clarity and reduce redundancy
1 parent 93554d1 commit b635b3c

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

lib/prompt.ts

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
function minimizeMessages(messages: any[], alreadyPrunedIds?: string[], protectedToolCallIds?: string[]): any[] {
88
const prunedIdsSet = alreadyPrunedIds ? new Set(alreadyPrunedIds.map(id => id.toLowerCase())) : new Set()
99
const protectedIdsSet = protectedToolCallIds ? new Set(protectedToolCallIds.map(id => id.toLowerCase())) : new Set()
10-
10+
1111
return messages.map(msg => {
1212
const minimized: any = {
1313
role: msg.info?.role
@@ -25,33 +25,33 @@ function minimizeMessages(messages: any[], alreadyPrunedIds?: string[], protecte
2525
})
2626
.map((part: any) => {
2727
// For text parts, keep the text content (needed for user intent & retention requests)
28-
if (part.type === 'text') {
29-
// Filter out ignored messages (e.g., DCP summary UI messages)
30-
if (part.ignored) {
31-
return null
32-
}
33-
return {
34-
type: 'text',
35-
text: part.text
36-
}
37-
}
28+
if (part.type === 'text') {
29+
// Filter out ignored messages (e.g., DCP summary UI messages)
30+
if (part.ignored) {
31+
return null
32+
}
33+
return {
34+
type: 'text',
35+
text: part.text
36+
}
37+
}
3838

3939
// For tool parts, keep what's needed for pruning decisions
4040
if (part.type === 'tool') {
4141
const callIDLower = part.callID?.toLowerCase()
4242
const isAlreadyPruned = prunedIdsSet.has(callIDLower)
4343
const isProtected = protectedIdsSet.has(callIDLower)
44-
44+
4545
let displayCallID = part.callID
4646
if (isAlreadyPruned) {
4747
displayCallID = '<already-pruned>'
4848
} else if (isProtected) {
4949
displayCallID = '<protected>'
5050
}
51-
51+
5252
const toolPart: any = {
5353
type: 'tool',
54-
callID: displayCallID,
54+
toolCallID: displayCallID,
5555
tool: part.tool
5656
}
5757

@@ -99,13 +99,9 @@ function minimizeMessages(messages: any[], alreadyPrunedIds?: string[], protecte
9999
}
100100

101101
export function buildAnalysisPrompt(unprunedToolCallIds: string[], messages: any[], protectedTools: string[], alreadyPrunedIds?: string[], protectedToolCallIds?: string[]): string {
102-
const protectedToolsText = protectedTools.length > 0
103-
? `- NEVER prune tool calls from these protected tools: ${protectedTools.join(", ")}\n`
104-
: '';
105-
106102
// Minimize messages to reduce token usage, passing already-pruned and protected IDs for replacement
107103
const minimizedMessages = minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds)
108-
104+
109105
// Stringify with pretty-printing, then replace escaped newlines with actual newlines
110106
// This makes the logged prompts much more readable
111107
const messagesJson = JSON.stringify(minimizedMessages, null, 2).replace(/\\n/g, '\n')
@@ -120,29 +116,24 @@ Guidelines for identifying obsolete tool calls:
120116
3. Failed or incorrect tool attempts that were immediately corrected (e.g., reading a file from the wrong path, then reading from the correct path)
121117
122118
DO NOT prune:
123-
${protectedToolsText}
124-
- Tool calls that modified state (edits, writes, etc.)
125119
- Tool calls whose outputs are actively being discussed
126120
- Tool calls that produced errors still being debugged
127-
- Tool calls where the user explicitly indicated they want to retain the information (e.g., "save this", "remember this", "keep this for later", "don't output anything else but save this")
128121
- Tool calls that are the MOST RECENT activity in the conversation (these may be intended for future use)
129122
130123
IMPORTANT: Available tool call IDs for analysis: ${unprunedToolCallIds.join(", ")}
131124
132-
The session history below may contain tool calls with IDs not in the available list above. These are either:
133-
1. Protected tools (marked with callID "<protected>")
134-
2. Already-pruned tools (marked with callID "<already-pruned>")
125+
The session history below may contain tool calls with IDs not in the available list above, these cannot be pruned. These are either:
126+
1. Protected tools (marked with toolCallID "<protected>")
127+
2. Already-pruned tools (marked with toolCallID "<already-pruned>")
135128
136129
ONLY return IDs from the available list above.
137130
138-
Session history:
131+
Session history (each tool call has a "toolCallID" field):
139132
${messagesJson}
140133
141134
You MUST respond with valid JSON matching this exact schema:
142135
{
143136
"pruned_tool_call_ids": ["id1", "id2", ...],
144137
"reasoning": "explanation of why these IDs were selected"
145-
}
146-
147-
Return ONLY the tool call IDs from the available list above that should be pruned.`
138+
}`
148139
}

0 commit comments

Comments
 (0)