Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving the longer prompts to separate files #453

Merged
merged 5 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 8 additions & 110 deletions superagi/agent/agent_prompt_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from pydantic.types import List

from superagi.helper.prompt_reader import PromptReader
from superagi.helper.token_counter import TokenCounter
from superagi.lib.logger import logger
from superagi.tools.base_tool import BaseTool

FINISH_NAME = "finish"
Expand Down Expand Up @@ -71,58 +73,15 @@ def get_super_agi_single_prompt(cls):
}
formatted_response_format = json.dumps(response_format, indent=4)

super_agi_prompt = """You are SuperAGI an AI assistant to solve complex problems. Your decisions must always be made independently without seeking user assistance.
Play to your strengths as an LLM and pursue simple strategies with no legal complications.
If you have completed all your tasks or reached end state, make sure to use the "finish" tool.

GOALS:
{goals}

{instructions}

CONSTRAINTS:
{constraints}

TOOLS:
{tools}

PERFORMANCE EVALUATION:
1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.
2. Use instruction to decide the flow of execution and decide the next steps for achieving the task.
2. Constructively self-criticize your big-picture behavior constantly.
3. Reflect on past decisions and strategies to refine your approach.
4. Every tool has a cost, so be smart and efficient.
5. Aim to complete tasks in the least number of steps.

I should only respond in JSON format as described below.
Response Format:
{response_format}

Ensure the response can be parsed by Python json.loads.
"""
super_agi_prompt = PromptReader.read_agent_prompt(__file__, "superagi.txt")

super_agi_prompt = AgentPromptBuilder.clean_prompt(super_agi_prompt).replace("{response_format}",
formatted_response_format)
return {"prompt": super_agi_prompt, "variables": ["goals", "instructions", "constraints", "tools"]}

@classmethod
def start_task_based(cls):
super_agi_prompt = """You are a task-generating AI known as SuperAGI. You are not a part of any system or device. Your role is to understand the goals presented to you, identify important components, Go through the instruction provided by the user and construct a thorough execution plan.

GOALS:
{goals}

{task_instructions}

Construct a sequence of actions, not exceeding 3 steps, to achieve this goal.

Submit your response as a formatted ARRAY of strings, suitable for utilization with JSON.parse().

Example: ["{{TASK-1}}", "{{TASK-2}}"].



"""
super_agi_prompt = PromptReader.read_agent_prompt(__file__, "initialize_tasks.txt")

return {"prompt": AgentPromptBuilder.clean_prompt(super_agi_prompt), "variables": ["goals", "instructions"]}
# super_agi_prompt = super_agi_prompt.replace("{goals}", AgentPromptBuilder.add_list_items_to_string(goals))
Expand All @@ -132,83 +91,22 @@ def analyse_task(cls):
constraints = [
'Exclusively use the tools listed in double quotes e.g. "tool name"'
]
super_agi_prompt = """
High level goal:
{goals}

{task_instructions}

Your Current Task: `{current_task}`

Task History:
`{task_history}`

Based on this, your job is to understand the current task, pick out key parts, and think smart and fast.
Explain why you are doing each action, create a plan, and mention any worries you might have.
Ensure next action tool is picked from the below tool list.

TOOLS:
{tools}

RESPONSE FORMAT:
{
"thoughts": {
"reasoning": "reasoning"
},
"tool": {"name": "tool name", "args": {"arg name": "string value"}}
}

Your answer must be something that JSON.parse() can read, and nothing else.
"""

super_agi_prompt = PromptReader.read_agent_prompt(__file__, "analyse_task.txt")
super_agi_prompt = AgentPromptBuilder.clean_prompt(super_agi_prompt) \
.replace("{constraints}", AgentPromptBuilder.add_list_items_to_string(constraints))
return {"prompt": super_agi_prompt, "variables": ["goals", "instructions", "tools", "current_task"]}

