AutoGen:启用下一代大型语言模型的应用程序

"像 AutoGen 这样的功能有望从根本上改变和扩展大型语言模型的能力。这是我最近在人工智能领域看到的最令人兴奋的发展之一。"                             --Doug Burger, Technical Fellow, Microsoft

文章内容来源:https://www.microsoft.com/en-us/research/blog/autogen-enabling-next-generation-large-language-model-applications/

图 1. AutoGen 使用多代理对话启用基于 LLM 的复杂工作流程。(左)AutoGen 代理是可定制的,可以基于LLMs, tools, humans, and even a combination of them.(右上)代理可以通过对话来解决任务。(右下)该框架支持许多其他复杂的对话模式。

设计、实施和优化可以充分利用大型语言模型 (LLM) 潜力的工作流程需要付出大量的努力和专业知识。自动化这些工作流程具有巨大的价值。随着开发人员开始创建日益复杂的基于 LLM 的应用程序,工作流程将不可避免地变得更加复杂。此类工作流程的潜在设计空间可能巨大且复杂,从而加大了编排具有强大性能的最佳工作流程的挑战。

AutoGen 是一个用于简化 LLM 工作流程的编排、优化和自动化的框架。它提供可定制和可对话的代理,利用最先进的 LLM(如 GPT-4)的最强功能,同时通过与人员和工具集成以及通过自动聊天在多个代理之间进行对话来解决其局限性

使用 AutoGen,构建复杂的多代理对话系统可以归结为:

  • 定义一组具有专门功能和角色的代理。
  • 定义代理之间的交互行为,即当一个代理收到另一个代理的消息时要回复什么。

这两个步骤都是直观且模块化的,使得这些代理可重用和可组合。例如,要构建一个基于代码的问答系统,可以设计代理及其交互,如图 2 所示。这样的系统可以将供应链等应用程序中所需的手动交互数量 减少到 3 -10倍。使用 AutoGen 可以将编码工作量减少 4 倍以上。

图 2.供应链优化中基于代码的问答的示例工作流程(在新选项卡中打开)。Commander 接收用户问题并与 Writer 和 Safeguard 进行协调。Writer 编写代码和解释,Safeguard 确保安全,Commander 执行代码。如果出现问题,可以重复该过程直至解决。阴影圆圈表示可以重复多次的步骤。

有能力、可交谈且可定制的代理——集成LLMs, humans, and tools

AutoGen 代理具有由LLMs, humans, and tools或这些元素的组合启用的功能。例如:  

  • 人们可以通过高级推理功能(例如,通过推理参数调整来优化性能)轻松配置代理中 LLM 的使用和角色 :https://github.com/microsoft/autogen/blob/main/notebook/agentchat_groupchat_research.ipynb
  • 人类智能和监督可以通过具有不同参与级别和模式的代理来实现(例如,使用 GPT-4 + 多个人类用户自动解决任务) : https://github.com/microsoft/autogen/blob/main/notebook/agentchat_auto_feedback_from_code_execution.ipynb
  • 这些代理对 LLM 驱动的代码/函数执行具有本机支持(例如,通过代码生成、执行和调试来自动解决任务),使用提供的工具作为函数。 : https://github.com/microsoft/autogen/blob/main/notebook/agentchat_auto_feedback_from_code_execution.ipynb

使用 AutoGen 内置代理的一种直接方法是调用助理代理和用户代理之间的自动聊天。举个例子(图 3),人们可以轻松构建 ChatGPT + 代码解释器 + 插件的增强版本,具有可定制的自动化程度,可在自定义环境中使用并可嵌入更大的系统中。也很容易扩展它们的行为以支持不同的应用场景,例如基于过去的交互添加个性化和适应性(例如,自动持续学习,传授座席新技能)。

图 3. AutoGen 的用户代理和助理代理可用于构建 ChatGPT + 代码解释器 + 插件的增强版本。助理代理扮演像 Bing Chat 这样的 AI 助手的角色。用户代理扮演用户的角色,模拟用户的代码执行等行为。AutoGen 可以自动执行两个代理之间的聊天,同时允许人工反馈或干预。用户代理无缝地与人类互动并在适当的时候使用工具。

