11import json
2+ import random
23import weakref
34from typing import Any , Dict , List
45from uuid import UUID
@@ -93,7 +94,9 @@ def add_system_messages(self) -> None:
9394 ):
9495 msg = dict (
9596 role = "user" ,
96- content = coder .fmt_system_prompt (coder .gpt_prompts .system_reminder ),
97+ content = self ._shuffle_reminders (
98+ coder .fmt_system_prompt (coder .gpt_prompts .system_reminder )
99+ ),
97100 )
98101 ConversationService .get_manager (coder ).add_message (
99102 message_dict = msg ,
@@ -103,6 +106,62 @@ def add_system_messages(self) -> None:
103106 mark_for_delete = 0 ,
104107 )
105108
109+ def add_randomized_cta (self ) -> None :
110+ coder = self .get_coder ()
111+ if not coder :
112+ return
113+
114+ message = random .choice (
115+ [
116+ "Given the above, please call any tools necessary to make progress on your task" ,
117+ (
118+ "Based on the information provided, please execute the appropriate tools to"
119+ " move the task forward."
120+ ),
121+ "With this context in mind, please proceed with your work." ,
122+ (
123+ "In light of the above, please utilize the required tools to continue with this"
124+ " request."
125+ ),
126+ (
127+ "Continue making progress. If you have reached the goal, summarize the results."
128+ " Otherwise, call the next necessary tool."
129+ ),
130+ (
131+ "Please use the proper tools to fulfill the next steps of this task based on"
132+ " the current data."
133+ ),
134+ (
135+ "You’ve got what you need, please invoke the right tools to keep making"
136+ " progress towards our goal."
137+ ),
138+ (
139+ "Considering what we've established, please use the available tools to complete"
140+ " the current objective."
141+ ),
142+ (
143+ "Given this information, please use the available tools to proceed with the"
144+ " assignment."
145+ ),
146+ "Please take the next logical steps to make headway on this task." ,
147+ ]
148+ )
149+
150+ msg = dict (
151+ role = "user" ,
152+ content = "\n \n " + message ,
153+ )
154+
155+ ConversationService .get_manager (coder ).add_message (
156+ message_dict = msg ,
157+ tag = MessageTag .REMINDER ,
158+ hash_key = ("main" , "randomized_cta" ),
159+ force = True ,
160+ mark_for_delete = 0 ,
161+ promotion = 2 * ConversationService .get_manager (coder ).DEFAULT_TAG_PROMOTION_VALUE ,
162+ mark_for_demotion = 1 ,
163+ )
164+
106165 def cleanup_files (self ) -> None :
107166 """
108167 Clean up ConversationFiles and remove corresponding messages from ConversationManager
@@ -903,6 +962,35 @@ def add_post_message_context_blocks(self) -> None:
903962 force = True ,
904963 )
905964
965+ def _shuffle_reminders (self , content : str ) -> str :
966+ """
967+ If the string is a critical_reminders block, shuffle all bulleted points
968+ to prevent the model from developing 'boilerplate blindness.'
969+ """
970+ if not content .strip ().startswith ('<context name="critical_reminders">' ):
971+ return content
972+
973+ lines = content .splitlines ()
974+
975+ # 1. Identify indices of lines starting with a hyphen (and the content itself)
976+ # We use strip() to handle indentation within the XML block
977+ list_info = [(i , line ) for i , line in enumerate (lines ) if line .strip ().startswith ("-" )]
978+
979+ if not list_info :
980+ return content
981+
982+ # 2. Extract and shuffle the list items
983+ indices = [item [0 ] for item in list_info ]
984+ bullet_contents = [item [1 ] for item in list_info ]
985+ random .shuffle (bullet_contents )
986+
987+ # 3. Reconstruct the block by placing shuffled items back into the original indices
988+ new_lines = list (lines )
989+ for index , shuffled_text in zip (indices , bullet_contents ):
990+ new_lines [index ] = shuffled_text
991+
992+ return "\n " .join (new_lines )
993+
906994 def debug_print_conversation_state (self ) -> None :
907995 """
908996 Print debug information about conversation state.
0 commit comments