Skip to content

Commit

Permalink
Testing and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed Apr 18, 2023
1 parent 661de4a commit e287d01
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
15 changes: 11 additions & 4 deletions AgentLLM.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def trim_context(self, context: List[str], max_tokens: int) -> List[str]:
break
return trimmed_context

def run(self, task: str, max_context_tokens: int = 500, long_term_access: bool = False):
def run(self, task: str, max_context_tokens: int = 4096, long_term_access: bool = False):
if not self.CFG.NO_MEMORY:
self.yaml_memory.log_interaction("USER", task)
context = self.context_agent(query=task, top_results_num=5, long_term_access=long_term_access)
Expand All @@ -59,9 +59,15 @@ def run(self, task: str, max_context_tokens: int = 500, long_term_access: bool =
commands_prompt = self.commands.get_prompt()
self.response = self.instruct(f"{commands_prompt}\n{prompt}")
else:
self.response = self.instruct(prompt)
# Chunk the prompt if it's too long
prompt_chunks = self.chunk_content(prompt)
responses = []
for chunk in prompt_chunks:
response = self.instruct(chunk)
responses.append(response)
self.response = " ".join(responses)

if not self.CFG.NO_MEMORY:
if self.CFG.NO_MEMORY:
self.store_result(task, self.response)
self.yaml_memory.log_interaction(self.CFG.AGENT_NAME, self.response)

Expand All @@ -79,6 +85,7 @@ def context_agent(self, query: str, top_results_num: int, long_term_access: bool
if long_term_access:
interactions = self.yaml_memory.memory["interactions"]
context = [interaction["message"] for interaction in interactions[-top_results_num:]]
context = self.chunk_content("\n\n".join(context))[:top_results_num]
else:
count = self.collection.count()
if count == 0:
Expand All @@ -103,7 +110,7 @@ def chunk_content(self, content: str, max_length: int = 500) -> List[str]:
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--prompt", type=str, default="What is the weather like today?")
parser.add_argument("--max_context_tokens", type=int, default=500)
parser.add_argument("--max_context_tokens", type=int, default=4096)
parser.add_argument("--long_term_access", type=bool, default=False)
args = parser.parse_args()
prompt = args.prompt
Expand Down
24 changes: 6 additions & 18 deletions Commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def load_commands(self):
for command_file in command_files:
module_name = os.path.splitext(os.path.basename(command_file))[0]
module = importlib.import_module(f"commands.{module_name}")
if issubclass(module.__dict__.get(module_name), Commands):
if issubclass(getattr(module, module_name), Commands):
command_class = getattr(module, module_name)()
for command_name, command_function in command_class.commands.items():
params = self.get_command_params(command_function)
Expand All @@ -37,23 +37,11 @@ def get_prompt(self):
for i, (command_name, command_function_name, params) in enumerate(self.commands, 1):
formatted_params = {f"{k}": repr(v) for k, v in params.items()}
commands_str += f'{i}. "{command_name}" - {command_function_name} {formatted_params}\n'

system_prompt = f"""
You are an AI language model. Your name is {self.CFG.AGENT_NAME}. Your role is to do anything asked of you with precision. You have the following constraints:
1. ~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.
2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.
3. No user assistance.
4. Exclusively use the commands listed in double quotes e.g. "command name".
You have the following resources:
1. Internet access for searches and information gathering.
2. Long Term memory management.
3. GPT-3.5 powered Agents for delegation of simple tasks.
4. File output.
You have the following commands available:
{commands_str}
"""
# Get prompt from model-prompts/{CFG.AI_MODEL}/system.txt
with open(f"model-prompts/{self.CFG.AI_MODEL}/system.txt", "r") as f:
system_prompt = f.read()
system_prompt = system_prompt.replace("{{COMMANDS}}", commands_str)
system_prompt = system_prompt.replace("{{AGENT_NAME}}", self.CFG.AGENT_NAME)
return system_prompt

def find_command(self, command_name: str):
Expand Down
4 changes: 4 additions & 0 deletions PROMPTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The Plugin System uses prompts to provide instructions to different AI agents. E
2. model-prompts/{model}/priority.txt
3. model-prompts/{model}/system.txt
4. model-prompts/{model}/task.txt
5. model-prompts/{model}/script.txt
### Prompt Formats

Each prompt has a specific format for providing instructions to the AI agents. The following section explains the format for each prompt type.
Expand Down Expand Up @@ -81,6 +82,9 @@ Return the tasks as an array.


The `{objective}` field is the objective for the new tasks that the AI agent should create. The `{result}` field is the result of the previous task. The `{task_description}` field is the description of the previous task. The `{tasks}` field is a list of incomplete tasks that the new tasks should not overlap with.

#### script.txt

### Conclusion

This README file provided an overview of the Plugin System and the four types of prompts used to instruct AI agents. It also provided the format for each prompt type.
Expand Down
2 changes: 1 addition & 1 deletion commands/execute_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

CFG = Config()

class ContainerActions(Commands):
class execute_code(Commands):
def __init__(self):
super().__init__()
self.commands = {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion commands/web_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

CFG = Config()

class WebScraping(Commands):
class web_playwright(Commands):
def __init__(self):
super().__init__()
self.commands = {
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ gitpython
flask-restful
flask_swagger
flask_swagger_ui
flasgger
flasgger
pynacl

0 comments on commit e287d01

Please sign in to comment.