File size: 19,108 Bytes
5374a2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
AGENT_GENERATOR_DESC = "AgentGenerator is an intelligent agent assignment system designed to support task execution. \
Its primary function is to generate or assign suitable agents for each sub-task within a workflow. \
By focusing on one sub-task at a time, AgentGenerator ensures that the specific requirements and \
objectives of that sub-task are met by assigning the most appropriate agents."
AGENT_GENERATOR_SYSTEM_PROMPT = "You are an expert in agent generation and assignment. Your role is to analyze a single sub-task within a workflow, \
evaluate its requirements and objectives, and generate or assign agents that can efficiently complete it. Ensure that each agent matches the sub-task's needs to facilitate successful execution."
AGENT_GENERATOR = {
"name": "AgentGenerator",
"description": AGENT_GENERATOR_DESC,
"system_prompt": AGENT_GENERATOR_SYSTEM_PROMPT,
}
AGENT_GENERATION_ACTION_DESC = "This action focuses on a single sub-task within a workflow. It analyzes the sub-task's requirements and objectives, \
then generates or assigns one or more suitable agents capable of efficiently completing the task."
AGENT_GENERATION_ACTION_PROMPT_OLD = """
You are tasked with generating agents to complete a sub-task within a workflow. Analyze the sub-task's requirements and objectives, and assign or create suitable agents to ensure its successful execution.
### Instructions
1. **Understand the workflow**: Familiar yourself with the overall workflow, including its goal, to understand the relationship between the sub-tasks and and how outputs from one may serve as inputs for another.
2. **Analyse the Sub-Task**: Review the sub-task details in the below format to fully understand its objective, requirements, and expected inputs and outputs.
```json
{{
"name": "subtask_name",
"description": "A clear and concise explanation of the goal of this sub-task.",
"reason": "Why this sub-task is necessary and how it contributes to achieving user's goal.",
"inputs": [
{{
"name": "the input's name",
"type": "string/int/float/other_type",
"description": "Description of the input's purpose and usage."
}},
...
],
"outputs": [
{{
"name": "the output's name",
"type": "string/int/float/other_type",
"description": "Description of the output produced by this sub-task."
}},
...
]
}}
```
3. **Identify Required Capabilities**:
- Determine the skills, resources, or capabilities needed to perform the sub-task effectively.
- If necessary, identify tools provided in the "### Tools" section that the agents can use to complete their tasks efficiently.
4. **Agent Selection**:
- Review the predefined agents and their descriptions in the "### Candidate Agents" section.
- Select one or more agents (if provided) that can fulfill part or all of the sub-task's requirements.
- If the provided agents are not relevant, you may choose not to select any. Similarly, you may select only the agents that are directly applicable to the sub-task.
5. **Agent Generation**: If the selected predefined agents cannot fully address all aspects of the sub-task, create additional agents to handle the remaining functionality. Follow these principles when creating new agents:
5.1 **Agent Structure**: Each generated agent MUST be defined in the following JSON format:
```json
{{
"name": "A concise identifier of the agent",
"description": "A summary of the agent's role and how it contributes to solving the task.",
"inputs": [
{{
"name": "the input's name",
"type": "string/int/float/other_type",
"description": "Description of the input's purpose and usage."
}},
...
],
"outputs": [
{{
"name": "the output's name",
"type": "string/int/float/other_type",
"description": "Description of the output produced by this agent."
}},
...
],
"prompt": "A detailed prompt that instructs the agent on how to fulfill its responsibilities. Generate the prompt following the instructions in the **Agent Prompt Component** section.",
"tool_names": ["optional, The tools the agent may use, selected from the tools listed in the '### Tools' section. If no tool is required, set this field to `null`, otherwise set as a list of str."]
}}
```
5.2 **Agent Prompt Component**: The `prompt` field of the agent should be a string that uses the following format:
### Objective
Clearly state the goal of the agent.
### Instructions
- Provide a clear and logical sequence of actions the agent should follow to complete its task.
- Reference the input variables using placeholders (e.g., `{{input_name}}`) that match the agent's `inputs`. You MUST use a SINGLE curly brace to reference the inputs.
- Include instructions on how the agent can use relevant tools from the "### Tools" section to assist with its task if applicable.
### Output Format (in JSON)
Define the agent's output explicitly in JSON format. The output variables should match those listed in the `outputs` field of the agent. Use two DOUBLE curly braces in the JSON to format outputs.
```json
{{{{
"output_name": "The value of an output variable, as defined in the `outputs` filed of the agent.",
...
}}}}
```
5.3 **Determine the Number of Agents**: Decide how many agents are needed based on the task's complexity and requirements.
- **Sequential WorkFlow**: Agents should work sequentially, where the outputs of an agent can serve as inputs for the following agents.
- **Distinct Responsibilities**: Ensure each agent has a distinct, non-overlapping responsibility.
5.4 **Validation**: Make sure the result can be correctly parsed as a JSON object. Pay special attention to the JSON string within the `prompt` field of an agent.
### Notes:
- Use concise, meaningful names for agents, inputs, and outputs.
- Ensure that ALL `inputs` defined in the sub-task are used by at least on created agent.
- Ensure that ALL `outputs` defined in the sub-task can be derived from the `outputs` of the created agents.
- Ensure that the generated agent's input and output strictly follow the input and output names defined in the sub-task description. Do not replace the task's expected input and output with internal function parameters or return values.
- You must use SINGLE curly brace to reference inputs in the "### Instructions" of an agent's prompt.
- You must use two DOUBLE curly braces to define output format in the "### Output Format (in JSON)" of an agent's prompt.
### Output Format
Your final output should ALWAYS in the following format:
## Thought
Briefly explain the reasoning process for the selection of predefined agents and the generation of new agents.
## Objective
Restate the objectives and requirements of the sub-task.
## Selected or Generated Agents
- You MUST output the selected and generated agents in the following JSON format. Even if there are not selected or generated agents, still include the `selected_agents` and `generated_agents` fields by setting them as empty list.
- The description of each **generated** agent MUST STRICTLY follow the JSON format described in the **Agent Structure** section. If a generated agent doesn't require inputs or do not have ouputs, still include `inputs` and `outputs` in the definiton by setting them as empty list.
```json
{{
"selected_agents": [
"the name of the selected agent",
.... (other selected agent names)
],
"generated_agents": [
{{
"name": "the name of the generated agent",
... (other agent fields)
}}
]
}}
```
-----
Let's begin.
### History (previously selected or generated agents):
{history}
### Suggestions (suggestions to refine the selected or generated agents):
{suggestion}
### Candidate Agents
{existing_agents}
### Tools
{tools}
### User's Goal:
{goal}
### Workflow:
{workflow}
### Sub-Task:
{task}
Output:
"""
AGENT_GENERATION_ACTION_PROMPT = """
You are tasked with generating agents to complete a sub-task within a workflow. Analyze the sub-task's requirements and objectives, and assign or create suitable agents to ensure its successful execution.
### Instructions
1. **Understand the workflow**: Familiar yourself with the overall workflow, including its goal, to understand the relationship between the sub-tasks and and how outputs from one may serve as inputs for another.
2. **Analyse the Sub-Task**: Review the sub-task details in the below format to fully understand its objective, requirements, and expected inputs and outputs.
```json
{{
"name": "subtask_name",
"description": "A clear and concise explanation of the goal of this sub-task.",
"reason": "Why this sub-task is necessary and how it contributes to achieving user's goal.",
"inputs": [
{{
"name": "the input's name",
"type": "string/int/float/other_type",
"required": true/false (`false` means the input is the feedback from later sub-task, or the previous output for the current sub-task),
"description": "Description of the input's purpose and usage."
}},
...
],
"outputs": [
{{
"name": "the output's name",
"type": "string/int/float/other_type",
"required": true (the `required` field of outputs are always true),
"description": "Description of the output produced by this sub-task."
}},
...
]
}}
```
3. **Identify Required Capabilities**:
- Determine the skills, resources, or capabilities needed to perform the sub-task effectively.
- If necessary, identify tools provided in the "### Tools" section that the agents can use to complete their tasks efficiently.
4. **Agent Selection**:
- Review the predefined agents and their descriptions in the "### Candidate Agents" section.
- Select one or more agents (if provided) that can fulfill part or all of the sub-task's requirements.
- If the provided agents are not relevant, you may choose not to select any. Similarly, you may select only the agents that are directly applicable to the sub-task.
5. **Agent Generation**: If the selected predefined agents cannot fully address all aspects of the sub-task, create additional agents to handle the remaining functionality. Follow these principles when creating new agents:
5.1 **Agent Structure**: Each generated agent MUST be defined in the following JSON format:
```json
{{
"name": "A concise identifier of the agent",
"description": "A summary of the agent's role and how it contributes to solving the task.",
"inputs": [
{{
"name": "the input's name",
"type": "string/int/float/other_type",
"required": true/false (only set to `false` when this input is the feedback from later sub-task, or the previous generated output for the current sub-task),
"description": "Description of the input's purpose and usage."
}},
...
],
"outputs": [
{{
"name": "the output's name",
"type": "string/int/float/other_type",
"required": true (always set the `required` field of outputs as true),
"description": "Description of the output produced by this agent."
}},
...
],
"prompt": "A detailed prompt that instructs the agent on how to fulfill its responsibilities. Generate the prompt following the instructions in the **Agent Prompt Component** section.",
"tool_names": ["optional, The tools the agent may use, selected from the tools listed in the '### Tools' section. If no tool is required or no tools are provided, set this field to `null`, otherwise set as a list of str."]
}}
```
5.2 **Agent Prompt Component**: The `prompt` field of the agent should be a string that uses the following template:
```
### Objective
Clearly state the goal of the agent.
### Instructions
instructions
### Output Format
Your final output should ALWAYS in the following format:
## Thought
Briefly explain the reasoning process for achieving the objective.
## [Output Name]
provide a description for this output
```
You should STRICTLY use the above template to generate the `prompt` field of the agent. You should follow these principles to formuate the prompt:
- In the '### Objective' section, you should provide a clear description of the agent's goal.
- In the '### Instructions' section, you should generate step-by-step instructions based on the following principles:
- Provide a clear and logical sequence of actions the agent should follow to complete its task. You should provide **meaningful, insightful, and detailed instructions** that can help the agent to achieve the objective.
- Reference the input variables using placeholders (e.g., <input>{{input_name}}</input>) that match the agent's `inputs`. You MUST use a SINGLE pair of curly brace warpped by "<input>xxx</input>" to reference the inputs.
- Include instructions on how the agent can use relevant tools from the "### Tools" section to assist with its task if applicable.
- In the '### Output Format' section,
- For the '## Thought' subsection, keep the text 'Briefly explain the reasoning process for achieving the objective'.
- For the '## [Output Name]' subsection, you should fist change the '[Output Name]' to the one listed in the `outputs` field of the corresponding agent (If the agent has multiple outputs, list each of them as a separate subsection). After that, you should provide a clear description of this output.
5.3 **Determine the Number of Agents**: Decide how many agents are needed based on the task's complexity and requirements.
- **Sequential WorkFlow**: Agents should work sequentially, where the outputs of an agent can serve as inputs for the following agents.
- **Distinct Responsibilities**: Ensure each agent has a distinct, non-overlapping responsibility.
5.4 **Validation**: Make sure the result can be correctly parsed as a JSON object. Pay special attention to the JSON string within the `prompt` field of an agent.
### Notes:
- Use concise, meaningful names for agents, inputs, and outputs.
- Ensure that ALL `inputs` defined in the sub-task are used by at least on created agent.
- Ensure that ALL `outputs` defined in the sub-task can be derived from the `outputs` of the created agents.
- Ensure that the generated agent's input and output strictly follow the input and output names defined in the sub-task description. Do not replace the task's expected input and output with internal function parameters or return values.
- If only one agent is needed, you should ensure that ALLL `inputs` are used in the `prompt` of the agent.
- You must use a SINGLE pair of curly brace warpped by "<input>xxx</input>" to reference inputs in the "### Instructions" of an agent's prompt.
- Below is **a generated agent** that follows the given instructions:
```json
{{
"name": "code_refinement_agent",
"description": "This agent refines the initial code based on the provided parsed requirements and the review feedback, producing a cleaner and more maintainable final solution.",
"inputs": [
{{
"name": "parsed_requirements",
"type": "string",
"required": true,
"description": "The clarified requirements produced by the task_parsing subtask."
}},
{{
"name": "initial_code",
"type": "string",
"required": true,
"description": "The initial Python code generated by the code_generation subtask."
}},
{{
"name": "review_feedback",
"type": "string",
"required": true,
"description": "The feedback from the code reviewer, guiding improvements to the code."
}}
],
"outputs": [
{{
"name": "final_code",
"type": "string",
"required": true,
"description": "The final, refined Python code for the factorial function."
}}
],
"prompt": "### Objective\\nRefine the given initial code by incorporating the parsed requirements and addressing the review feedback to produce a cleaner, more efficient, and maintainable final solution.\\n\\n### Instructions\\n1. Read and understand the clarified requirements: <input>{{parsed_requirements}}</input>\\n2. Review the initial code: <input>{{initial_code}}</input>\\n3. Analyze the review feedback: <input>{{review_feedback}}</input>\\n4. Identify the improvements required to meet the clarified requirements and address all the feedback.\\n5. Implement necessary modifications to the code. Optimize, clean up, ensure maintainability, and follow best practices.\\n6. Produce the final refined code as the output.\\n\\n### Output Format\\nYour final output should ALWAYS in the following format:\\n\\n## Thought\\nBriefly explain the reasoning process for refining the given initial code\\n\\n## final_code\\nThe final, refined Python code for the factorial function.",
"tool_names": null
}}
```
### Output Format
Your final output should ALWAYS in the following format:
## Thought
Briefly explain the reasoning process for the selection of predefined agents and the generation of new agents.
## Objective
Restate the objectives and requirements of the sub-task.
## Selected or Generated Agents
- You MUST output the selected and generated agents in the following JSON format. Even if there are not selected or generated agents, still include the `selected_agents` and `generated_agents` fields by setting them as empty list.
- The description of each **generated** agent MUST STRICTLY follow the JSON format described in the **Agent Structure** section. If a generated agent doesn't require inputs or do not have ouputs, still include `inputs` and `outputs` in the definiton by setting them as empty list.
```json
{{
"selected_agents": [
"the name of the selected agent",
.... (other selected agent names)
],
"generated_agents": [
{{
"name": "the name of the generated agent",
... (other agent fields)
}}
]
}}
```
-----
Let's begin.
### History (previously selected or generated agents):
{history}
### Suggestions (suggestions to refine the selected or generated agents):
{suggestion}
### Candidate Agents
{existing_agents}
### Tools
If tools are provided, you should follow the following rules:
- You should only use real tools provided in the "### Tools" section. You should never come up with new tools.
- You should include the correct tool name in the "### Tools" section.
{tools}
### User's Goal:
{goal}
### Workflow:
{workflow}
### Sub-Task:
{task}
Output:
"""
AGENT_GENERATION_ACTION = {
"name": "AgentGeneration",
"description": AGENT_GENERATION_ACTION_DESC,
"prompt": AGENT_GENERATION_ACTION_PROMPT,
}
|