@@ -955,26 +955,36 @@ impl ChatContext {
955955 // Errors from attempting to send too large of a conversation history. In
956956 // this case, attempt to automatically compact the history for the user.
957957 crate :: api_client:: ApiClientError :: ContextWindowOverflow => {
958- let history_too_small = self
959- . conversation_state
960- . backend_conversation_state ( false , true )
961- . await
962- . history
963- . len ( )
964- < 2 ;
965- if history_too_small {
966- print_err ! (
967- "Your conversation is too large - try reducing the size of
968- the context being passed" ,
969- err
970- ) ;
958+ if !self . conversation_state . can_create_summary_request ( ) . await {
959+ execute ! (
960+ self . output,
961+ style:: SetForegroundColor ( Color :: Red ) ,
962+ style:: Print ( "Your conversation is too large to continue.\n " ) ,
963+ style:: SetForegroundColor ( Color :: Reset ) ,
964+ style:: Print ( format!( "• Run {} to analyze your context usage\n " , "/usage" . green( ) ) ) ,
965+ style:: Print ( format!(
966+ "• Run {} to reset your conversation state\n " ,
967+ "/clear" . green( )
968+ ) ) ,
969+ style:: SetAttribute ( Attribute :: Reset ) ,
970+ style:: Print ( "\n \n " ) ,
971+ ) ?;
972+ self . conversation_state . reset_next_user_message ( ) ;
971973 return Ok ( ChatState :: PromptUser {
972974 tool_uses : None ,
973975 pending_tool_index : None ,
974976 skip_printing_tools : false ,
975977 } ) ;
976978 }
977979
980+ execute ! (
981+ self . output,
982+ style:: SetForegroundColor ( Color :: Yellow ) ,
983+ style:: Print ( "The context window has overflowed, summarizing the history..." ) ,
984+ style:: SetAttribute ( Attribute :: Reset ) ,
985+ style:: Print ( "\n \n " ) ,
986+ ) ?;
987+
978988 return Ok ( ChatState :: CompactHistory {
979989 tool_uses : None ,
980990 pending_tool_index : None ,
@@ -1220,8 +1230,10 @@ impl ChatContext {
12201230 // Check token usage and display warnings if needed
12211231 if pending_tool_index. is_none ( ) {
12221232 // Only display warnings when not waiting for tool approval
1223- if let Err ( e) = self . display_char_warnings ( ) . await {
1224- warn ! ( "Failed to display character limit warnings: {}" , e) ;
1233+ if self . conversation_state . can_create_summary_request ( ) . await {
1234+ if let Err ( e) = self . display_char_warnings ( ) . await {
1235+ warn ! ( "Failed to display character limit warnings: {}" , e) ;
1236+ }
12251237 }
12261238 }
12271239
0 commit comments