見出し画像

BabyAGIを触って、ソースを読んでみる

話題のBabyAGIを触ってみました。

処理の流れ

アルゴリズムについては、発案者の説明もありましたが、実際に実行してみてソースや処理を眺めると、下記のような流れのようです。

  1. 目的やタスクを指定して

  2. タスクリストを作り、タスクキューから次のタスクを選定する

  3. タスク実行エージェントが、タスク処理をする。その際にコンテキストを参照する

  4. コンテキストをベクトル化してメモリにしまう。

  5. タスク生成エージェントがタスクリストを生成する。

  6. タスクキューに格納される

  7. 以降2の繰り返し

ちょっとソースを読む

個人的に面白いと思ったのは、コンテキストを格納したり参照している箇所と優先度決めのところ。ちょっとソースを読んでみる

コンテキストを考慮する

下記でタスク実行させて

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

下記でコンテキストをつくってしまう

# 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_PINECONE_COMPAT
)

ベクトル化もOpenAI製のものを用いている

# Get embedding for the text
def get_ada_embedding(text):
    text = text.replace("\n", " ")
    return openai.Embedding.create(input=[text], model="text-embedding-ada-002")[
        "data"
    ][0]["embedding"]

タスクの優先度は?

タスクキューの優先順位考慮もプロンプトで与えられそう。ON/OFF切り替えられる

