privatestaticfinalStringNO_PLAN= "If the user's query is complex (e.g. programming a website, game or app), or requires" + " a long chain of steps to complete (e.g. conduct research on a certain topic" + " from different sources), you NEED to create a plan first by calling" + " 'create_plan'. Otherwise, you can directly execute the user's query without" + " planning.\n";
// translate the NO_PLAN to ZH_CN in following lines.
privatestaticfinalStringRULE_WAIT_FOR_CONFIRMATION= "⚠️ WAIT FOR USER CONFIRMATION:\n" + "- Present the plan and confirm with user before execution\n" + "- If user's request already implies execution intent (e.g., \"execute\"," + " \"execute the plan\"), proceed directly without asking\n" + "- Otherwise, ask: \"Should I proceed with this plan?\"\n" + "- Start execution only after user confirms (e.g., \"yes\", \"go ahead\"," + " \"proceed\", \"do it\")\n" + "- If user says anything else (questions, modifications, unrelated topics)," + " respond accordingly but DO NOT start execution\n";
// translate the RULE_WAIT_FOR_CONFIRMATION to ZH_CN in following lines.
// Count subtasks by state // 待办任务项 intnTodo=0; // 进行中的任务项 intnInProgress=0; // 已完成的任务项 intnDone=0; // 已放弃的任务项 intnAbandoned=0;
for (inti=0; i < plan.getSubtasks().size(); i++) { SubTasksubtask= plan.getSubtasks().get(i); switch (subtask.getState()) { case TODO -> nTodo++; case IN_PROGRESS -> { nInProgress++; inProgressIdx = i; } case DONE -> nDone++; case ABANDONED -> nAbandoned++; } }
// All subtasks are todo - at the beginning // 初始阶段,所有任务均在待办状态 hint = AT_THE_BEGINNING.replace("{plan}", plan.toMarkdown(false)) + IMPORTANT_RULES_SEPARATOR + confirmationRule + RULE_COMMON;
privatestaticfinalStringAT_THE_BEGINNING= "The current plan:\n" + "```\n" + "{plan}\n" + "```\n" + "Your options include:\n" + "- Mark the first subtask as 'in_progress' by calling 'update_subtask_state' with" + " subtask_idx=0 and state='in_progress', and start executing it.\n" + "- If the first subtask is not executable, analyze why and what you can do to" + " advance the plan, e.g. ask user for more information, revise the plan by" + " calling 'revise_current_plan'.\n" + "- If the user asks you to do something unrelated to the plan, prioritize the" + " completion of user's query first, and then return to the plan afterward.\n" + "- If the user no longer wants to perform the current plan, confirm with the user" + " and call the 'finish_plan' function.\n";
// translate the AT_THE_BEGINNING to ZH_CN in following lines.
privatestaticfinalStringWHEN_A_SUBTASK_IN_PROGRESS= "The current plan:\n" + "```\n" + "{plan}\n" + "```\n" + "Now the subtask at index {subtask_idx}, named '{subtask_name}', is " + "'in_progress'. Its details are as follows:\n" + "```\n" + "{subtask}\n" + "```\n" + "Your options include:\n" + "- Go on execute the subtask and get the outcome.\n" + "- Call 'finish_subtask' with the specific outcome if the subtask is " + "finished.\n" + "- Ask the user for more information if you need.\n" + "- Revise the plan by calling 'revise_current_plan' if necessary.\n" + "- If the user asks you to do something unrelated to the plan, " + "prioritize the completion of user's query first, and then return to " + "the plan afterward.\n";
// translate the WHEN_A_SUBTASK_IN_PROGRESS to ZH_CN in following lines.
privatestaticfinalStringWHEN_NO_SUBTASK_IN_PROGRESS= "The current plan:\n" + "```\n" + "{plan}\n" + "```\n" + "The first {index} subtasks are done, and there is no subtask " + "'in_progress'. Now Your options include:\n" + "- Mark the next subtask as 'in_progress' by calling " + "'update_subtask_state', and start executing it.\n" + "- Ask the user for more information if you need.\n" + "- Revise the plan by calling 'revise_current_plan' if necessary.\n" + "- If the user asks you to do something unrelated to the plan, " + "prioritize the completion of user's query first, and then return to " + "the plan afterward.\n";
// translate the WHEN_NO_SUBTASK_IN_PROGRESS to ZH_CN in following lines.
privatestaticfinalStringAT_THE_END= "The current plan:\n" + "```\n" + "{plan}\n" + "```\n" + "All the subtasks are done. Now your options are:\n" + "- Finish the plan by calling 'finish_plan' with the specific " + "outcome, and summarize the whole process and outcome to the user.\n" + "- Revise the plan by calling 'revise_current_plan' if necessary.\n" + "- If the user asks you to do something unrelated to the plan, " + "prioritize the completion of user's query first, and then return to " + "the plan afterward.\n";
// translate the AT_THE_END to ZH_CN in following lines.
privatestaticfinalStringRULE_COMMON= "- Update before processing each subtask: When processing each subtask, call" + " get_subtask_count and view_subtasks to confirm the latest information:" + " get_subtask_count is used to confirm the total number of subtasks to avoid" + " omissions;view_subtasks is used to query subtask information, execute subtasks" + " strictly according to the latest information, and pay attention to ignoring the" + " original request.\n" + "- User May Modify Plan: Users can directly add, edit, or delete subtasks without" + " going through you.\n" + "- Only focus on the current content: Always follow the latest plan content," + " especially when the original plan conflicts with the latest queried plan," + " follow the latest queried plan without considering the initial requirements.\n" + "- Do not modify plan: Do not modify or amend the plan without a clear plan" + " modification instruction from user\n" + "- Language consistency: Respond to users in the same language as the plan\n";
// translate the RULE_COMMON to ZH_CN in following lines.
/** * Storage interface for persisting and retrieving plans. * * <p>Implementations can store plans in memory, database, or any other persistent storage. */ publicinterfacePlanStorage {
/** * Add a plan to storage. * * @param plan The plan to store * @return Mono that completes when the plan is stored */ Mono<Void> addPlan(Plan plan);
/** * Get a plan by its ID. * * @param planId The plan ID * @return Mono emitting the plan, or empty if not found */ Mono<Plan> getPlan(String planId);
/** * Get all plans from storage. * * @return Mono emitting a list of all plans */ Mono<List<Plan>> getPlans(); }
/** * Load PlanNotebook state from the session. * * @param session the session to load state from * @param sessionKey the session identifier */ @Override publicvoidloadFrom(Session session, SessionKey sessionKey) { // Clear existing state first to avoid stale data this.currentPlan = null; session.get(sessionKey, keyPrefix + "_state", PlanNotebookState.class) .ifPresent(state -> this.currentPlan = state.currentPlan()); }
/** * Create a plan by given name and sub-tasks. * * @param name The plan name, should be concise, descriptive and not exceed 10 words * @param description The plan description, including the constraints, target and outcome * @param expectedOutcome The expected outcome of the plan * @param subtasks A list of sequential sub-tasks that make up the plan * @return Tool response message */
✨ Journey into the AI cosmos — where neural networks ignite curiosity, backend systems pulse with precision, and every line of code weaves the future. Dive in, explore, and transform.