AI-Powered Task Management System with Python and OpenAI: A Pared-Down Version of Task-Driven Autonomous Agent
If you're looking for a Python script that demonstrates an AI-powered task management system, look no further than BabyAGI. This script utilizes the APIs of OpenAI and Pinecone to prioritize, create, and execute tasks based on a predefined objective and the result of previous tasks.
Build an AI-Powered Task Management System with OpenAI and Pinecone APIs |
The main idea behind BabyAGI is that it takes the result of previous tasks and creates new ones based on the objective using OpenAI's natural language processing (NLP) capabilities. Pinecone is then used to store and retrieve task results for context. Although it's a pared-down version of the original Task-Driven Autonomous Agent, it still packs a punch in terms of its functionality.
How It Works
The script works by running an infinite loop that goes through the following steps:
- Pull the first task from the task list.
- Send the task to the execution agent, which utilizes OpenAI's API to complete the task based on the context.
- Enrich the result and store it in Pinecone.
- Create new tasks and reprioritize the task list based on the objective and the result of the previous task.
The script utilizes various functions such as the execution_agent(), task_creation_agent(), and prioritization_agent() to achieve these steps. The execution_agent() function takes two parameters: the objective and the task. It sends a prompt to OpenAI's API, which returns the result of the task. The task_creation_agent() function takes four parameters: the objective, the result of the previous task, the task description, and the current task list. It sends a prompt to OpenAI's API, which returns a list of new tasks as strings. The prioritization_agent() function takes the ID of the current task as a parameter and sends a prompt to OpenAI's API, which returns the reprioritized task list as a numbered list.
The script uses Pinecone to store and retrieve task results for context. It creates a Pinecone index based on the table name specified in the YOUR_TABLE_NAME variable. Pinecone is then used to store the results of the task in the index, along with the task name and any additional metadata.
How to Use
To use the script, you will need to follow these steps:
- Install the required packages: pip install -r requirements.txt
- Copy the .env.example file to .env: cp .env.example .env. This is where you will set the following variables:
- Set your OpenAI and Pinecone API keys in the OPENAI_API_KEY, OPENAPI_API_MODEL, and PINECONE_API_KEY variables.
- Set the Pinecone environment in the PINECONE_ENVIRONMENT variable.
- Set the name of the table where the task results will be stored in the TABLE_NAME variable.
- Set the objective of the task management system in the OBJECTIVE variable. Alternatively, you can pass it to the script as a quote argument.
- Set the first task of the system in the FIRST_TASK variable.
- Run the script using the command: ./babyagi.py ["<objective>"]
This script is designed to be run continuously as part of a task management system. Running this script continuously can result in high API usage, so please use it responsibly. Additionally, the script requires the OpenAI and Pinecone APIs to be set up correctly, so make sure you have set up the APIs before running the script.
BabyAGI is a pared-down version of the original Task-Driven Autonomous Agent (Mar 28, 2023) shared on Twitter. Official GitHub page of BabyAGI.