Skip to content

Commit a3e7ba2

Browse files
committed
context pruner: only 10% of context max for messages after pruning
1 parent 850ac21 commit a3e7ba2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

.agents/context-pruner.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ const definition: AgentDefinition = {
2929
handleSteps: function* ({ agentState, params }) {
3030
const messages = agentState.messageHistory
3131

32-
// Target: summarized messages should be at most 15% of max context
33-
const TARGET_SUMMARY_FACTOR = 0.15
32+
// Target: summarized messages should be at most 10% of max context
33+
const TARGET_SUMMARY_FACTOR = 0.1
3434

3535
// Limits for truncating long messages (chars)
36-
const USER_MESSAGE_LIMIT = 20000
37-
const ASSISTANT_MESSAGE_LIMIT = 5000
36+
const USER_MESSAGE_LIMIT = 15000
37+
const ASSISTANT_MESSAGE_LIMIT = 4000
3838

3939
// Prompt cache expiry time (Anthropic caches for 5 minutes)
4040
const CACHE_EXPIRY_MS = 5 * 60 * 1000
@@ -79,8 +79,8 @@ const definition: AgentDefinition = {
7979
// The USER_PROMPT is the actual user message; INSTRUCTIONS_PROMPT comes after it
8080
// We need to find the USER_PROMPT and check the gap between it and the last assistant message
8181
let cacheWillMiss = false
82-
const userPromptIndex = currentMessages.findLastIndex(
83-
(message) => message.tags?.includes('USER_PROMPT'),
82+
const userPromptIndex = currentMessages.findLastIndex((message) =>
83+
message.tags?.includes('USER_PROMPT'),
8484
)
8585
if (userPromptIndex > 0) {
8686
const userPromptMsg = currentMessages[userPromptIndex]
@@ -119,7 +119,8 @@ const definition: AgentDefinition = {
119119
(message) => message.tags?.includes('INSTRUCTIONS_PROMPT'),
120120
)
121121
if (lastRemainingInstructionsIndex !== -1) {
122-
instructionsPromptMessage = currentMessages[lastRemainingInstructionsIndex]
122+
instructionsPromptMessage =
123+
currentMessages[lastRemainingInstructionsIndex]
123124
currentMessages.splice(lastRemainingInstructionsIndex, 1)
124125
}
125126

@@ -167,7 +168,7 @@ const definition: AgentDefinition = {
167168
if (message.tags?.includes('INSTRUCTIONS_PROMPT')) return false
168169
if (message.tags?.includes('STEP_PROMPT')) return false
169170
if (message.tags?.includes('SUBAGENT_SPAWN')) return false
170-
171+
171172
// Exclude previous conversation summaries
172173
if (message.role === 'user' && Array.isArray(message.content)) {
173174
for (const part of message.content) {

0 commit comments

Comments
 (0)