def prioritization_agent():
    task_names = tasks_storage.get_task_names()
    next_task_id = tasks_storage.next_task_id()
    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}."""

気になること、やってみたいこと

  • 問題解決に至る処理の流れについてはとてもシンプルで、タスク処理が一つずつで実行されているので、いつ収束されるのか予測不能なこと

  • 収束までの必要予算の見積もり

  • 非同期でマルチタスクになったらどうなるのだろう

  • プロセスの説明力:処理結果が見づらいので視覚化したい

参考:実行結果

babyagi    | 
babyagi    | *****CONFIGURATION*****
babyagi    | 
babyagi    | Name: BabyAGI
babyagi    | LLM : gpt-3.5-turbo
babyagi    | Mode: none
babyagi    | 
babyagi    | *****OBJECTIVE*****
babyagi    | 
babyagi    | Solve world hunger
babyagi    | 
babyagi    | Initial task: Develop a task list
babyagi    | 
babyagi    | *****TASK LIST*****
babyagi    | 
babyagi    |  • Develop a task list
babyagi    | 
babyagi    | *****NEXT TASK*****
babyagi    | 
babyagi    | Develop a task list
babyagi    | 
babyagi    | *******RELEVANT CONTEXT******
babyagi    | 
babyagi    | ['Research and analyze successful models of food banks in similar communities, and develop a plan for implementing a food bank program in marginalized communities. This will involve researching the types of food banks, the number of participants, the impact on the community, and the resources needed to establish and maintain the program. The plan will address potential barriers to accessing the food banks and provide solutions to overcome these barriers. The success of the program will be monitored and evaluated regularly to ensure its effectiveness in achieving the objective of solving', 'Develop a task list', 'Research and analyze successful models of food cooperatives in similar communities, and develop a plan for implementing a food cooperative program in marginalized communities. This will involve researching the types of food cooperatives, the number of participants, the impact on the community, and the resources needed to establish and maintain the program. The plan will address potential barriers to accessing the food cooperatives and provide solutions to overcome these barriers. The success of the program will be monitored and evaluated regularly to ensure its effectiveness in achieving the', 'Conduct research on successful community garden models in similar communities and develop a plan for implementing a community garden program in marginalized communities.', 'Research and analyze successful sustainable agriculture projects in similar communities. This will involve looking at the types of projects that exist, the number of participants they serve, and the impact they have on the community. The analysis will also include the resources needed to establish and maintain sustainable agriculture projects, including funding, staff, and volunteers.']
babyagi    | 
babyagi    | *****TASK RESULT*****
babyagi    | 
babyagi    | 1. Conduct a needs assessment to identify the communities most affected by hunger and food insecurity.
babyagi    | 2. Develop partnerships with local organizations, businesses, and government agencies to secure funding and resources for food programs.
babyagi    | 3. Identify and secure a location for a food bank or food cooperative program.
babyagi    | 4. Recruit and train volunteers to assist with food distribution and program operations.
babyagi    | 5. Develop a system for collecting and distributing food donations from local businesses and individuals.
babyagi    | 6. Establish a system for tracking program participation and evaluating program effectiveness.
babyagi    | 7. Develop outreach and education programs to raise awareness about food insecurity and promote healthy eating habits.
babyagi    | 8. Explore opportunities for sustainable agriculture projects to provide fresh produce for food programs.
babyagi    | 9. Develop partnerships with local schools to provide meals for children in need.
babyagi    | 10. Advocate for policy changes at the local and national level to address the root causes of food insecurity.
babyagi    | 
babyagi    | *****TASK LIST*****
babyagi    | 
babyagi    |  • Conduct outreach and education programs to raise awareness about food insecurity and promote healthy eating habits in underserved communities.
babyagi    |  • Develop partnerships with local healthcare providers to address the health consequences of food insecurity.
babyagi    |  • Research and implement sustainable agriculture projects to provide fresh produce for food programs.
babyagi    |  • Develop a system for efficient and effective food distribution to communities in need.
babyagi    |  • Advocate for policy changes at the international level to address the root causes of food insecurity.
babyagi    | 
babyagi    | *****NEXT TASK*****
babyagi    | 
babyagi    | Conduct outreach and education programs to raise awareness about food insecurity and promote healthy eating habits in underserved communities.
babyagi    | 
babyagi    | *******RELEVANT CONTEXT******
babyagi    | 
babyagi    | ['Research and analyze successful models of food banks in similar communities, and develop a plan for implementing a food bank program in marginalized communities. This will involve researching the types of food banks, the number of participants, the impact on the community, and the resources needed to establish and maintain the program. The plan will address potential barriers to accessing the food banks and provide solutions to overcome these barriers. The success of the program will be monitored and evaluated regularly to ensure its effectiveness in achieving the objective of solving', 'Develop a task list', 'Research and analyze successful models of food cooperatives in similar communities, and develop a plan for implementing a food cooperative program in marginalized communities. This will involve researching the types of food cooperatives, the number of participants, the impact on the community, and the resources needed to establish and maintain the program. The plan will address potential barriers to accessing the food cooperatives and provide solutions to overcome these barriers. The success of the program will be monitored and evaluated regularly to ensure its effectiveness in achieving the', 'Conduct research on successful community garden models in similar communities and develop a plan for implementing a community garden program in marginalized communities.', 'Research and analyze successful sustainable agriculture projects in similar communities. This will involve looking at the types of projects that exist, the number of participants they serve, and the impact they have on the community. The analysis will also include the resources needed to establish and maintain sustainable agriculture projects, including funding, staff, and volunteers.']
babyagi    | 
babyagi    | *****TASK RESULT*****
babyagi    | 
babyagi    | Based on the previously completed tasks, it is clear that implementing food banks, cooperatives, and community gardens can help address food insecurity in marginalized communities. However, it is also important to educate and raise awareness about the issue of food insecurity and promote healthy eating habits in these communities. Therefore, my task will be to conduct outreach and education programs to achieve this objective.
babyagi    | 
babyagi    | To begin, I will research successful outreach and education programs that have been implemented in similar communities. This will involve looking at the types of programs that exist, the number of participants they serve, and the impact they have on the community. The analysis will also include the resources needed to establish and maintain outreach and education programs, including funding, staff, and volunteers.
babyagi    | 
babyagi    | Once I have developed a plan for implementing outreach and education programs, I will work with local organizations and community leaders to identify the most effective ways to reach underserved communities. This may involve partnering with schools, community centers, and other organizations to provide educational materials and resources.
babyagi    | 
babyagi    | The outreach and education programs will focus on promoting healthy eating habits and addressing the root causes of food insecurity. This may include providing information on nutrition, meal planning, and budgeting, as well as addressing issues such as food waste and food deserts.
babyagi    | 
babyagi    | To ensure the effectiveness of the outreach and education programs, I will monitor and evaluate their impact regularly. This will involve collecting data on the number of participants, the types of activities and resources provided, and the impact on the community. Based on this data, I will make adjustments to the programs as needed to ensure their continued success in achieving the objective of solving world hunger.
babyagi    | 
babyagi    | *****TASK LIST*****
babyagi    | 
babyagi    |  • Advocate for policy changes at the international level to address the root causes of food insecurity.
babyagi    |  • Research successful models of sustainable agriculture projects that have been implemented in similar communities. This will involve looking at the types of projects that exist, the resources needed to establish and maintain them, and the impact they have on the community.
babyagi    |  • Develop partnerships with local healthcare providers to address the health consequences of food insecurity.
babyagi    |  • Develop partnerships with local businesses and organizations to establish a system for efficient and effective
babyagi    | 
babyagi    | *****NEXT TASK*****
babyagi    | 
babyagi    | Advocate for policy changes at the international level to address the root causes of food insecurity.
babyagi    | 
babyagi    | *******RELEVANT CONTEXT******
babyagi    | 
babyagi    | ['Research and analyze successful models of food banks in similar communities, and develop a plan for implementing a food bank program in marginalized communities. This will involve researching the types of food banks, the number of participants, the impact on the community, and the resources needed to establish and maintain the program. The plan will address potential barriers to accessing the food banks and provide solutions to overcome these barriers. The success of the program will be monitored and evaluated regularly to ensure its effectiveness in achieving the objective of solving', 'Develop a task list', 'Conduct outreach and education programs to raise awareness about food insecurity and promote healthy eating habits in underserved communities.', 'Research and analyze successful models of food cooperatives in similar communities, and develop a plan for implementing a food cooperative program in marginalized communities. This will involve researching the types of food cooperatives, the number of participants, the impact on the community, and the resources needed to establish and maintain the program. The plan will address potential barriers to accessing the food cooperatives and provide solutions to overcome these barriers. The success of the program will be monitored and evaluated regularly to ensure its effectiveness in achieving the', 'Conduct research on successful community garden models in similar communities and develop a plan for implementing a community garden program in marginalized communities.']
babyagi    | 
babyagi    | *****TASK RESULT*****
babyagi    | 
babyagi    | Based on the previously completed tasks, it is clear that implementing food banks, cooperatives, and community gardens can help alleviate food insecurity in marginalized communities. However, these solutions only address the symptoms of the problem and not the root causes. To truly solve world hunger, we must advocate for policy changes at the international level that address the systemic issues that lead to food insecurity.
babyagi    | 
babyagi    | Some potential policy changes that could be advocated for include:
babyagi    | 
babyagi    | 1. Addressing income inequality: Income inequality is a major contributor to food insecurity. Policies that address income inequality, such as progressive taxation and a living wage, could help ensure that everyone has access to the resources they need to purchase food.
babyagi    | 
babyagi    | 2. Addressing climate change: Climate change is already having a significant impact on food production, and this impact is only expected to worsen in the coming years. Policies that address climate change, such as reducing greenhouse gas emissions and investing in sustainable agriculture, could help ensure that food production remains stable in the face of changing environmental conditions.
babyagi    | 
babyagi    | 3. Addressing trade policies: Trade policies can have a significant impact on food security, particularly in developing countries. Policies that prioritize local food production and protect small-scale farmers could help ensure that everyone has access to affordable, nutritious food.
babyagi    | 
babyagi    | Advocating for these policy changes will require collaboration and coordination at the international level. However, by addressing the root causes of food insecurity, we can work towards a world where everyone has access to the food they need to thrive.
babyagi    | 
babyagi    | *****TASK LIST*****
babyagi    | 
babyagi    |  • Research successful models of sustainable agriculture projects that have been implemented in similar communities. This will involve looking at the types of projects that exist, the resources needed to establish and maintain them, and the impact they have on the community.
babyagi    |  • Develop partnerships with local healthcare providers to address the health consequences of food insecurity.
babyagi    |  • Develop partnerships with local businesses and organizations to establish a system for efficient and effective community-led food production projects.
babyagi    |  • Research successful policies implemented by governments to address income inequality and
babyagi    | 
babyagi    | *****NEXT TASK*****
babyagi    | 
babyagi    | Research successful models of sustainable agriculture projects that have been implemented in similar communities. This will involve looking at the types of projects that exist, the resources needed to establish and maintain them, and the impact they have on the community.
babyagi    | 
babyagi    | *******RELEVANT CONTEXT******
babyagi    | 
babyagi    | ['Advocate for policy changes at the international level to address the root causes of food insecurity.', 'Research and analyze successful models of food banks in similar communities, and develop a plan for implementing a food bank program in marginalized communities. This will involve researching the types of food banks, the number of participants, the impact on the community, and the resources needed to establish and maintain the program. The plan will address potential barriers to accessing the food banks and provide solutions to overcome these barriers. The success of the program will be monitored and evaluated regularly to ensure its effectiveness in achieving the objective of solving', 'Develop a task list', 'Conduct outreach and education programs to raise awareness about food insecurity and promote healthy eating habits in underserved communities.', 'Research and analyze successful models of food cooperatives in similar communities, and develop a plan for implementing a food cooperative program in marginalized communities. This will involve researching the types of food cooperatives, the number of participants, the impact on the community, and the resources needed to establish and maintain the program. The plan will address potential barriers to accessing the food cooperatives and provide solutions to overcome these barriers. The success of the program will be monitored and evaluated regularly to ensure its effectiveness in achieving the']
^CGracefully stopping... (press Ctrl+C again to force)


この記事が気に入ったらサポートをしてみませんか?