AutoGPT解析

2024-10-07  本文已影响0人  杰森斯坦sen

AutoGPT是一个相对全面精巧可以构建AI Agent的框架,包含了AI代理的创建、部署和持续管理。

AI agent的结构被设计成很像人类,具有个性、记忆、思维过程和能力等不同组件。


AI agent的组件

Forge

对于AI代理的创建,AutoGPT提供了一个叫Forge的工具模版,自动生成Agent的代码,配置和运行脚本,甚至还包括了基准测试系统和前端。

创建Agent:

./run agent create YOUR_AGENT_NAME

运行Agent:

./run agent start YOUR_AGENT_NAME
Agent运行起来

Forge的核心代码结构包含:

component

from forge.agent import BaseAgent
from forge.agent.components import AgentComponent

class HelloComponent(AgentComponent):
    pass

class SomeComponent(AgentComponent):
    def __init__(self, hello_component: HelloComponent):
        self.hello_component = hello_component

class MyAgent(BaseAgent):
    def __init__(self):
        # These components will be automatically discovered and used
        self.hello_component = HelloComponent()
        # We pass HelloComponent to SomeComponent
        self.some_component = SomeComponent(self.hello_component)

按顺序指定component:

class MyAgent(Agent):
    def __init__(self):
        self.hello_component = HelloComponent()
        self.calculator_component = CalculatorComponent()
        # Explicitly set components list
        self.components = [self.hello_component, self.calculator_component]

可以从配置文件导入components:

{
    "CodeExecutorConfiguration": {
        "execute_local_commands": false,
        "shell_command_control": "allowlist",
        "shell_allowlist": ["cat", "echo"],
        "shell_denylist": [],
        "docker_container_name": "agent_sandbox"
    },
    "FileManagerConfiguration": {
        "storage_path": "agents/AutoGPT/",
        "workspace_path": "agents/AutoGPT/workspace"
    },
    "GitOperationsConfiguration": {
        "github_username": null
    },
    "ActionHistoryConfiguration": {
        "llm_name": "gpt-3.5-turbo",
        "max_tokens": 1024,
        "spacy_language_model": "en_core_web_sm"
    },
    "ImageGeneratorConfiguration": {
        "image_provider": "dalle",
        "huggingface_image_model": "CompVis/stable-diffusion-v1-4",
        "sd_webui_url": "http://localhost:7860"
    },
    "WebSearchConfiguration": {
        "duckduckgo_max_attempts": 3
    },
    "WebSeleniumConfiguration": {
        "llm_name": "gpt-3.5-turbo",
        "web_browser": "chrome",
        "headless": true,
        "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
        "browse_spacy_language_model": "en_core_web_sm"
    }
}

Agent Protocol

定义了Agent接口,方便统一构建各种Agent。
Agent Protocol主要定义了Task 任务、Step 步骤、Artifact 生成文件,以及对应的API定义:

Protocol还包括记忆模块db.py,核心类是AgentDB,在Agent初始化时传入db的配置信息。

Agent

BaseAgent 提供了两个Agent工作需要的抽象方法:

Agent是AutoGPT实现的继承自BaseAgent 并实现了上面两个抽象方法,包含所有内建的components。这样最简单的创建自己的Agent的方法就是继承这个Agent,然后添加自己额外的component。当然也可以直接继承BaseAgent 可以做更多的定制化。

class MyComponent(AgentComponent):
    pass

class MyAgent(Agent):
    def __init__(
        self,
        settings: AgentSettings,
        llm_provider: MultiProvider
        file_storage: FileStorage,
        app_config: AppConfig,
    ):
        # Call the parent constructor to bring in the default components
        super().__init__(settings, llm_provider, file_storage, app_config)
        # Add your custom component
        self.my_component = MyComponent()

重构

最近AutoGPT做了一次全新的重构,把Forge等组件都移动到classic文件夹,新的核心目录变成autogpt_platform,包含如下等模块:

Supabase架构
上一篇 下一篇

猜你喜欢

热点阅读