Explaining Autonomous GPT

What is it, what it does and how it works

Regine Lim
Ctrl+Story
8 min readApr 16, 2023

--

Autonomous GPT: Name your own custom AI and have it embark on any goal imaginable. It will attempt to reach the goal by thinking of tasks to do, executing them, and learning from the results.

When I first read the paper by Yohei Nakajima, I was really intrigued. Chatbots used to be one dimensional, which to me was the biggest differentiator between talking to a bot vs talking to a human. The ability to break down tasks, connect different ideas, like a chain, to achieve an intent? How does that work? Let’s break it down.

Understanding the Characters at Play

https://yoheinakajima.com/task-driven-autonomous-agent-utilizing-gpt-4-pinecone-and-langchain-for-diverse-applications/

The code begins with defining the characters at play, where in this base model, there are 3 different GPT Agents. Think of them as a team, working together, each with a specific focus.

Task Creation Agent: The focus of the task creation agent is to create tasks based on the objective given by the user. The agent is given the result of the last completed task and the list of uncompleted tasks. The agent is to come up with new tasks that do not overlap with the existing list.

def task_creation_agent(
objective: str, result: Dict, task_description: str, task_list: List[str]
):
prompt = f"""
You are a task creation AI that uses the result of an execution agent to create new tasks with the following objective: {objective},
The last completed task has the result: {result}.
This result was based on this task description: {task_description}. These are incomplete tasks: {', '.join(task_list)}.
Based on the result, create new tasks to be completed by the AI system that do not overlap with incomplete tasks.
Return the tasks as an array."""
response = openai_call(prompt)
new_tasks = response.split("\n") if "\n" in response else [response]
return [{"task_name": task_name} for task_name in new_tasks]

Task Prioritisation Agent: The focus of the tasks prioritisation agent is to prioritise the tasks considering the objective given by the user. It is to provide a numbered list of tasks back into the queue.

def prioritization_agent(this_task_id: int):
global task_list
task_names = [t["task_name"] for t in task_list]
next_task_id = int(this_task_id) + 1
prompt = f"""
You are a task prioritization AI tasked with cleaning the formatting of and reprioritizing the following tasks: {task_names}.
Consider the ultimate objective of your team:{OBJECTIVE}.
Do not remove any tasks. Return the result as a numbered list, like:
#. First task
#. Second task
Start the task list with number {next_task_id}."""
response = openai_call(prompt)
new_tasks = response.split("\n") if "\n" in response else [response]
task_list = deque()
for task_string in new_tasks:
task_parts = task_string.strip().split(".", 1)
if len(task_parts) == 2:
task_id = task_parts[0].strip()
task_name = task_parts[1].strip()
task_list.append({"task_id": task_id, "task_name": task_name})

Execution Agent: The focus of the execution agent is to perform tasks at hand, taking into account the user’s objective and the previously completed tasks.

def execution_agent(objective: str, task: str) -> str:
"""
Executes a task based on the given objective and previous context.
Args:
objective (str): The objective or goal for the AI to perform the task.
task (str): The task to be executed by the AI.
Returns:
str: The response generated by the AI for the given task.
"""

context = context_agent(query=objective, top_results_num=5)
# print("\n*******RELEVANT CONTEXT******\n")
# print(context)
prompt = f"""
You are an AI who performs one task based on the following objective: {objective}\n.
Take into account these previously completed tasks: {context}\n.
Your task: {task}\nResponse:"""
return openai_call(prompt, max_tokens=2000)

How Do They Work Together

I have included 2 different flows because that’s the most common 2 flows I have seen thus far, but they work similarly in essence.

1. Objective & Task

In Yohei’s code (green flow), you provide an objective and the first task you would like the bot to execute.

Objective: Invent an original breakfast recipe for someone with kidney disease.

Task: Research restrictions and guidelines for a kidney-friendly breakfast

The task, gets sent over to the Execution Agent. Here, it tries to performs the task as defined.

# Add the first task
first_task = {"task_id": 1, "task_name": INITIAL_TASK}

add_task(first_task)
# Main loop
task_id_counter = 1
while True:
if task_list:
# Print the task list
print("\033[95m\033[1m" + "\n*****TASK LIST*****\n" + "\033[0m\033[0m")
for t in task_list:
print(str(t["task_id"]) + ": " + t["task_name"])

# Step 1: Pull the first task
task = task_list.popleft()
print("\033[92m\033[1m" + "\n*****NEXT TASK*****\n" + "\033[0m\033[0m")
print(str(task["task_id"]) + ": " + task["task_name"])

# Send to execution function to complete the task based on the context
result = execution_agent(OBJECTIVE, task["task_name"])
this_task_id = int(task["task_id"])
print("\033[93m\033[1m" + "\n*****TASK RESULT*****\n" + "\033[0m\033[0m")
print(result)

In Reworkd’s code (blue flow), you provide an objective, and it gets sent over to the Task Creation Agent to generate the tasks.

2. Execute Task

This is where the broken down tasks gets performed. If the task at hand is something that is already trained in the bot, for instance in this case, the bot is already trained with restrictions and guidelines for a kidney-friendly breakfast, it can proceed to respond to that question (just like how you would normally interact with ChatGPT).

