@@ -191,8 +191,6 @@ import {
191191 MAX_OVERALL_CHARACTERS ,
192192 FSREAD_MEMORY_BANK_MAX_PER_FILE ,
193193 FSREAD_MEMORY_BANK_MAX_TOTAL ,
194- MID_LOOP_COMPACTION_HANDOFF_PROMPT ,
195- COMPACTION_PROMPT ,
196194} from './constants/constants'
197195import {
198196 AgenticChatError ,
@@ -948,11 +946,6 @@ export class AgenticChatController implements ChatHandlers {
948946
949947 const compactIds = session . getAllDeferredCompactMessageIds ( )
950948 await this . #invalidateCompactCommand( params . tabId , compactIds )
951- // Set compactionDeclined flag if there were pending compaction requests
952- // This prevents endless compaction warning loops when user declines compaction once
953- if ( compactIds . length > 0 ) {
954- session . compactionDeclined = true
955- }
956949 session . rejectAllDeferredToolExecutions ( new ToolApprovalException ( 'Command ignored: new prompt' , false ) )
957950 await this . #invalidateAllShellCommands( params . tabId , session )
958951
@@ -988,10 +981,6 @@ export class AgenticChatController implements ChatHandlers {
988981 session . abortRequest ( )
989982 const compactIds = session . getAllDeferredCompactMessageIds ( )
990983 await this . #invalidateCompactCommand( params . tabId , compactIds )
991- // Set compactionDeclined flag if there were pending compaction requests
992- if ( compactIds . length > 0 ) {
993- session . compactionDeclined = true
994- }
995984 void this . #invalidateAllShellCommands( params . tabId , session )
996985 session . rejectAllDeferredToolExecutions ( new CancellationError ( 'user' ) )
997986
@@ -1109,7 +1098,7 @@ export class AgenticChatController implements ChatHandlers {
11091098 }
11101099
11111100 // Result Handling - This happens only once
1112- const result = await this . #handleFinalResult(
1101+ return await this . #handleFinalResult(
11131102 finalResult ,
11141103 session ,
11151104 params . tabId ,
@@ -1118,13 +1107,6 @@ export class AgenticChatController implements ChatHandlers {
11181107 isNewConversation ,
11191108 chatResultStream
11201109 )
1121-
1122- // Reset compactionDeclined flag after successful completion
1123- if ( session . compactionDeclined ) {
1124- session . compactionDeclined = false
1125- }
1126-
1127- return result
11281110 } catch ( err ) {
11291111 // HACK: the chat-client needs to have a partial event with the associated messageId sent before it can accept the final result.
11301112 // Without this, the `working` indicator never goes away.
@@ -1196,29 +1178,25 @@ export class AgenticChatController implements ChatHandlers {
11961178 /**
11971179 * Prepares the initial request input for the chat prompt
11981180 */
1199- #getCompactionRequestInput( session : ChatSessionService , toolResults ?: any [ ] ) : ChatCommandInput {
1181+ #getCompactionRequestInput( session : ChatSessionService ) : ChatCommandInput {
12001182 this . #debug( 'Preparing compaction request input' )
12011183 // Get profileArn from the service manager if available
12021184 const profileArn = this . #serviceManager?. getActiveProfileArn ( )
12031185 const requestInput = this . #triggerContext. getCompactionChatCommandInput (
12041186 profileArn ,
12051187 this . #getTools( session ) ,
12061188 session . modelId ,
1207- this . #origin,
1208- toolResults
1189+ this . #origin
12091190 )
12101191 return requestInput
12111192 }
12121193
12131194 /**
12141195 * Runs the compaction, making requests and processing tool uses until completion
12151196 */
1216- #shouldCompact( currentRequestCount : number , session : ChatSessionService ) : boolean {
1217- const EFFECTIVE_COMPACTION_THRESHOLD = COMPACTION_CHARACTER_THRESHOLD - COMPACTION_PROMPT . length
1218- if ( currentRequestCount > EFFECTIVE_COMPACTION_THRESHOLD && ! session . compactionDeclined ) {
1219- this . #debug(
1220- `Current request total character count is: ${ currentRequestCount } , prompting user to compact (threshold: ${ EFFECTIVE_COMPACTION_THRESHOLD } )`
1221- )
1197+ #shouldCompact( currentRequestCount : number ) : boolean {
1198+ if ( currentRequestCount > COMPACTION_CHARACTER_THRESHOLD ) {
1199+ this . #debug( `Current request total character count is: ${ currentRequestCount } , prompting user to compact` )
12221200 return true
12231201 } else {
12241202 return false
@@ -1401,10 +1379,6 @@ export class AgenticChatController implements ChatHandlers {
14011379 let currentRequestCount = 0
14021380 const pinnedContext = additionalContext ?. filter ( item => item . pinned )
14031381
1404- // Store initial non-empty prompt for compaction handoff
1405- const initialPrompt =
1406- initialRequestInput . conversationState ?. currentMessage ?. userInputMessage ?. content ?. trim ( ) || ''
1407-
14081382 metric . recordStart ( )
14091383 this . logSystemInformation ( )
14101384 while ( true ) {
@@ -1469,63 +1443,6 @@ export class AgenticChatController implements ChatHandlers {
14691443 this . #llmRequestStartTime = Date . now ( )
14701444 // Phase 3: Request Execution
14711445 currentRequestInput = sanitizeRequestInput ( currentRequestInput )
1472-
1473- if ( this . #shouldCompact( currentRequestCount , session ) ) {
1474- this . #features. logging . info (
1475- `Entering mid-loop compaction at iteration ${ iterationCount } with ${ currentRequestCount } characters`
1476- )
1477- this . #telemetryController. emitMidLoopCompaction (
1478- currentRequestCount ,
1479- iterationCount ,
1480- this . #features. runtime . serverInfo . version ?? ''
1481- )
1482- const messageId = this . #getMessageIdForCompact( uuid ( ) )
1483- const confirmationResult = this . #processCompactConfirmation( messageId , currentRequestCount )
1484- const cachedButtonBlockId = await chatResultStream . writeResultBlock ( confirmationResult )
1485- await this . waitForCompactApproval ( messageId , chatResultStream , cachedButtonBlockId , session )
1486-
1487- // Run compaction
1488- const toolResults =
1489- currentRequestInput . conversationState ?. currentMessage ?. userInputMessage ?. userInputMessageContext
1490- ?. toolResults || [ ]
1491- const compactionRequestInput = this . #getCompactionRequestInput( session , toolResults )
1492- const compactionResult = await this . #runCompaction(
1493- compactionRequestInput ,
1494- session ,
1495- metric ,
1496- chatResultStream ,
1497- tabId ,
1498- promptId ,
1499- CompactHistoryActionType . Nudge ,
1500- session . conversationId ,
1501- token ,
1502- documentReference
1503- )
1504-
1505- if ( ! compactionResult . success ) {
1506- this . #features. logging . error ( `Compaction failed: ${ compactionResult . error } ` )
1507- return compactionResult
1508- }
1509-
1510- // Show compaction summary to user before continuing
1511- await chatResultStream . writeResultBlock ( {
1512- type : 'answer' ,
1513- body :
1514- ( compactionResult . data ?. chatResult . body || '' ) +
1515- '\n\nConversation history has been compacted successfully!' ,
1516- messageId : uuid ( ) ,
1517- } )
1518-
1519- currentRequestInput = this . #updateRequestInputWithToolResults(
1520- currentRequestInput ,
1521- [ ] ,
1522- MID_LOOP_COMPACTION_HANDOFF_PROMPT + initialPrompt
1523- )
1524- shouldDisplayMessage = false
1525- this . #features. logging . info ( `Completed mid-loop compaction, restarting loop with handoff prompt` )
1526- continue
1527- }
1528-
15291446 // Note: these logs are very noisy, but contain information redacted on the backend.
15301447 this . #debug(
15311448 `generateAssistantResponse/SendMessage Request: ${ JSON . stringify ( currentRequestInput , this . #imageReplacer, 2 ) } `
@@ -1754,7 +1671,7 @@ export class AgenticChatController implements ChatHandlers {
17541671 currentRequestInput = this . #updateRequestInputWithToolResults( currentRequestInput , toolResults , content )
17551672 }
17561673
1757- if ( this . #shouldCompact( currentRequestCount , session ) ) {
1674+ if ( this . #shouldCompact( currentRequestCount ) ) {
17581675 this . #telemetryController. emitCompactNudge (
17591676 currentRequestCount ,
17601677 this . #features. runtime . serverInfo . version ?? ''
0 commit comments