AI Agent Hub
AI エージェント / プラグイン情報メディア
← 一覧へ
BabyAGI
OTHER

BabyAGI

BabyAGI

自律エージェント研究の出発点となった軽量フレームワーク。タスク生成 → 実行 → 優先度付けの3エージェントループで目標を達成する古典的な実装。

#自律エージェント#古典#軽量
REPO STATS

リポジトリ統計

⭐ Stars
22.3k
🍴 Forks
2.9k
⚠️ Open Issues
25
🌿 Language
Python
📄 License
-
🕒 最終更新
2026.01.31 (3か月前)
📅 公開日
2023.04.03
🌿 Branch
main
README

ドキュメント

— AI による自動翻訳 (2026.05.07 更新)

BabyAGI

2023 年 3 月の元の BabyAGI は、自律エージェント開発の手法としてタスク計画を導入しました。このプロジェクトはアーカイブされ、babyagi_archive リポジトリに移動されました(2024 年 9 月スナップショット)。

注意

このフレームワークは、開発者として仕事をしたことのない Yohei によって構築されました。このリポジトリの目的は、アイデアを共有し、議論を刺激し、経験豊富な開発者が試験的に使用することです。本番環境での使用を想定していません。注意して使用してください。


この最新の BabyAGI は、自己構築する自律エージェント用の実験的フレームワークです。BabyAGI を拡張する以前の取り組みにより、汎用自律エージェントを構築する最適な方法は、自分自身を構築できる最もシンプルなものを構築することが明確になりました。

簡潔な概要については、こちらの X/Twitter スレッドをご覧ください

コアは、データベースから関数を保存、管理、実行するための新しい関数フレームワーク(functionz)です。インポート、依存関数、認証シークレットを追跡するためのグラフベースの構造を提供し、自動ロードと包括的なロギング機能を備えています。さらに、関数を管理し、更新を実行し、ログを表示するためのダッシュボードが付属しています。

目次

クイックスタート

ダッシュボードをすぐに確認して、その動作を見るには:

  1. BabyAGI をインストール:

    pip install babyagi
  2. BabyAGI をインポートしてダッシュボードをロード:

    import babyagi
    
    if __name__ == "__main__":
        app = babyagi.create_app('/dashboard')
        app.run(host='0.0.0.0', port=8080)
  3. ダッシュボードに移動:

    ブラウザを開いて http://localhost:8080/dashboard にアクセスして、BabyAGI ダッシュボードにアクセスしてください。

基本的な使用方法

babyagi をインポートして、関数を登録することから始めます。ここでは、一方が他方に依存する 2 つの関数を登録する方法を示しています。

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)

関数メタデータ

関数は、メタデータを使用して登録でき、その機能を強化し、関係を管理することができます。以下は、関数メタデータのより包括的な例で、すべてのフィールドの論理的な使用方法を示しています:

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

利用可能なメタデータフィールド:

  • imports:関数が依存する外部ライブラリのリスト。
  • dependencies:この関数が依存する他の関数のリスト。
  • key_dependencies:関数に必要なシークレットキーのリスト。
  • metadata["description"]:関数が何をするかの説明。

関数の読み込み

register_function を使用する以外に、load_function を使用して、プラグインや関数のドラフトパックを読み込むことができます。BabyAGI にはビルトイン関数パックが付属しており、ファイルパスを指定することで独自のパックを読み込むことができます。

利用可能な関数パックは babyagi/functionz/packs にあります。

カスタム関数パックの読み込み:

import babyagi

# カスタム関数パックの読み込み
babyagi.load_functions("path/to/your/custom_functions.py")

このアプローチにより、関連する関数をパックに整理することで、関数の構築と管理が容易になります。

キー依存関係

key_dependencies をコードから直接保存するか、ダッシュボード経由で管理できます。

コードからキー依存関係を保存する:

import babyagi

# シークレットキーを追加
babyagi.add_key_wrapper('openai_api_key', 'your_openai_api_key')

ダッシュボード経由でキー依存関係を追加する:

ダッシュボードに移動し、add_key_wrapper 機能を使用してシークレットキーを安全に追加します。

実行環境

BabyAGI は、必須の関数パックを自動的に読み込み、その依存関係を管理し、シームレスな実行環境を確保します。さらに、関数間の関係を含む、すべてのアクティビティを記録して、関数実行と依存関係の包括的な追跡を提供します。

ログ

BabyAGI は、すべての関数実行とその相互作用を追跡するための包括的なログシステムを実装しています。ログメカニズムにより、関数呼び出し(入力、出力、実行時間、エラーを含む)がすべて記録され、監視とデバッグの目的で利用できます。

主要なログ機能:

  • 実行追跡: 関数の開始と終了時刻、関数名、引数、キーワード引数、実行時間を記録します。

  • エラーログ: 関数実行中に発生するエラーをキャプチャして記録し、トラブルシューティング用の詳細なエラーメッセージを提供します。

  • 依存関係管理: 関数間の依存関係を自動的に解決して記録し、実行前に必要なすべての関数とライブラリが読み込まれていることを確認します。

  • トリガーログ: トリガーされた関数の実行を記録し、どの関数が他の関数によってトリガーされたか、およびそれぞれの実行結果の詳細を示します。

  • 包括的なレコード: すべての関数実行の履歴を保持し、ユーザーが過去のアクティビティを確認し、関数の関係を理解し、パフォーマンスメトリクスを分析できるようにします。

