babyagi README

The project's README from github.com/yoheinakajima/babyagi. As one markdown file: README.md.

BabyAGI

[!NOTE] The original BabyAGI from March 2023 introduced task planning as a method for developing autonomous agents. This project has been archived and moved to the babyagi_archive repo (September 2024 snapshot).

[!CAUTION] This is a framework built by Yohei who has never held a job as a developer. The purpose of this repo is to share ideas and spark discussion and for experienced devs to play with. Not meant for production use. Use with cautioun.


This newest BabyAGI is an experimental framework for a self-building autonomous agent. Earlier efforts to expand BabyAGI have made it clear that the optimal way to build a general autonomous agent is to build the simplest thing that can build itself.

Check out this introductory X/Twitter thread for a simple overview.

The core is a new function framework (functionz) for storing, managing, and executing functions from a database. It offers a graph-based structure for tracking imports, dependent functions, and authentication secrets, with automatic loading and comprehensive logging capabilities. Additionally, it comes with a dashboard for managing functions, running updates, and viewing logs.

Table of Contents

Quick Start

To quickly check out the dashboard and see how it works:

  1. Install BabyAGI:

    pip install babyagi
    
  2. Import BabyAGI and load the dashboard:

    import babyagi
    
    if __name__ == "__main__":
        app = babyagi.create_app('/dashboard')
        app.run(host='0.0.0.0', port=8080)
    
  3. Navigate to the dashboard:

    Open your browser and go to http://localhost:8080/dashboard to access the BabyAGI dashboard.

Basic Usage

Start by importing babyagi and registering your functions. Here's how to register two functions, where one depends on the other:

import babyagi

# Register a simple function
@babyagi.register_function()
def world():
    return "world"

# Register a function that depends on 'world'
@babyagi.register_function(dependencies=["world"])
def hello_world():
    x = world()
    return f"Hello {x}!"

# Execute the function
print(babyagi.hello_world())  # Output: Hello world!

if __name__ == "__main__":
    app = babyagi.create_app('/dashboard')
    app.run(host='0.0.0.0', port=8080)

Function Metadata

Functions can be registered with metadata to enhance their capabilities and manage their relationships. Here's a more comprehensive example of function metadata, showing logical usage of all fields:

import babyagi

@babyagi.register_function(
    imports=["math"],
    dependencies=["circle_area"],
    key_dependencies=["openai_api_key"],
    metadata={
        "description": "Calculates the volume of a cylinder using the circle_area function."
    }
)
def cylinder_volume(radius, height):
    import math
    area = circle_area(radius)
    return area * height

Available Metadata Fields:

Function Loading

In addition to using register_function, you can use load_function to load plugins or draft packs of functions. BabyAGI comes with built-in function packs, or you can load your own packs by pointing to the file path.

You can find available function packs in babyagi/functionz/packs.

Loading Custom Function Packs:

import babyagi

# Load your custom function pack
babyagi.load_functions("path/to/your/custom_functions.py")

This approach makes function building and management easier by organizing related functions into packs.

Key Dependencies

You can store key_dependencies directly from your code or manage them via the dashboard.

Storing Key Dependencies from Code:

import babyagi

# Add a secret key
babyagi.add_key_wrapper('openai_api_key', 'your_openai_api_key')

Adding Key Dependencies via Dashboard:

Navigate to the dashboard and use the add_key_wrapper feature to securely add your secret keys.

Execution Environment

BabyAGI automatically loads essential function packs and manages their dependencies, ensuring a seamless execution environment. Additionally, it logs all activities, including the relationships between functions, to provide comprehensive tracking of function executions and dependencies.

Log

BabyAGI implements a comprehensive logging system to track all function executions and their interactions. The logging mechanism ensures that every function call, including its inputs, outputs, execution time, and any errors, is recorded for monitoring and debugging purposes.

Key Logging Features:

How Triggers Work:

Triggers are mechanisms that allow certain functions to be automatically executed in response to specific events or actions within the system. For example, when a function is added or updated, a trigger can initiate the generation of a description for that function.

Triggers enhance the autonomy of BabyAGI by enabling automated workflows and reducing the need for manual intervention. However, it's essential to manage triggers carefully to avoid unintended recursive executions or conflicts between dependent functions.

Dashboard

The BabyAGI dashboard offers a user-friendly interface for managing functions, monitoring executions, and handling configurations. Key features include:

Accessing the Dashboard:

After running your application, navigate to http://localhost:8080/dashboard to access the BabyAGI dashboard.

Pre-loaded Functions Summary

