@@ -16,25 +16,33 @@ export function resetToolTrackerCount(tracker: ToolTracker): void {
1616
1717/**
1818 * Track new tool results in OpenAI/Anthropic messages.
19- * Increments toolResultCount only for tools not already seen.
19+ * Increments toolResultCount only for tools not already seen and not protected .
2020 * Returns the number of NEW tools found (since last call).
2121 */
22- export function trackNewToolResults ( messages : any [ ] , tracker : ToolTracker ) : number {
22+ export function trackNewToolResults ( messages : any [ ] , tracker : ToolTracker , protectedTools : Set < string > ) : number {
2323 let newCount = 0
2424 for ( const m of messages ) {
2525 if ( m . role === 'tool' && m . tool_call_id ) {
2626 if ( ! tracker . seenToolResultIds . has ( m . tool_call_id ) ) {
2727 tracker . seenToolResultIds . add ( m . tool_call_id )
28- tracker . toolResultCount ++
29- newCount ++
28+ // Skip protected tools for nudge frequency counting
29+ const toolName = tracker . getToolName ?.( m . tool_call_id )
30+ if ( ! toolName || ! protectedTools . has ( toolName ) ) {
31+ tracker . toolResultCount ++
32+ newCount ++
33+ }
3034 }
3135 } else if ( m . role === 'user' && Array . isArray ( m . content ) ) {
3236 for ( const part of m . content ) {
3337 if ( part . type === 'tool_result' && part . tool_use_id ) {
3438 if ( ! tracker . seenToolResultIds . has ( part . tool_use_id ) ) {
3539 tracker . seenToolResultIds . add ( part . tool_use_id )
36- tracker . toolResultCount ++
37- newCount ++
40+ // Skip protected tools for nudge frequency counting
41+ const toolName = tracker . getToolName ?.( part . tool_use_id )
42+ if ( ! toolName || ! protectedTools . has ( toolName ) ) {
43+ tracker . toolResultCount ++
44+ newCount ++
45+ }
3846 }
3947 }
4048 }
@@ -48,7 +56,7 @@ export function trackNewToolResults(messages: any[], tracker: ToolTracker): numb
4856 * Uses position-based tracking since Gemini doesn't have tool call IDs.
4957 * Returns the number of NEW tools found (since last call).
5058 */
51- export function trackNewToolResultsGemini ( contents : any [ ] , tracker : ToolTracker ) : number {
59+ export function trackNewToolResultsGemini ( contents : any [ ] , tracker : ToolTracker , protectedTools : Set < string > ) : number {
5260 let newCount = 0
5361 let positionCounter = 0
5462 for ( const content of contents ) {
@@ -60,8 +68,12 @@ export function trackNewToolResultsGemini(contents: any[], tracker: ToolTracker)
6068 positionCounter ++
6169 if ( ! tracker . seenToolResultIds . has ( positionId ) ) {
6270 tracker . seenToolResultIds . add ( positionId )
63- tracker . toolResultCount ++
64- newCount ++
71+ // Skip protected tools for nudge frequency counting
72+ const toolName = part . functionResponse . name
73+ if ( ! toolName || ! protectedTools . has ( toolName ) ) {
74+ tracker . toolResultCount ++
75+ newCount ++
76+ }
6577 }
6678 }
6779 }
@@ -73,14 +85,18 @@ export function trackNewToolResultsGemini(contents: any[], tracker: ToolTracker)
7385 * Track new tool results in OpenAI Responses API input.
7486 * Returns the number of NEW tools found (since last call).
7587 */
76- export function trackNewToolResultsResponses ( input : any [ ] , tracker : ToolTracker ) : number {
88+ export function trackNewToolResultsResponses ( input : any [ ] , tracker : ToolTracker , protectedTools : Set < string > ) : number {
7789 let newCount = 0
7890 for ( const item of input ) {
7991 if ( item . type === 'function_call_output' && item . call_id ) {
8092 if ( ! tracker . seenToolResultIds . has ( item . call_id ) ) {
8193 tracker . seenToolResultIds . add ( item . call_id )
82- tracker . toolResultCount ++
83- newCount ++
94+ // Skip protected tools for nudge frequency counting
95+ const toolName = tracker . getToolName ?.( item . call_id )
96+ if ( ! toolName || ! protectedTools . has ( toolName ) ) {
97+ tracker . toolResultCount ++
98+ newCount ++
99+ }
84100 }
85101 }
86102 }
0 commit comments