You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLPlanExecuteAndReflectAgentRunner.java
"In this environment, the executor agent only has access to the below tools. You must choose from only the following tools — no other tools are available. Do not use tools not listed here.\n"
613
+
"In this environment, you have access to the tools listed below. Use these tools to create your plan, and do not reference or use any tools not listed here.\n"
614
614
);
615
615
inttoolNumber = 0;
616
616
for (Map.Entry<String, Tool> entry : tools.entrySet()) {
+ "You have currently executed the following steps: \n[${parameters."
64
64
+ COMPLETED_STEPS_FIELD
65
-
+ "}] \n\n";
65
+
+ "}] \n\nRemember: Respond only in JSON format following the required schema.";
66
66
67
-
// modify these -- ensure that it breaks down steps simpler
68
67
publicstaticfinalStringDEFAULT_PLANNER_PROMPT =
69
-
"For the given objective, generate a step-by-step plan composed of simple, self-contained tasks. The final step should directly yield the final answer. Avoid unnecessary steps.";
68
+
"For the given objective, generate a step-by-step plan composed of simple, self-contained steps. The final step should directly yield the final answer. Avoid unnecessary steps.";
70
69
71
-
// modify these -- update your plan based on completed steps
72
70
publicstaticfinalStringDEFAULT_REFLECT_PROMPT =
73
-
"Update your plan based on the latest results. If the task is complete, return the final answer. Otherwise, include only the remaining steps — do not repeat previously completed ones.";
71
+
"Update your plan based on the latest step results. If the task is complete, return the final answer. Otherwise, include only the remaining steps. Do not repeat previously completed steps.";
When you deliver your final result, include a comprehensive report. This report must:
78
-
79
-
1. List every analysis or step you performed.
80
-
2. Summarize the inputs, methods, tools, and data used at each step.
81
-
3. Include key findings from all intermediate steps — do NOT omit them.
82
-
4. Clearly explain how the steps led to your final conclusion. Only mention the completed steps.
83
-
5. Return the full analysis and conclusion in the 'result' field, even if some of this was mentioned earlier.
84
-
85
-
The final response should be fully self-contained and detailed, allowing a user to understand the full investigation without needing to reference prior messages and steps.
75
+
When you deliver your final result, include a comprehensive report. This report must:
76
+
1. List every analysis or step you performed.
77
+
2. Summarize the inputs, methods, tools, and data used at each step.
78
+
3. Include key findings from all intermediate steps — do NOT omit them.
79
+
4. Clearly explain how the steps led to your final conclusion. Only mention the completed steps.
80
+
5. Return the full analysis and conclusion in the 'result' field, even if some of this was mentioned earlier. Ensure that special characters are escaped in the 'result' field.
81
+
6. The final response should be fully self-contained and detailed, allowing a user to understand the full investigation without needing to reference prior messages and steps.
+ "Use \"steps\" to return an array of strings where each string is a step to complete the objective, leave it empty if you know the final result. Please wrap each step in quotes and escape any special characters within the string. \n"
96
-
+ "Use \"result\" return the final response when you have enough information, leave it empty if you want to execute more steps \n"
92
+
+ "Use \"result\" return the final response when you have enough information, leave it empty if you want to execute more steps. Please escape any special characters within the result.\n"
97
93
+ "Here are examples of valid responses following the required JSON schema:\n\n"
98
94
+ "Example 1 - When you need to execute steps:\n"
99
95
+ "{\n"
@@ -103,7 +99,7 @@ public class PromptTemplate {
103
99
+ "Example 2 - When you have the final result:\n"
104
100
+ "{\n"
105
101
+ "\t\"steps\": [],\n"
106
-
+ "\t\"result\": \"This is an example result\"\n"
102
+
+ "\t\"result\": \"This is an example result\\n with escaped special characters\"\n"
107
103
+ "}\n"
108
104
+ "Important rules for the response:\n"
109
105
+ "1. Do not use commas within individual steps \n"
@@ -112,67 +108,36 @@ public class PromptTemplate {
112
108
113
109
publicstaticfinalStringPLANNER_RESPONSIBILITY =
114
110
"""
115
-
You are a thoughtful and analytical agent working as the `Planner & Reflector Agent` in a Plan–Execute–Reflect framework. You collaborate with a separate `Executor Agent`, whose sole responsibility is to carry out specific Steps that you generate.
116
-
117
-
## Core Responsibilities
118
-
- Receive a high-level objective or user goal and generate a clear, ordered sequence of simple executable Steps to complete the objective
119
-
- Ensure each Step is self-contained, meaning it can be executed without any prior context
120
-
- Each Step must specify exactly what to do, where to do it, and with which tools or parameters — avoid abstract instructions like “for each index” or “try something”
121
-
- If a partially completed plan and its execution results are provided, update the plan accordingly:
122
-
- Only include new Steps that still need to be executed
123
-
- Do not repeat previously completed Steps unless their output is outdated, missing, or clearly insufficient
124
-
- Use results from completed steps to avoid redundant or unnecessary follow-up actions
125
-
- If the task is already complete, return the final answer instead of a new plan
126
-
- If the available information is sufficient to provide a useful or partial answer, do so — do not over-plan or run unnecessary steps
127
-
- Use only the tools provided to construct your plan. You will be provided a list of available tools for each objective. Use only these tools in your plan — do not invent new tool names, do not guess what tools might exist, and do not reference tools not explicitly listed. If no suitable tool is available, plan using reasoning or observations instead.
128
-
- Always respond in JSON format
129
-
130
-
## Step Guidelines
131
-
- Each Step must be simple, atomic, and concrete — suitable for execution by a separate agent
132
-
- Avoid ambiguity: Steps should clearly define the **specific data sources, indexes, services, or parameters** to use
133
-
- Do not include generic instructions that require iteration or interpretation (e.g., “for all indexes” or “check relevant logs”)
134
-
- Do not add any superfluous steps — the result of the final step should directly answer the objective
135
-
136
-
### Bad Step Example: "Use the SearchIndexTool to sample documents from each index"
137
-
138
-
### Good Step Example: "Use the SearchIndexTool to sample documents for the index: index-name"
139
-
140
-
## Structural Expectations
141
-
- Track what Steps you generate and why
142
-
- Specify what tool or method each Step will likely require
143
-
- Use execution results to guide re-planning or task completion decisions
144
-
- Reuse prior results — do not re-fetch documents or metadata if they have already been retrieved
145
-
- If further progress is unlikely based on tool limitations or available data, stop and return the best possible result to the user
146
-
- Never rely on implicit knowledge, do not make make assumptions
147
-
148
-
Your goal is to produce a clean, efficient, and logically sound plan — or to adapt an existing one — to help the Executor Agent make steady progress toward the final answer. If no further progress can reasonably be made, summarize what has been learned and end the investigation.
111
+
You are a thoughtful and analytical planner agent in a plan-execute-reflect framework. Your job is to design a clear, step-by-step plan for a given objective.
112
+
113
+
Instructions:
114
+
- Break the objective into an ordered list of atomic, self-contained Steps that, if executed, will lead to the final result or complete the objective.
115
+
- Each Step must state what to do, where, and which tool/parameters would be used. You do not execute tools, only reference them for planning.
116
+
- Use only the provided tools; do not invent or assume tools. If no suitable tool applies, use reasoning or observations instead.
117
+
- Base your plan only on the data and information explicitly provided; do not rely on unstated knowledge or external facts.
118
+
- If there is insufficient information to create a complete plan, summarize what is known so far and clearly state what additional information is required to proceed.
119
+
- Stop and summarize if the task is complete or further progress is unlikely.
120
+
- Avoid vague instructions; be specific about data sources, indexes, or parameters.
121
+
- Never make assumptions or rely on implicit knowledge.
122
+
- Respond only in JSON format.
123
+
124
+
Step examples:
125
+
Good example: \"Use Tool to sample documents from index: 'my-index'\"
126
+
Bad example: \"Use Tool to sample documents from each index\"
127
+
Bad example: \"Use Tool to sample documents from all indices\"
149
128
""";
150
129
151
-
// ask it to break down a large step into a smaller step
152
130
publicstaticfinalStringEXECUTOR_RESPONSIBILITY =
153
131
"""
154
-
You are a dedicated helper agent working as the `Executor Agent` in a Plan–Execute–Reflect framework. In this setup, a separate `Planner & Reflector Agent` both creates an ordered list of discrete Steps and, after seeing your execution outputs, re-plans or refines those Steps as needed.
155
-
156
-
Your sole responsibility is to execute whatever Step you receive.
157
-
158
-
## Core Responsibilities
159
-
- Receive a discrete Step and execute it completely
160
-
- Run all necessary internal reasoning or tool calls
161
-
- Return a single, consolidated response that fully addresses that Step
162
-
- If previous context can help you answer the Step, reuse that information instead of calling tools again
163
-
164
-
## Critical Requirements
165
-
- You must never return an empty response
166
-
- Never end your reply with questions or requests for more information
167
-
- If you search any index, always include the full raw documents in your output. Do not summarize—so that every piece of retrieved evidence remains visible. This is critical for the `Planner & Reflector Agent` to decide the next step.
168
-
- If you cannot complete the Step, provide a clear explanation of what went wrong or what information was missing
169
-
- Never rely on implicit knowledge, do not make make assumptions
170
-
171
-
## Efficiency Guidelines
172
-
- Reuse previous context when applicable, stating what you're reusing and why
173
-
- Use the most direct approach first
174
-
- If a tool call fails, try alternative approaches before declaring failure
175
-
- If a search request is complex, break it down into multiple simple search queries
176
-
177
-
Your response must be complete and actionable as-is.""";
132
+
You are a precise and reliable executor agent in a plan-execute-reflect framework. Your job is to execute the given instruction provided by the planner and return a complete, actionable result.
133
+
134
+
Instructions:
135
+
- Fully execute the given Step using the most relevant tools or reasoning.
136
+
- Include all relevant raw tool outputs (e.g., full documents from searches) so the planner has complete information; do not summarize unless explicitly instructed.
137
+
- Base your execution and conclusions only on the data and tool outputs available; do not rely on unstated knowledge or external facts.
138
+
- If the available data is insufficient to complete the Step, summarize what was obtained so far and clearly state the additional information or access required to proceed (do not guess).
139
+
- If unable to complete the Step, clearly explain what went wrong and what is needed to proceed.
140
+
- Avoid making assumptions and relying on implicit knowledge.
141
+
- Your response must be self-contained and ready for the planner to use without modification. Never end with a question.
142
+
- Break complex searches into simpler queries when appropriate.""";
Copy file name to clipboardExpand all lines: ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/agent/MLPlanExecuteAndReflectAgentRunnerTest.java
+14-4Lines changed: 14 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -237,7 +237,7 @@ public void testBasicExecution() {
"In this environment, the executor agent only has access to the below tools. You must choose from only the following tools — no other tools are available. Do not use tools not listed here.\n"
578
+
"In this environment, you have access to the tools listed below. Use these tools to create your plan, and do not reference or use any tools not listed here.\n"
579
579
+ "Tool 1 - tool1: description1\n"
580
580
+ "\n"
581
-
+ "No other tools are available. Do not invent tools.\n\n",
581
+
+ "No other tools are available. Do not invent tools. Only use tools to create the plan.\n"
0 commit comments