@@ -40,31 +40,57 @@ public class DefaultPlanToHint implements PlanToHint {
4040
4141 private static final String HINT_PREFIX = "<system-hint>" ;
4242 private static final String HINT_SUFFIX = "</system-hint>" ;
43+ private static final String IMPORTANT_RULES_SEPARATOR = "Important Rules: \n " ;
44+
45+ private static final String RULE_WAIT_FOR_CONFIRMATION =
46+ "⚠️ CRITICAL - WAIT FOR USER CONFIRMATION:\n "
47+ + "You MUST NOT execute any subtask until the user explicitly confirms.\n "
48+ + "- DO NOT call 'update_subtask_state' to start execution\n "
49+ + "- DO NOT proceed with any task in the plan\n "
50+ + "- ONLY present the plan and ASK user: \" Should I proceed with this plan?\" \n "
51+ + "- Wait for explicit commands like: \" execute\" , \" go ahead\" , \" start\" ,"
52+ + " \" proceed\" , \" yes\" , \" ok\" , \" do it\" , \" run\" , \" begin\" \n "
53+ + "- If user says anything else (questions, modifications, unrelated topics),"
54+ + " respond accordingly but DO NOT start execution\n "
55+ + "- VIOLATION of this rule is a critical error\n " ;
56+
57+ private static final String RULE_COMMON =
58+ "- Update before processing each subtask: When processing each subtask, call"
59+ + " get_subtask_count and view_subtasks to confirm the latest information:"
60+ + " get_subtask_count is used to confirm the total number of subtasks to avoid"
61+ + " omissions;view_subtasks is used to query subtask information, execute subtasks"
62+ + " strictly according to the latest information, and pay attention to ignoring the"
63+ + " original request.\n "
64+ + "- User May Modify Plan: Users can directly add, edit, or delete subtasks without"
65+ + " going through you.\n "
66+ + "- Only focus on the current content: Always follow the latest plan content,"
67+ + " especially when the original plan conflicts with the latest queried plan,"
68+ + " follow the latest queried plan without considering the initial requirements.\n "
69+ + "- Do not modify plan: Do not modify or amend the plan without a clear plan"
70+ + " modification instruction from user\n " ;
4371
4472 private static final String NO_PLAN =
45- "If the user's query is complex (e.g. programming a website, game or "
46- + "app), or requires a long chain of steps to complete (e.g. conduct "
47- + "research on a certain topic from different sources), you NEED to "
48- + "create a plan first by calling 'create_plan'. Otherwise, you can "
49- + "directly execute the user's query without planning." ;
73+ "If the user's query is complex (e.g. programming a website, game or app), or requires "
74+ + " a long chain of steps to complete (e.g. conduct research on a certain topic "
75+ + " from different sources), you NEED to create a plan first by calling "
76+ + " 'create_plan'. Otherwise, you can directly execute the user's query without "
77+ + " planning.\n " ;
5078
5179 private static final String AT_THE_BEGINNING =
5280 "The current plan:\n "
53- + "```\n "
54- + "{plan}\n "
55- + "```\n "
56- + "Your options include:\n "
57- + "- Mark the first subtask as 'in_progress' by calling "
58- + "'update_subtask_state' with subtask_idx=0 and state='in_progress', "
59- + "and start executing it.\n "
60- + "- If the first subtask is not executable, analyze why and what you "
61- + "can do to advance the plan, e.g. ask user for more information, "
62- + "revise the plan by calling 'revise_current_plan'.\n "
63- + "- If the user asks you to do something unrelated to the plan, "
64- + "prioritize the completion of user's query first, and then return "
65- + "to the plan afterward.\n "
66- + "- If the user no longer wants to perform the current plan, confirm "
67- + "with the user and call the 'finish_plan' function.\n " ;
81+ + "```\n "
82+ + "{plan}\n "
83+ + "```\n "
84+ + "Your options include:\n "
85+ + "- Mark the first subtask as 'in_progress' by calling 'update_subtask_state' with"
86+ + " subtask_idx=0 and state='in_progress', and start executing it.\n "
87+ + "- If the first subtask is not executable, analyze why and what you can do to"
88+ + " advance the plan, e.g. ask user for more information, revise the plan by"
89+ + " calling 'revise_current_plan'.\n "
90+ + "- If the user asks you to do something unrelated to the plan, prioritize the"
91+ + " completion of user's query first, and then return to the plan afterward.\n "
92+ + "- If the user no longer wants to perform the current plan, confirm with the user"
93+ + " and call the 'finish_plan' function.\n " ;
6894
6995 private static final String WHEN_A_SUBTASK_IN_PROGRESS =
7096 "The current plan:\n "
@@ -84,7 +110,7 @@ public class DefaultPlanToHint implements PlanToHint {
84110 + "- Revise the plan by calling 'revise_current_plan' if necessary.\n "
85111 + "- If the user asks you to do something unrelated to the plan, "
86112 + "prioritize the completion of user's query first, and then return to "
87- + "the plan afterward." ;
113+ + "the plan afterward.\n " ;
88114
89115 private static final String WHEN_NO_SUBTASK_IN_PROGRESS =
90116 "The current plan:\n "
@@ -99,7 +125,7 @@ public class DefaultPlanToHint implements PlanToHint {
99125 + "- Revise the plan by calling 'revise_current_plan' if necessary.\n "
100126 + "- If the user asks you to do something unrelated to the plan, "
101127 + "prioritize the completion of user's query first, and then return to "
102- + "the plan afterward." ;
128+ + "the plan afterward.\n " ;
103129
104130 private static final String AT_THE_END =
105131 "The current plan:\n "
@@ -112,7 +138,7 @@ public class DefaultPlanToHint implements PlanToHint {
112138 + "- Revise the plan by calling 'revise_current_plan' if necessary.\n "
113139 + "- If the user asks you to do something unrelated to the plan, "
114140 + "prioritize the completion of user's query first, and then return to "
115- + "the plan afterward." ;
141+ + "the plan afterward.\n " ;
116142
117143 /**
118144 * Generates a contextual hint message based on the current plan state.
@@ -128,15 +154,20 @@ public class DefaultPlanToHint implements PlanToHint {
128154 * </ul>
129155 *
130156 * @param plan The current plan, or null if no plan exists
157+ * @param needUserConfirm Whether to include the "wait for user confirmation" rule in hints
131158 * @return A formatted hint message wrapped in system-hint tags, or null if no hint is
132159 * applicable
133160 */
134161 @ Override
135- public String generateHint (Plan plan ) {
162+ public String generateHint (Plan plan , boolean needUserConfirm ) {
136163 String hint ;
164+ String confirmationRule = needUserConfirm ? RULE_WAIT_FOR_CONFIRMATION : "" ;
137165
138166 if (plan == null ) {
139- hint = NO_PLAN ;
167+ hint =
168+ needUserConfirm
169+ ? NO_PLAN + IMPORTANT_RULES_SEPARATOR + confirmationRule
170+ : NO_PLAN ;
140171 } else {
141172 // Count subtasks by state
142173 int nTodo = 0 ;
@@ -166,7 +197,11 @@ public String generateHint(Plan plan) {
166197
167198 } else if (nInProgress == 0 && nDone == 0 ) {
168199 // All subtasks are todo - at the beginning
169- hint = AT_THE_BEGINNING .replace ("{plan}" , plan .toMarkdown (false ));
200+ hint =
201+ AT_THE_BEGINNING .replace ("{plan}" , plan .toMarkdown (false ))
202+ + IMPORTANT_RULES_SEPARATOR
203+ + confirmationRule
204+ + RULE_COMMON ;
170205
171206 } else if (nInProgress > 0 && inProgressIdx != null ) {
172207 // One subtask is in_progress
@@ -177,17 +212,21 @@ public String generateHint(Plan plan) {
177212 }
178213 hint =
179214 WHEN_A_SUBTASK_IN_PROGRESS
180- .replace ("{plan}" , plan .toMarkdown (false ))
181- .replace ("{subtask_idx}" , String .valueOf (inProgressIdx ))
182- .replace ("{subtask_name}" , subtaskName )
183- .replace ("{subtask}" , inProgressSubtask .toMarkdown (true ));
215+ .replace ("{plan}" , plan .toMarkdown (false ))
216+ .replace ("{subtask_idx}" , String .valueOf (inProgressIdx ))
217+ .replace ("{subtask_name}" , subtaskName )
218+ .replace ("{subtask}" , inProgressSubtask .toMarkdown (true ))
219+ + IMPORTANT_RULES_SEPARATOR
220+ + RULE_COMMON ;
184221
185222 } else if (nInProgress == 0 && nDone > 0 ) {
186223 // No subtask is in_progress, and some subtasks are done
187224 hint =
188225 WHEN_NO_SUBTASK_IN_PROGRESS
189- .replace ("{plan}" , plan .toMarkdown (false ))
190- .replace ("{index}" , String .valueOf (nDone ));
226+ .replace ("{plan}" , plan .toMarkdown (false ))
227+ .replace ("{index}" , String .valueOf (nDone ))
228+ + IMPORTANT_RULES_SEPARATOR
229+ + RULE_COMMON ;
191230
192231 } else {
193232 // No relevant hint for this state
0 commit comments