トリガーの仕組み:

トリガーは、システム内の特定のイベントやアクションに応答して、特定の関数を自動的に実行するメカニズムです。たとえば、関数が追加または更新されたときに、トリガーはその関数の説明の生成を開始できます。

トリガーは、BabyAGI の自律性を高め、自動化されたワークフローを実現し、手動操作の必要性を軽減します。ただし、意図しない再帰的実行や依存関数間の競合を避けるために、トリガーを慎重に管理することが重要です。

ダッシュボード

BabyAGI ダッシュボードは、関数の管理、実行の監視、設定の処理を行うためのユーザーフレンドリーなインターフェースを提供します。主な機能は以下の通りです:

  • 関数管理: ダッシュボードから直接関数の登録、登録解除、および更新を行うことができます。

  • 依存関係の可視化: 関数間の依存関係を表示および管理して、それらの関係を理解することができます。

  • シークレットキー管理: ダッシュボードインターフェースを通じてシークレットキーを安全に追加および管理します。

  • ログと監視: 入力、出力、実行時間を含む関数実行の包括的なログにアクセスします。

  • トリガー管理: 特定のイベントまたは条件に基づいて関数の実行を自動化するトリガーを設定します。

ダッシュボードへのアクセス:

アプリケーションを実行した後、http://localhost:8080/dashboard にアクセスして、BabyAGI ダッシュボードにアクセスしてください。

プリロード関数の概要

BabyAGI には 2 つのプリロード関数パックが含まれています:

  1. デフォルト関数(packs/default_functions.py):

    • 関数実行: 関数とバージョンを実行、追加、更新、または取得します。
    • キー管理: シークレットキーを追加および取得します。
    • トリガー: 他の関数に基づいて関数を実行するトリガーを追加します。
    • ログ: オプションのフィルターを使用してログを取得します。
  2. AI 関数(packs/ai_generator.py):

    • AI の説明と埋め込み: 関数の説明と埋め込みを自動生成します。
    • 関数選択: プロンプトに基づいて類似の関数を検索または選択します。

自己構築エージェントの実行

BabyAGI には 2 つの実験的な自己構築エージェントが含まれており、フレームワークが自己構築コーディングエージェントに対して、既存の関数を活用して新しい関数を書くのにどのように役立つかを示しています。

1. process_user_inputcode_writing_functions パック内)

この関数はまず、既存の関数を使用するか新しい関数を生成するかを判断します。新しい関数が必要な場合、それらを小さな再利用可能なコンポーネントに分割し、最終的な関数に組み合わせます。

以下を試してください:

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 test@test.com")

これを実行すると、シェルで生成される関数を見ることができ、完了すると新しい関数がダッシュボードで利用可能になります。

2. self_buildself_build パック内)

この関数はユーザーの説明を取得し、ユーザーが AI アシスタントに尋ねるかもしれない X 個の異なるタスクを生成します。各タスクは process_user_input によって処理され、既存の関数で十分でない場合は新しい関数を作成します。

以下を試してください:

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)

これにより、営業担当者が AI アシスタントに尋ねるかもしれない 3 つの異なるタスクが生成され、それらを処理するための関数が作成されます。

*関数はダッシュボードで生成されて保存されますが、生成されたコードは最小限であり、改善が必要な場合があることに注意してください。

alt text

警告: これらのドラフト機能は実験的な概念であり、意図したとおりに機能しない場合があります。大幅な改善が必要であり、慎重に使用する必要があります。

貢献

貢献は大いに歓迎されていますが、正直なところ、私は PR の管理が得意ではありません。夜間と週末に一人で作業しているため、進みが遅くなることをご了承ください。より大きなグループと協力する前に、小さなコアチームを構築することから始めるかもしれません。

開発者、投資家、オープンソースの支援者、または私が行っている興味深い AI の仕事に関心がある場合は、こちらのフォームに記入してください(今後いくつか楽しいイニシアチブが予定されています!)

ライセンス

BabyAGI は MIT ライセンスの下で公開されています。詳細については、LICENSE ファイルを参照してください。

— GitHub から取得した原文(一部省略の場合あり)

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:

  • imports: List of external libraries the function depends on.
  • dependencies: List of other functions this function depends on.
  • key_dependencies: List of secret keys required by the function.
  • metadata["description"]: A description of what the function does.

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:

  • Execution Tracking: Logs when a function starts and finishes execution, including the function name, arguments, keyword arguments, and execution time.

  • Error Logging: Captures and logs any errors that occur during function execution, providing detailed error messages for troubleshooting.

  • Dependency Management: Automatically resolves and logs dependencies between functions, ensuring that all required functions and libraries are loaded before execution.

  • Trigger Logging: Logs the execution of triggered functions, detailing which functions were triggered by others and their respective execution outcomes.

  • Comprehensive Records: Maintains a history of all function executions, enabling users to review past activities, understand function relationships, and analyze performance metrics.

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:

  • Function Management: Register, deregister, and update functions directly from the dashboard.

  • Dependency Visualization: View and manage dependencies between functions to understand their relationships.

  • Secret Key Management: Add and manage secret keys securely through the dashboard interface.

  • Logging and Monitoring: Access comprehensive logs of function executions, including inputs, outputs, and execution times.

  • Trigger Management: Set up triggers to automate function executions based on specific events or conditions.

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 test@test.com")

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.

RELATED

同じカテゴリの他のツール