BabyAGI includes two pre-loaded function packs:

  1. Default Functions (packs/default_functions.py):

    • Function Execution: Run, add, update, or retrieve functions and versions.
    • Key Management: Add and retrieve secret keys.
    • Triggers: Add triggers to execute functions based on others.
    • Logs: Retrieve logs with optional filters.
  2. AI Functions (packs/ai_generator.py):

    • AI Description & Embeddings: Auto-generate descriptions and embeddings for functions.
    • Function Selection: Find or choose similar functions based on prompts.

Running a Self-Building Agent

BabyAGI includes two experimental self-building agents, showcasing how the framework can help a self-building coding agent leverage existing functions to write new ones.

1. process_user_input in the code_writing_functions pack

This function first determines whether to use an existing function or generate new ones. If new functions are needed, it breaks them down into smaller reusable components and combines them into a final function.

Try this:

import babyagi

babyagi.add_key_wrapper('openai_api_key', os.environ['OPENAI_API_KEY'])
babyagi.load_functions("drafts/code_writing_functions")

babyagi.process_user_input("Grab today's score from ESPN and email it to [email protected]")

When you run this, you will see the functions being generated in the shell and new functions will be available in the dashboard once completed.

2. self_build in the self_build pack

This function takes a user description and generates X distinct tasks that a user might ask an AI assistant. Each task is processed by process_user_input, creating new functions if no existing ones suffice.

Try this:

import babyagi

babyagi.add_key_wrapper('openai_api_key', os.environ['OPENAI_API_KEY'])
babyagi.load_functions("drafts/code_writing_functions")
babyagi.load_functions("drafts/self_build")

babyagi.self_build("A sales person at an enterprise SaaS company.", 3)

This will generate 3 distinct tasks a salesperson might ask an AI assistant and create functions to handle those.

*The functions will be generated and stored in the dashboard, but note that the generated code is minimal and may need improvement.

alt text

Warning: These draft features are experimental concepts and may not function as intended. They require significant improvements and should be used with caution.

Contributing

Contributions are greatly appreciatedly, but candidly I have not been great at managing PRs. Please be patient as things will move slow while I am working on this alone (on nights and weekends). I may start by building a small core crew before collaborating with a larger group.

If you are a dev, investor, friend of open-source and interesting supporting AI work I do, please fill this form (I have a few fun initiatives coming up!)

License

BabyAGI is released under the MIT License. See the LICENSE file for more details.

babyagi (yoheinakajima/babyagi)

Searching Database…

22.4K ·GitHub
这是什么?BabyAGI 是一个实验性框架,用于构建可自我构建的自主智能体。它围绕函数框架 functionz 搭建,能够从数据库中存储、管理和执行函数。
这是现成的智能体,还是我可以在上面搭建的框架?这是一个框架,不是开箱即用的智能体。核心是 functionz,一个基于图结构的系统,用于注册函数、跟踪它们的依赖、导入项和密钥,并提供日志记录和管理仪表盘。
仪表盘怎么跑起来?先安装 BabyAGI,然后在 Python 中 import babyagi 并加载仪表盘,再在浏览器中打开本地仪表盘的网址。
使用时需要 API 密钥吗?密钥和 API 密钥被当作“密钥依赖”来管理,你可以在代码中设置,也可以通过仪表盘的“添加密钥”功能安全地添加。需要哪些密钥,取决于你加载了哪些函数包。
能用在生产环境吗?不适合。维护者明确表示它不适用于生产环境,而且自我构建智能体的功能仍处于实验阶段,可能生成简陋甚至无法运行的代码。
这个项目适合谁?它面向有经验的开发者,适合想要试验自我构建智能体概念的人,而不是寻找成品的普通用户。
自带的两个自我构建智能体演示是什么?processUserInput(位于代码编写函数包中)会判断是复用已有函数,还是为某个任务生成新函数;selfBuild 接收一段描述,生成若干个不同的任务,并通过 processUserInput 为每个任务创建相应的函数。
BabyAGI 默认自带什么?默认附带两个函数包:Default Functions,涵盖函数执行、密钥管理、触发器和日志;AI Functions,可自动生成描述和嵌入向量,并根据提示帮助挑选相似的函数。
我可以在仪表盘上做什么?仪表盘可以让你注册、更新和注销函数,查看依赖关系,管理密钥,设置触发器,以及查看执行日志。
2023 年的原版 BabyAGI 和这个项目是什么关系?2023 年 3 月推出的原版 BabyAGI 首次为自主智能体引入了任务规划,现已归档到单独的 babyagiarchive 仓库中;本仓库是一个更新的、不同的实验性框架。
What are similar projects?hive, turnstone, evenfire, crewAI, Choir, Agentlas-OS, PocketFlow, brigade
Size
2.2 MB
Stars
22.4K
Updated
CommitJan 31
Age
3y
Commits · 90 Days