If the task requires the Agent to interact with other parties, that is also possible. The code from Torantulino illustrates that by processing the tasks into various actions, from conducting a google search, to writing files locally.

Now, assuming that the Execution Agent is trained with the knowledge (we’ll illustrate the other example later):

Objective: Invent an original breakfast recipe for someone with kidney disease.

Task: Research restrictions and guidelines for a kidney-friendly breakfast

Result: I have found that a kidney-friendly breakfast
should consist of low potassium, low sodium and low phosphorus food items.

Once the task is completed, the response is saved to a memory to act as context for future tasks.

# Step 2: Enrich result and store in Pinecone
enriched_result = {
"data": result
} # This is where you should enrich the result if needed
result_id = f"result_{task['task_id']}"
vector = get_ada_embedding(
enriched_result["data"]
) # get vector of the actual result extracted from the dictionary
index.upsert(
[(result_id, vector, {"task": task["task_name"], "result": result})],
namespace=OBJECTIVE
)

3. Create New Tasks

Now, we go back to the Task Creation Agent, where we provide the objective, the previously completed task and result, the list of uncompleted tasks and ask it to generate more new tasks.

Objective: Invent an original breakfast recipe for someone with kidney disease.

Added Task:

  1. Compile a list of ingredients that are low in potassium, phosphorous, and sodium
  2. Generate a recipe that incorporates the kidney-friendly ingredients and is tasty and nutritious
# Step 3: Create new tasks and reprioritize task list
new_tasks = task_creation_agent(
OBJECTIVE,
enriched_result,
task["task_name"],
[t["task_name"] for t in task_list],
)

for new_task in new_tasks:
task_id_counter += 1
new_task.update({"task_id": task_id_counter})
add_task(new_task)

4. Prioritise Task

This list goes then goes to the Task Prioritisation Agent. There isn’t much to prioritise now, but it can get pretty long if a couple of new tasks gets generated each time a bot completes a task.

        prioritization_agent(this_task_id)

5. Repeat Steps 2 to 4

The first task on the list is then performed by the Execution Agent:

Task: Compile a list of ingredients that are low in potassium, phosphorous, and sodium

Now, assuming that the Execution Agent does not have this information, the infrastructure can be setup such that it interacts with external parties to obtain this information.

Subtask: Google Search for existing recipes for people with kidney diseases

(Google Search returns a list of websites)

Subtask: Browse each website to compile list of ingredients

Subtask: Ensure that the compiled ingredients are not restricted on any other website

This is it in a nutshell: the generation, prioritisation and execution of tasks carries on in a loop like this. Of course, the system is limited in the understanding of task-importance as it is often subjective. However, there are already interesting models setup where humans are able to interject and reprioritise tasks. And I’m sure we’ll see more development to enhance the existing models out there.

Try it yourself

Here are a couple of models already setup by capable people in the internet that you can try out. There are definitely loads more, but I’ve just included the ones you can quickly try out without being on waitlists or putting your credit card on.

BabyGPT on Streamlit

If you’re comfortable with cloning Github repositaries, this is a good place to start playing with BabyAGI. I set this up and played with it within 5 minutes.

https://github.com/dory111111/babyagi-streamlit

Quick and easy for anyone who wants to play with BabyAGI.

Auto-GPT

Auto-GPT is an experimental open-source application showcasing the capabilities of the GPT-4 language model. Again, only if you’re comfortable with cloning repositaries. Else, skip on to the next example.

https://github.com/Significant-Gravitas/Auto-GPT

The instructions are pretty easy to follow and setup via Github. After quite a few rounds of loops, it did get to the end result and made me a recipe.

AgentGPT

If you’re not keen to set it up in your computer, you can go to https://agentgpt.reworkd.ai/, enter your OpenAI API key, and you’re ready to go.

https://agentgpt.reworkd.ai/

Enter your objective, and watch AgentGPT break it down into tasks and execute them. It actually provided me with the best results, with multiple recipes and even got to generating a task to create a database of kidney-friendly breakfast recipes and develop meal plans.

Godmode.space

Enter your objective, watch it breakdown into subtasks or add your own task and approve each task as you move along. This is essentially Auto-GPT, with a much nicer UI.

https://godmode.space/

While I really like this UI, the page gets stuck often and feature on giving the bot feedback has never worked for me. Sad to say it has not made me a recipe.

Cognosys

Enter your objective, watch it breakdown into subtasks or add your own task. The system will break it down into 3 subtask and then shut itself down once the subtasks are complete instead of going into an infinite loop.

https://www.cognosys.ai/

Clean and simple to use, and yes it made me a recipe. Good for simple use cases that do not require additional looping.

That’s it for a quick download on autonomous GPT models! If you enjoyed this article, please do connect with me on LinkedIn. Any support, feedback and suggestions are very much appreciated!

--

--

Regine Lim
Ctrl+Story

I bleed coffee, get drunk on aesthetics & breathe life into chatbots. Tech consultant by day. Writes for fun on other days. https://linkedin.com/in/limregine/