Skip to content

Commit 4567b3b

Browse files
committed
context pruner: 1k token fudge factor
1 parent 654eb9b commit 4567b3b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

agents/context-pruner.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ const definition: AgentDefinition = {
312312
const SUMMARY_HEADER =
313313
'This is a summary of the conversation so far. The original messages have been condensed to save context space.'
314314

315+
/** Fudge factor for token count threshold to trigger pruning earlier */
316+
const TOKEN_COUNT_FUDGE_FACTOR = 1000
317+
315318
// =============================================================================
316319
// Helper Functions (must be inside handleSteps since it's serialized to a string)
317320
// =============================================================================
@@ -598,7 +601,7 @@ const definition: AgentDefinition = {
598601
// - Prune when context exceeds max, OR
599602
// - Prune when prompt cache will miss (>5 min gap) to take advantage of fresh context
600603
// If not, return messages with just the subagent-specific tags removed
601-
if (agentState.contextTokenCount <= maxContextLength && !cacheWillMiss) {
604+
if (agentState.contextTokenCount + TOKEN_COUNT_FUDGE_FACTOR <= maxContextLength && !cacheWillMiss) {
602605
yield {
603606
toolName: 'set_messages',
604607
input: { messages: currentMessages },

0 commit comments

Comments
 (0)