babyagi


Namebabyagi JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/yoheinakajima/babyagi
SummaryAn experimental prototype framework for building self building autonomous agents.
upload_time2024-10-11 07:24:33
maintainerNone
docs_urlNone
authorYohei Nakajima
requires_python>=3.6
licenseNone
keywords agi ai framework baby agi
VCS
bugtrack_url
requirements Flask sqlalchemy cryptography scikit-learn litellm openai
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://github.com/yoheinakajima/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](https://x.com/yoheinakajima/status/1840678823681282228) 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](#quick-start)
- [Basic Usage](#basic-usage)
- [Function Metadata](#function-metadata)
- [Function Loading](#function-loading)
- [Key Dependencies](#key-dependencies)
- [Execution Environment](#execution-environment)
  - [Log](#log)
- [Dashboard](#dashboard)
- [Pre-loaded Functions](#pre-loaded-functions)
- [Future/Draft Features](#futuredraft-features)
- [API Reference](#api-reference)
- [Contributing](#contributing)
- [License](#license)

## Quick Start

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

1. **Install BabyAGI:**

    ```bash
    pip install babyagi
    ```

2. **Import BabyAGI and load the dashboard:**

    ```python
    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:

```python
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:

```python
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:**

```python
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:**

```python
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:

~~~python
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:

~~~python
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](https://github.com/yoheinakajima/babyagi_staging/blob/main/self_build.png?raw=true)



**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](https://forms.gle/UZLyT75HQULr8XNUA) (I have a few fun initiatives coming up!)

## License

BabyAGI is released under the MIT License. See the [LICENSE](LICENSE) file for more details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/yoheinakajima/babyagi",
    "name": "babyagi",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "AGI, AI, Framework, Baby AGI",
    "author": "Yohei Nakajima",
    "author_email": "babyagi@untapped.vc",
    "download_url": "https://files.pythonhosted.org/packages/fb/cb/c64f9a07f9c391c418695e2f0c3c4819949059f72ac000fd45fcc353566f/babyagi-0.1.4.tar.gz",
    "platform": null,
    "description": "# BabyAGI\n\n> [!NOTE]\n> 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](https://github.com/yoheinakajima/babyagi_archive) repo (September 2024 snapshot).\n\n> [!CAUTION]\n> 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.\n\n---\n\nThis 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.\n\nCheck out [this introductory X/Twitter thread](https://x.com/yoheinakajima/status/1840678823681282228) for a simple overview.\n\nThe 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.\n\n## Table of Contents\n\n- [Quick Start](#quick-start)\n- [Basic Usage](#basic-usage)\n- [Function Metadata](#function-metadata)\n- [Function Loading](#function-loading)\n- [Key Dependencies](#key-dependencies)\n- [Execution Environment](#execution-environment)\n  - [Log](#log)\n- [Dashboard](#dashboard)\n- [Pre-loaded Functions](#pre-loaded-functions)\n- [Future/Draft Features](#futuredraft-features)\n- [API Reference](#api-reference)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Quick Start\n\nTo quickly check out the dashboard and see how it works:\n\n1. **Install BabyAGI:**\n\n    ```bash\n    pip install babyagi\n    ```\n\n2. **Import BabyAGI and load the dashboard:**\n\n    ```python\n    import babyagi\n\n    if __name__ == \"__main__\":\n        app = babyagi.create_app('/dashboard')\n        app.run(host='0.0.0.0', port=8080)\n    ```\n\n3. **Navigate to the dashboard:**\n\n    Open your browser and go to `http://localhost:8080/dashboard` to access the BabyAGI dashboard.\n    \n## Basic Usage\n\nStart by importing `babyagi` and registering your functions. Here's how to register two functions, where one depends on the other:\n\n```python\nimport babyagi\n\n# Register a simple function\n@babyagi.register_function()\ndef world():\n    return \"world\"\n\n# Register a function that depends on 'world'\n@babyagi.register_function(dependencies=[\"world\"])\ndef hello_world():\n    x = world()\n    return f\"Hello {x}!\"\n\n# Execute the function\nprint(babyagi.hello_world())  # Output: Hello world!\n\nif __name__ == \"__main__\":\n    app = babyagi.create_app('/dashboard')\n    app.run(host='0.0.0.0', port=8080)\n```\n\n## Function Metadata\n\nFunctions 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:\n\n```python\nimport babyagi\n\n@babyagi.register_function(\n    imports=[\"math\"],\n    dependencies=[\"circle_area\"],\n    key_dependencies=[\"openai_api_key\"],\n    metadata={\n        \"description\": \"Calculates the volume of a cylinder using the circle_area function.\"\n    }\n)\ndef cylinder_volume(radius, height):\n    import math\n    area = circle_area(radius)\n    return area * height\n```\n\n**Available Metadata Fields:**\n\n- `imports`: List of external libraries the function depends on.\n- `dependencies`: List of other functions this function depends on.\n- `key_dependencies`: List of secret keys required by the function.\n- `metadata[\"description\"]`: A description of what the function does.\n\n## Function Loading\n\nIn 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.\n\nYou can find available function packs in `babyagi/functionz/packs`.\n\n**Loading Custom Function Packs:**\n\n```python\nimport babyagi\n\n# Load your custom function pack\nbabyagi.load_functions(\"path/to/your/custom_functions.py\")\n```\n\nThis approach makes function building and management easier by organizing related functions into packs.\n\n## Key Dependencies\n\nYou can store `key_dependencies` directly from your code or manage them via the dashboard.\n\n**Storing Key Dependencies from Code:**\n\n```python\nimport babyagi\n\n# Add a secret key\nbabyagi.add_key_wrapper('openai_api_key', 'your_openai_api_key')\n```\n\n**Adding Key Dependencies via Dashboard:**\n\nNavigate to the dashboard and use the **add_key_wrapper** feature to securely add your secret keys.\n\n## Execution Environment\n\nBabyAGI 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.\n\n### Log\n\nBabyAGI 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.\n\n**Key Logging Features:**\n\n- **Execution Tracking:** Logs when a function starts and finishes execution, including the function name, arguments, keyword arguments, and execution time.\n  \n- **Error Logging:** Captures and logs any errors that occur during function execution, providing detailed error messages for troubleshooting.\n\n- **Dependency Management:** Automatically resolves and logs dependencies between functions, ensuring that all required functions and libraries are loaded before execution.\n\n- **Trigger Logging:** Logs the execution of triggered functions, detailing which functions were triggered by others and their respective execution outcomes.\n\n- **Comprehensive Records:** Maintains a history of all function executions, enabling users to review past activities, understand function relationships, and analyze performance metrics.\n\n**How Triggers Work:**\n\nTriggers 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.\n\nTriggers 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.\n\n## Dashboard\n\nThe BabyAGI dashboard offers a user-friendly interface for managing functions, monitoring executions, and handling configurations. Key features include:\n\n- **Function Management:** Register, deregister, and update functions directly from the dashboard.\n\n- **Dependency Visualization:** View and manage dependencies between functions to understand their relationships.\n\n- **Secret Key Management:** Add and manage secret keys securely through the dashboard interface.\n\n- **Logging and Monitoring:** Access comprehensive logs of function executions, including inputs, outputs, and execution times.\n\n- **Trigger Management:** Set up triggers to automate function executions based on specific events or conditions.\n\n**Accessing the Dashboard:**\n\nAfter running your application, navigate to `http://localhost:8080/dashboard` to access the BabyAGI dashboard.\n## Pre-loaded Functions Summary\n\nBabyAGI includes two pre-loaded function packs:\n\n1. **Default Functions (`packs/default_functions.py`):**\n   - **Function Execution:** Run, add, update, or retrieve functions and versions.\n   - **Key Management:** Add and retrieve secret keys.\n   - **Triggers:** Add triggers to execute functions based on others.\n   - **Logs:** Retrieve logs with optional filters.\n\n2. **AI Functions (`packs/ai_generator.py`):**\n   - **AI Description & Embeddings:** Auto-generate descriptions and embeddings for functions.\n   - **Function Selection:** Find or choose similar functions based on prompts.\n\n## Running a Self-Building Agent\n\nBabyAGI includes two experimental self-building agents, showcasing how the framework can help a self-building coding agent leverage existing functions to write new ones.\n\n### 1. `process_user_input` in the `code_writing_functions` pack\n\nThis 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.\n\nTry this:\n\n~~~python\nimport babyagi\n\nbabyagi.add_key_wrapper('openai_api_key', os.environ['OPENAI_API_KEY'])\nbabyagi.load_functions(\"drafts/code_writing_functions\")\n\nbabyagi.process_user_input(\"Grab today's score from ESPN and email it to test@test.com\")\n~~~\n\nWhen you run this, you will see the functions being generated in the shell and new functions will be available in the dashboard once completed.\n\n### 2. `self_build` in the `self_build` pack\n\nThis 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.\n\nTry this:\n\n~~~python\nimport babyagi\n\nbabyagi.add_key_wrapper('openai_api_key', os.environ['OPENAI_API_KEY'])\nbabyagi.load_functions(\"drafts/code_writing_functions\")\nbabyagi.load_functions(\"drafts/self_build\")\n\nbabyagi.self_build(\"A sales person at an enterprise SaaS company.\", 3)\n~~~\n\nThis will generate 3 distinct tasks a salesperson might ask an AI assistant and create functions to handle those.\n\n*The functions will be generated and stored in the dashboard, but note that the generated code is minimal and may need improvement.\n\n![alt text](https://github.com/yoheinakajima/babyagi_staging/blob/main/self_build.png?raw=true)\n\n\n\n**Warning:** These draft features are experimental concepts and may not function as intended. They require significant improvements and should be used with caution.\n\n\n## Contributing\n\nContributions 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.\n\nIf you are a dev, investor, friend of open-source and interesting supporting AI work I do, please fill [this form](https://forms.gle/UZLyT75HQULr8XNUA) (I have a few fun initiatives coming up!)\n\n## License\n\nBabyAGI is released under the MIT License. See the [LICENSE](LICENSE) file for more details.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "An experimental prototype framework for building self building autonomous agents.",
    "version": "0.1.4",
    "project_urls": {
        "Author": "https://x.com/yoheinakajima",
        "Homepage": "https://github.com/yoheinakajima/babyagi"
    },
    "split_keywords": [
        "agi",
        " ai",
        " framework",
        " baby agi"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b74b1c1ee1561130e6b3fb5e97f08704543959d7d0c55ca1c3bd2ad51bc10dc4",
                "md5": "cd3e0e016bbe3f73c57238206ccdbb20",
                "sha256": "1e77f602ef75ffe960641b63697c8854b2642ebdd9276dbf8a0f3ccc72797a33"
            },
            "downloads": -1,
            "filename": "babyagi-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cd3e0e016bbe3f73c57238206ccdbb20",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 109399,
            "upload_time": "2024-10-11T07:24:30",
            "upload_time_iso_8601": "2024-10-11T07:24:30.203137Z",
            "url": "https://files.pythonhosted.org/packages/b7/4b/1c1ee1561130e6b3fb5e97f08704543959d7d0c55ca1c3bd2ad51bc10dc4/babyagi-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fbcbc64f9a07f9c391c418695e2f0c3c4819949059f72ac000fd45fcc353566f",
                "md5": "d433f45f5b8a31f164935347ce50bf85",
                "sha256": "49e7f757c57afb248a82cf2c1648264b373b22b2002b1ccf75db12dcc9490a45"
            },
            "downloads": -1,
            "filename": "babyagi-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "d433f45f5b8a31f164935347ce50bf85",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 83354,
            "upload_time": "2024-10-11T07:24:33",
            "upload_time_iso_8601": "2024-10-11T07:24:33.384835Z",
            "url": "https://files.pythonhosted.org/packages/fb/cb/c64f9a07f9c391c418695e2f0c3c4819949059f72ac000fd45fcc353566f/babyagi-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-11 07:24:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yoheinakajima",
    "github_project": "babyagi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "Flask",
            "specs": [
                [
                    ">=",
                    "2.0.0"
                ]
            ]
        },
        {
            "name": "sqlalchemy",
            "specs": [
                [
                    "<",
                    "2.0"
                ],
                [
                    ">=",
                    "1.4"
                ]
            ]
        },
        {
            "name": "cryptography",
            "specs": []
        },
        {
            "name": "scikit-learn",
            "specs": []
        },
        {
            "name": "litellm",
            "specs": []
        },
        {
            "name": "openai",
            "specs": []
        }
    ],
    "lcname": "babyagi"
}
        
Elapsed time: 0.36659s