Agent based on conversation-centric的设计有很多好处,包括:

  • 自然地处理歧义、反馈、进展和协作。
  • 实现有效的编码相关任务,例如使用工具来进行来回故障排除。
  • 允许用户通过聊天中的代理无缝选择加入或选择退出。
  • 通过多位专家的合作实现集体目标。

AutoGen 支持自动聊天和多样化的通信模式,可以轻松编排复杂、动态的工作流程并进行多功能性实验。

图 4 (下图所示)展示了一种新游戏——对话式国际象棋,由 AutoGen 启用。

图 4. AutoGen 支持的新应用程序示例:对话式国际象棋。它可以支持各种场景,因为每个玩家都可以是 LLM-empowered AI、human或两者的混合体。它允许玩家创造性地表达自己的棋子,例如使用笑话、模因参考和角色扮演,使国际象棋游戏对玩家和观察者来说都更具娱乐性。

代码连接:https://github.com/microsoft/flaml/blob/main/notebook/autogen_agentchat_chess.ipynb

图 5(下图所示) 说明 AutoGen 如何支持群组聊天使用另一个称为“GroupChatManager”的特殊代理在多个Agent之间进行通信。

图 5. AutoGen 如何启用动态群聊的概述解决任务:我们使用一个称为管理器的Agent,它重复以下三个步骤:选择一个发言者(在本例中为Bob),要求发言者做出响应,并将所选发言者的消息广播给所有其他代理。

代码连接:https://github.com/microsoft/autogen/blob/main/notebook/agentchat_groupchat.ipynb

AutoGen入门

微软提供了免费的包可供使用。

可以查看链接:AutoGen | AutoGenEnabling Next-Gen LLM Applications via Multi-Agent Conversation Frameworkicon-default.png?t=N7T8https://microsoft.github.io/autogen/

 要安装它,请运行

pip install pyautogen

您只需几行代码即可快速启用强大的体验:

# Auther : auserwn
# -*- codeing = utf-8 -*-
# @Time : 2023/10/11 13:54
# @Auther : auser
# @file : .py
# @software : PyCharm

import autogen

config_list = [
{
    "model":"gpt-3.5-turbo",
    "api_key":"your-apikey",
    "api_base":"https://api.chatanywhere.com.cn/v1"
}
]

llm_config = {"config_list":config_list,"seed":42}
user_proxy = autogen.UserProxyAgent(
    name="User_proxy",
    system_message="A human aadmin.",
    code_execution_config={"last_n_messages":2,"work_dir":"."},
    human_input_mode="TERMINATE"
)
coder = autogen.AssistantAgent(
    name="Coder",
    llm_config=llm_config
)
pm = autogen.AssistantAgent(
    name="Producer_manager",
    system_message="Creative in product ideas.",
    llm_config=llm_config,
)
groupchat = autogen.GroupChat(agents=[user_proxy,coder,pm],messages=[],max_round=12)
manager = autogen.GroupChatManager(groupchat=groupchat,llm_config=llm_config)

# user_proxy.initiate_chat(manager,message="Find a lastet paper about gpt-4 on arxiv and find it's potential appliacation in software")
user_proxy.initiate_chat(manager,message="Query finance news on yahoo.com,randomly pick one,scrape the article content,and form a post for writing a blog")

 生成输出:

D:\Anaconda\envs\myenv\python.exe E:/Text-to-sql/git/pergit_wangning/code/1007code/Agent-AutoGen/AutoGen-案例一-群聊.py
User_proxy (to chat_manager):

Query finance news on yahoo.com,randomly pick one,scrape the article content,and form a post for writing a blog

--------------------------------------------------------------------------------
Coder (to chat_manager):

# filename: finance_news_scraper.py

# Import necessary libraries
import requests
from bs4 import BeautifulSoup
import random

# Define the URL to scrape
url = "https://finance.yahoo.com/"

# Send a GET request to the URL
response = requests.get(url)

# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(response.content, "html.parser")

# Find all the article links on the page
article_links = soup.find_all("a", class_="js-content-viewer")

# Randomly select one of the article links
random_link = random.choice(article_links)

# Extract the URL of the selected article
article_url = random_link["href"]

# Send a GET request to the article URL
article_response = requests.get(article_url)

# Parse the HTML content of the article using BeautifulSoup
article_soup = BeautifulSoup(article_response.content, "html.parser")

# Find the article title and content
article_title = article_soup.find("h1").get_text()
article_content = article_soup.find("div", class_="caas-body").get_text()

# Print the article title and content
print("Title: ", article_title)
print("Content: ", article_content)

# Form a post for writing a blog
post = f"Check out this finance news article I found on Yahoo: {article_title} {article_url}. Here's a summary: {article_content}"

# Print the post
print("Post: ", post)

# TERMINATE

--------------------------------------------------------------------------------
Producer_manager (to chat_manager):

This code scrapes the Yahoo Finance website for the latest news and randomly selects one article to extract the title and content. The code then forms a post for writing a blog with the article title, URL, and a summary of the content. Here's an example of what the output could look like:

Title:  Dow Jones Futures: Market Rally Faces Key Test; Tesla, Apple, Microsoft, Facebook In Focus
Content:  Dow Jones futures: The stock market rally faces a key test, with Tesla, Apple, Microsoft and Facebook in focus. The Dow Jones, S&P 500 and Nasdaq composite are all near record highs. But the stock market rally is facing some key tests. Tesla stock is trying to hold above a key level. Apple, Microsoft and Facebook are all near buy points. Meanwhile, the Federal Reserve is expected to signal a shift in monetary policy. 

Post: Check out this finance news article I found on Yahoo: Dow Jones Futures: Market Rally Faces Key Test; Tesla, Apple, Microsoft, Facebook In Focus https://finance.yahoo.com/news/dow-jones-futures-market-rally-233000556.html. Here's a summary: Dow Jones futures: The stock market rally faces a key test, with Tesla, Apple, Microsoft and Facebook in focus. The Dow Jones, S&P 500 and Nasdaq composite are all near record highs. But the stock market rally is facing some key tests. Tesla stock is trying to hold above a key level. Apple, Microsoft and Facebook are all near buy points. Meanwhile, the Federal Reserve is expected to signal a shift in monetary policy.

--------------------------------------------------------------------------------

>>>>>>>> USING AUTO REPLY...
User_proxy (to chat_manager):



--------------------------------------------------------------------------------

>>>>>>>> USING AUTO REPLY...
User_proxy (to chat_manager):



--------------------------------------------------------------------------------

>>>>>>>> USING AUTO REPLY...
User_proxy (to chat_manager):



--------------------------------------------------------------------------------

>>>>>>>> USING AUTO REPLY...
User_proxy (to chat_manager):



--------------------------------------------------------------------------------

>>>>>>>> USING AUTO REPLY...
User_proxy (to chat_manager):



--------------------------------------------------------------------------------

>>>>>>>> USING AUTO REPLY...
User_proxy (to chat_manager):



--------------------------------------------------------------------------------

>>>>>>>> USING AUTO REPLY...
User_proxy (to chat_manager):



--------------------------------------------------------------------------------

>>>>>>>> USING AUTO REPLY...
User_proxy (to chat_manager):



--------------------------------------------------------------------------------

>>>>>>>> USING AUTO REPLY...
User_proxy (to chat_manager):



--------------------------------------------------------------------------------

进程已结束,退出代码0

微软还提供了其他使用案例:

AutoGen - Automated Multi Agent Chat | AutoGenAutoGen offers conversable agents powered by LLM, tool or human, which can be used to perform tasks collectively via automated chat. This framework allows tool use and human participation via multi-agent conversation.icon-default.png?t=N7T8https://microsoft.github.io/autogen/docs/Examples/AutoGen-AgentChat/

猜你喜欢

转载自blog.csdn.net/wangning0714/article/details/133914045