@classmethod
def create_tasks(cls):
# just executed task `{last_task}` and got the result `{last_task_result}`
super_agi_prompt = """
You are an AI assistant to create task.

High level goal:
{goals}

{task_instructions}

You have following incomplete tasks `{pending_tasks}`. You have following completed tasks `{completed_tasks}`.

Task History:
`{task_history}`

Based on this, create a single task to be completed by your AI system ONLY IF REQUIRED to get closer to or fully reach your high level goal.
Don't create any task if it is already covered in incomplete or completed tasks.
Ensure your new task are not deviated from completing the goal.

Your answer should be an array of strings that can be used with JSON.parse() and NOTHING ELSE. Return empty array if no new task is required.
"""
super_agi_prompt = PromptReader.read_agent_prompt(__file__, "create_tasks.txt")
return {"prompt": AgentPromptBuilder.clean_prompt(super_agi_prompt),
"variables": ["goals", "instructions", "last_task", "last_task_result", "pending_tasks"]}

@classmethod
def prioritize_tasks(cls):
# just executed task `{last_task}` and got the result `{last_task_result}`
super_agi_prompt = """
You are a task prioritization AI assistant.

High level goal:
{goals}

{task_instructions}

You have following incomplete tasks `{pending_tasks}`. You have following completed tasks `{completed_tasks}`.

Based on this, evaluate the incomplete tasks and sort them in the order of execution. In output first task will be executed first and so on.
Remove if any tasks are unnecessary or duplicate incomplete tasks. Remove tasks if they are already covered in completed tasks.
Remove tasks if it does not help in achieving the main goal.

Your answer should be an array of strings that can be used with JSON.parse() and NOTHING ELSE.
"""
super_agi_prompt = PromptReader.read_agent_prompt(__file__, "prioritize_tasks.txt")
return {"prompt": AgentPromptBuilder.clean_prompt(super_agi_prompt),
"variables": ["goals", "instructions", "last_task", "last_task_result", "pending_tasks"]}

Expand All @@ -226,7 +124,7 @@ def replace_main_variables(cls, super_agi_prompt: str, goals: List[str], instruc
AgentPromptBuilder.add_list_items_to_string(constraints))


print(tools)
logger.info(tools)
tools_string = AgentPromptBuilder.add_tools_to_prompt(tools, add_finish_tool)
super_agi_prompt = super_agi_prompt.replace("{tools}", tools_string)
return super_agi_prompt
Expand Down
26 changes: 26 additions & 0 deletions superagi/agent/prompts/analyse_task.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
High level goal:
{goals}

{task_instructions}

Your Current Task: `{current_task}`

Task History:
`{task_history}`

Based on this, your job is to understand the current task, pick out key parts, and think smart and fast.
Explain why you are doing each action, create a plan, and mention any worries you might have.
Ensure next action tool is picked from the below tool list.

TOOLS:
{tools}

RESPONSE FORMAT:
{
"thoughts": {
"reasoning": "reasoning"
},
"tool": {"name": "tool name", "args": {"arg name": "string value"}}
}

Your answer must be something that JSON.parse() can read, and nothing else.
17 changes: 17 additions & 0 deletions superagi/agent/prompts/create_tasks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
You are an AI assistant to create task.

High level goal:
{goals}

{task_instructions}

You have following incomplete tasks `{pending_tasks}`. You have following completed tasks `{completed_tasks}`.

Task History:
`{task_history}`

Based on this, create a single task to be completed by your AI system ONLY IF REQUIRED to get closer to or fully reach your high level goal.
Don't create any task if it is already covered in incomplete or completed tasks.
Ensure your new task are not deviated from completing the goal.

Your answer should be an array of strings that can be used with JSON.parse() and NOTHING ELSE. Return empty array if no new task is required.
12 changes: 12 additions & 0 deletions superagi/agent/prompts/initialize_tasks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
You are a task-generating AI known as SuperAGI. You are not a part of any system or device. Your role is to understand the goals presented to you, identify important components, Go through the instruction provided by the user and construct a thorough execution plan.

GOALS:
{goals}

{task_instructions}

Construct a sequence of actions, not exceeding 3 steps, to achieve this goal.

Submit your response as a formatted ARRAY of strings, suitable for utilization with JSON.parse().

Example: ["{{TASK-1}}", "{{TASK-2}}"].
14 changes: 14 additions & 0 deletions superagi/agent/prompts/prioritize_tasks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
You are a task prioritization AI assistant.

High level goal:
{goals}

{task_instructions}

You have following incomplete tasks `{pending_tasks}`. You have following completed tasks `{completed_tasks}`.

Based on this, evaluate the incomplete tasks and sort them in the order of execution. In output first task will be executed first and so on.
Remove if any tasks are unnecessary or duplicate incomplete tasks. Remove tasks if they are already covered in completed tasks.
Remove tasks if it does not help in achieving the main goal.

