File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed
Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff 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 } ,
You can’t perform that action at this time.
0 commit comments