AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Implements Agent system Auto-GPT can now run sub-instances of itself.
Torantulino3774c39c1eeb
diff --git a/AutonomousAI/agent_manager.py b/AutonomousAI/agent_manager.pynew file mode 100644index 0000000000..20b5884186--- /dev/null+++ b/AutonomousAI/agent_manager.py@@ -0,0 +1,68 @@+import openai++next_key = 0+agents = {} # key, (task, full_message_history)++# Create new GPT agent+def create_agent(task, prompt, model):+ global next_key+ global agents++ messages = [{"role": "user", "content": prompt},]++ # Start GTP3 instance+ response = openai.ChatCompletion.create(+ model="model",+ messages=messages,+ )++ agent_reply = response.choices[0].message["content"]++ # Update full message history+ messages.append({"role": "assistant", "content": agent_reply})++ key = next_key+ next_key += 1 # This is done instead of len(agents) to make keys unique even if agents are deleted++ agents[key] = (task, messages)++ return key, agent_reply++def message_agent(key, message):+ global agents++ task, messages = agents[key]++ # Add user message to message history before sending to agent+ messages.append({"role": "user", "content": message})++ # Start GTP3 instance+ response = openai.ChatCompletion.create(+ model="model",+ messages=messages,+ )++ # Get agent response+ agent_reply = response.choices[0].message["content"]++ # Update full message history+ messages.append({"role": "assistant", "content": agent_reply})++ return agent_reply++def list_agents():+ global agents++ # Return a list of agent keys and their tasks+ return [(key, task) for key, (task, _) in agents.items()]++def delete_agent(key):+ global agents++ try:+ del agents[key]+ return True+ except KeyError:+ return False++diff --git a/AutonomousAI/commands.py b/AutonomousAI/commands.pyindex 18cd814247..6d130db894 100644--- a/AutonomousAI/commands.py+++ b/AutonomousAI/commands.py@@ -2,6 +2,8 @@ import browseimport jsonimport memory as memimport datetime+import agent_manager as agents+def get_command(response):try:@@ -31,10 +33,14 @@ def execute_command(command_name, arguments):return delete_memory(arguments["key"])elif command_name == "memory_ovr":return overwrite_memory(arguments["key"], arguments["string"])- elif command_name == "start_instance":- return start_instance(arguments["name"], arguments["prompt"])- elif command_name == "manage_instances":- return manage_instances(arguments["action"])+ elif command_name == "start_agent":+ return start_agent(arguments["task"], arguments["prompt"])+ elif command_name == "message_agent":+ return message_agent(arguments["key"], arguments["message"])+ elif command_name == "list_agents":+ return list_agents()+ elif command_name == "delete_agent":+ return delete_agent(arguments["key"])elif command_name == "navigate_website":return navigate_website(arguments["action"], arguments["username"])elif command_name == "register_account":@@ -98,15 +104,23 @@ def overwrite_memory(key, string):### TODO: Not Yet Implemented: ###-def start_instance(name, prompt):- _text = "Starting instance with name " + name + " and prompt " + prompt- print(_text)- return "Command not implemented yet."+def start_agent(task, prompt, model = "gpt-3.5-turbo"):+ key, agent_response = agents.create_agent(task, prompt, model)+ return f"Agent created with key {key}. First response: {agent_response}"++def message_agent(key, message):+ agent_response = agents.message_agent(key, message)+ return f"Agent {key} responded: {agent_response}"++def list_agents():+ return agents.list_agents()++def delete_agent(key):+ result = agents.delete_agent(key)+ if result == False:+ return f"Agent {key} does not exist."+ return f"Agent {key} deleted."-def manage_instances(action):- _text = "Managing instances with action " + action- print(_text)- return _textdef navigate_website(action, username):_text = "Navigating website with action " + action + " and username " + usernamediff --git a/AutonomousAI/data/prompt.txt b/AutonomousAI/data/prompt.txtindex 27cc9611d1..23fb02c083 100644--- a/AutonomousAI/data/prompt.txt+++ b/AutonomousAI/data/prompt.txt@@ -11,8 +11,10 @@ COMMANDS:4. Memory Add: "memory_add", args: "string": "<string>"5. Memory Delete: "memory_del", args: "key": "<key>"6. Memory Overwrite: "memory_ovr", args: "key": "<key>", "string": "<string>"-7. Start GPT-4 Instance: "start_instance", args: "name": "<key>", "prompt": "<prompt>"-8. Manage GPT-4 Instances: "manage_instances", args: "action": "view_kill"+7. Start GPT Agent: "start_agent", "task": "<short_task_desc>", "prompt": "<prompt>"+8. Message GPT Agent: "message_agent", args: "key": "<key>", "message": "<message>"+9. List GPT Agents: "list_agents", args: ""+10. Delete GPT Agent: "delete_agent", args: "key": "<key>"9. Navigate & Perform: "navigate_website", args: "action": "click_button/input_text/register_account", "text/username": "<text>/<username>"10.Register account: "register_account", args: "username": "<username>", "website": "<website>"11.Transcribe & Summarise: "transcribe_summarise", args: "url": "<url>"