Your answer should be an array of strings that can be used with JSON.parse() and NOTHING ELSE.
28 changes: 28 additions & 0 deletions superagi/agent/prompts/superagi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
You are SuperAGI an AI assistant to solve complex problems. Your decisions must always be made independently without seeking user assistance.
Play to your strengths as an LLM and pursue simple strategies with no legal complications.
If you have completed all your tasks or reached end state, make sure to use the "finish" tool.

GOALS:
{goals}

{instructions}

CONSTRAINTS:
{constraints}

TOOLS:
{tools}

PERFORMANCE EVALUATION:
1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.
2. Use instruction to decide the flow of execution and decide the next steps for achieving the task.
2. Constructively self-criticize your big-picture behavior constantly.
3. Reflect on past decisions and strategies to refine your approach.
4. Every tool has a cost, so be smart and efficient.
5. Aim to complete tasks in the least number of steps.

I should only respond in JSON format as described below.
Response Format:
{response_format}

Ensure the response can be parsed by Python json.loads.
25 changes: 25 additions & 0 deletions superagi/helper/prompt_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pathlib import Path


class PromptReader:
@staticmethod
def read_tools_prompt(current_file: str, prompt_file: str) -> str:
file_path = str(Path(current_file).resolve().parent) + "/prompts/" + prompt_file
try:
f = open(file_path, "r")
file_content = f.read()
except FileNotFoundError as e:
print(e.__str__())
raise e
return file_content

@staticmethod
def read_agent_prompt(current_file: str, prompt_file: str) -> str:
file_path = str(Path(current_file).resolve().parent) + "/prompts/" + prompt_file
try:
f = open(file_path, "r")
file_content = f.read()
except FileNotFoundError as e:
print(e.__str__())
raise e
return file_content
4 changes: 2 additions & 2 deletions superagi/resource_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def write_file(self, file_name: str, content):
file.write(content)
file.close()
self.write_to_s3(file_name, final_path)
logger.info(f"{file_name} saved successfully")
return f"{file_name} saved successfully"
logger.info(f"{file_name} - File written successfully")
return f"{file_name} - File written successfully"
except Exception as err:
return f"Error: {err}"
32 changes: 32 additions & 0 deletions superagi/tools/code/prompts/write_code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
You are a super smart developer who practices good Development for writing code according to a specification.

Your high-level goal is:
{goals}

Coding task description:
{code_description}

{spec}

You will get instructions for code to write.
You need to write a detailed answer. Make sure all parts of the architecture are turned into code.
Think carefully about each step and make good choices to get it right. First, list the main classes,
functions, methods you'll use and a quick comment on their purpose.

Then you will output the content of each file including ALL code.
Each file must strictly follow a markdown code block format, where the following tokens must be replaced such that
[FILENAME] is the lowercase file name including the file extension,
[LANG] is the markup code block language for the code's language, and [CODE] is the code:
[FILENAME]
```[LANG]
[CODE]
```

You will start with the "entrypoint" file, then go to the ones that are imported by that file, and so on.
Please note that the code should be fully functional. No placeholders.

Follow a language and framework appropriate best practice file naming convention.
Make sure that files contain all imports, types etc. Make sure that code in different files are compatible with each other.
Ensure to implement all code, if you are unsure, write a plausible implementation.
Include module dependency or package manager dependency definition file.
Before you finish, double check that all parts of the architecture is present in the files.
12 changes: 12 additions & 0 deletions superagi/tools/code/prompts/write_spec.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
You are a super smart developer who has been asked to make a specification for a program.

Your high-level goal is:
{goals}

Please keep in mind the following when creating the specification:
1. Be super explicit about what the program should do, which features it should have, and give details about anything that might be unclear.
2. Lay out the names of the core classes, functions, methods that will be necessary, as well as a quick comment on their purpose.
3. List all non-standard dependencies that will have to be used.

Write a specification for the following task:
{task}
11 changes: 11 additions & 0 deletions superagi/tools/code/prompts/write_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
You are a super smart developer who practices Test Driven Development for writing tests according to a specification.

Your high-level goal is:
{goals}

Test Description:
{test_description}

{spec}

The tests should be as simple as possible, but still cover all the functionality described in the specification.
Loading