AutoAgent:全自动零代码LLM智能体框架

项目描述

AutoAgent是一个全自动化零代码的LLM智能体框架,旨在简化智能体的创建和管理过程。该项目通过创新的元智能体(MetaAgent)架构,实现了智能体的自动生成、工具调用和工作流编排,无需人工编码即可构建复杂的AI系统。

功能特性

  • 智能体自动生成:通过XML表单自动创建和配置智能体
  • 多智能体协作:支持智能体间的通信和任务传递
  • 工具自动调用:集成多种工具(文件浏览、网页操作、代码执行等)
  • 工作流编排:可视化编排复杂的工作流程
  • 环境集成:支持Docker和本地环境
  • 自动错误处理:内置重试和错误恢复机制
  • 知识管理:集成代码和文档的向量检索功能
  • 评估系统:内置任务评估和性能分析工具

核心创新点包括:

  • 元智能体架构实现自我改进
  • 零代码智能体创建工作流
  • 动态工具调用和组合

安装指南

系统要求

  • Python 3.8+
  • Docker(如需使用容器环境)
  • Git(如需从仓库克隆)

安装步骤

  1. 克隆仓库:
git clone https://github.com/HKUDS/AutoAgent.git
cd AutoAgent
  1. 安装依赖:
pip install -e .
  1. 配置环境变量:
cp .env.example .env
# 编辑.env文件配置您的设置
  1. 启动Docker环境(可选):
docker-compose up -d

使用说明

基本使用示例

from autoagent import MetaChain
from autoagent.agents import get_system_triage_agent

# 初始化客户端
client = MetaChain()

# 获取智能体
agent = get_system_triage_agent("gpt-4")

# 运行智能体
response = client.run(
    agent=agent,
    messages=[{"role": "user", "content": "帮我解决这个问题..."}]
)

典型工作流

  1. 创建智能体
from autoagent.agents.meta_agent import agent_editor

# 通过表单创建新智能体
new_agent = agent_editor.create_agent(agent_form_xml)
  1. 运行工具
from autoagent.tools import execute_command

# 执行系统命令
result = execute_command("ls -la", context_variables)
  1. 管理工作流
from autoagent.workflows import create_workflow

# 创建工作流
workflow = create_workflow(workflow_form_xml)

核心代码

智能体运行引擎

async def run_async(self, agent: Agent, messages: List, context_variables: dict = None, debug: bool = False) -> Response:
    """
    异步运行智能体
    
    参数:
        agent: 要运行的智能体实例
        messages: 消息历史记录
        context_variables: 上下文变量字典
        debug: 是否启用调试模式
        
    返回:
        Response对象包含运行结果
    """
    # 初始化上下文
    context_variables = context_variables or {}
    
    # 处理函数调用
    if self.fn_call:
        messages = self._process_fn_call(agent, messages)
    
    # 调用LLM
    response = await self._call_llm(agent, messages)
    
    # 处理工具调用
    if response.tool_calls:
        return await self._handle_tool_calls(agent, response, context_variables)
        
    return response

工具调用系统

def register_tool(tool_func):
    """
    装饰器函数,用于注册新工具
    
    参数:
        tool_func: 要注册的工具函数
        
    返回:
        注册后的工具函数
    """
    tool_name = tool_func.__name__
    tool_args = inspect.signature(tool_func).parameters
    
    # 构建工具描述
    tool_desc = {
        "name": tool_name,
        "description": tool_func.__doc__,
        "parameters": {
            "type": "object",
            "properties": {
                name: {"type": "string"} 
                for name in tool_args
            }
        }
    }
    
    # 注册到全局工具库
    registry.tools[tool_name] = tool_func
    registry.tools_info[tool_name] = tool_desc
    
    return tool_func

工作流引擎

class WorkflowEngine:
    def __init__(self):
        self.events = {}
        self.agents = {}
        
    async def run_workflow(self, workflow_xml: str, input_data: dict) -> dict:
        """
        运行工作流
        
        参数:
            workflow_xml: 工作流定义XML
            input_data: 输入数据
            
        返回:
            工作流执行结果
        """
        # 解析工作流
        workflow = self._parse_workflow(workflow_xml)
        
        # 初始化上下文
        context = {"input": input_data}
        
        # 执行工作流
        for event in workflow["events"]:
            result = await self._execute_event(event, context)
            context.update(result)
            
        return context["output"]

更多精彩内容 请关注我的个人公众号 公众号(办公AI智能小助手)
公众号二维码
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

Logo

更多推荐