欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > 多智能体框架

多智能体框架

2025/2/26 8:56:36 来源:https://blog.csdn.net/star1210644725/article/details/145865774  浏览:    关键词:多智能体框架

多个不同的角色的Agent,共同完成一份复杂的工作。由一个统筹管理的智能体,自主规划多个智能体分别做什么,以及执行的顺序。

agent 应该包含的属性

执行特定任务

根据其角色和目标做出决策

能够使用工具来实现目标

与其他代理沟通和协作

保留互动记忆

在允许的情况下委派任务

如何协作是关键

  1. 条件自主:通过编码,顺序执行。
  2. 高度自主:能够自行决定不同角色Agent的是否要执行,以及执行顺序。

主要关注的点:

1、自主性

2、开发人员能够控制的精度 (可编码改造)

一、汇总

特性

AutoGen

agentScope

Swarm

CrewAI

LangGraph

时间 & star

2023.05

star 36.4k

2024.02

star 5.6k

2024.10

star 17.2k

2024年

star 22.9k

2023.01

star 7.5k

框架类型

对话智能体

角色智能体

角色智能体

角色智能体

基于图的智能体

自主性

高度自主

条件自主

条件自主

高度自主

条件自主

协作

集中式群聊

群聊

任务传递

具有角色和目标的自主智能体

基于条件的循环图

执行

由专用智能体管理

任务传递

动态委托,但可以定义层次化流程

所有智能体都可以执行

适用场景

原型设计

从开发到生产

详细控制场景

二、已有多智能体框架

2.1 AutoGen (微软)

2023.05

star 36.4k

GitHub - microsoft/autogen: A programming framework for agentic AI 🤖 PyPi: autogen-agentchat Discord: https://aka.ms/autogen-discord Office Hour: https://aka.ms/autogen-officehour

AutoGen 专注于对话智能体,提供对话作为多智能体协作的能力。它的设计理念围绕着模拟小组讨论,智能体发送和接收消息以启动或继续对话。

AutoGen 是一个用于构建 AI 代理系统的开源框架。它简化了事件驱动、分布式、可扩展且具有弹性的代理应用程序的创建。它允许您快速构建 AI 代理协作并自主或在人工监督下执行任务的系统。

autoGen 中定义的多智能体的模式

并发:通过传递消息给多种智能体。来执行

Concurrent Agents — AutoGen

顺序工作流,按顺序执行

Sequential Workflow — AutoGen

群聊:多个智能体,还有一个群聊管理器,群聊管理器,决定谁来发言。

群聊是一种设计模式,其中一组代理共享一个共同的消息线程:他们都订阅并发布同一主题。每个参与代理都专门负责一项特定任务,例如在协作写作任务中担任作家、插画师和编辑。您还可以添加一个代理来代表人类用户,以便在需要时帮助指导代理。在群聊中,参与者轮流发布消息,并且该过程是连续的——每次只有一个代理在工作。在后台,轮流顺序由群聊管理器代理维护,该代理在收到消息后选择下一个发言的代理。选择下一个代理的具体算法可能因您的应用程序要求而异。通常,使用循环算法或具有 LLM 模型的选择器。群聊可用于将复杂任务动态分解为较小的任务,这些任务可以由具有明确角色的专门代理来处理。还可以将群聊嵌套成层次结构,每个参与者都是一个递归群聊。

Group Chat — AutoGen

多智能体辩论

Multi-Agent Debate — AutoGen

2.2 AgentScope

2024.02

star 5.6k

文档:

AgentScope 文档 — AgentScope 文档

实现狼人杀的示例代码

样例:狼人杀游戏 — AgentScope 文档

https://img.alicdn.com/imgextra/i3/O1CN01n2Q2tR1aCFD2gpTdu_!!6000000003293-1-tps-960-482.gif

2.3 Swarm (openAI)

2024.10

star 17.2k

Swarm框架本身并不具备自我感知任务变化的能力。它依赖于开发者定义的智能体(Agent)和交接(Handoff)机制来管理和协调任务。智能体可以封装指令和工具,并能够独立执行任务或与其他智能体协作。当一个智能体遇到无法独立处理的任务时,它可以通过交接机制将任务传递给另一个智能体。这种设计允许智能体之间根据任务需求和能力匹配进行动态调整,确保任务能够以最高效的方式完成,但这需要开发者预先定义智能体的行为和交接逻辑。因此,Swarm框架的灵活性和适应性取决于开发者如何设计和实现智能体及其交互,而不是框架自身具备感知任务变化的能力。

swarm 集成了langchain的工具

示例:

from swarm import Agent# 定义一个函数用于处理指定商品的退款
def process_refund(item_id, reason="NOT SPECIFIED"):"""
    处理商品退款。    参数:
        item_id (str): 要退款的商品唯一标识。
        reason (str): 退款原因,默认值为 "NOT SPECIFIED"。    返回:
        str: 表示退款成功的消息。
    """print(f"[mock] Refunding item {item_id} because {reason}...")return "Success!"# 定义一个函数用于对用户的购物车应用折扣
def apply_discount():"""
    对用户的购物车应用折扣。    返回:
        str: 表示折扣成功应用的消息。
    """print("[mock] Applying discount...")return "Applied discount of 11%"# 创建一个分诊代理,用于将用户请求分配给合适的代理
triage_agent = Agent(
    name="Triage Agent",
    instructions="判断哪个代理最适合处理用户的请求,并将对话转移到该代理。",
)# 创建一个销售代理,用于处理与销售相关的用户请求
sales_agent = Agent(
    name="Sales Agent",
    instructions="对销售蜜蜂表现出极大的热情。",
)# 创建一个退款代理,用于处理与退款相关的用户请求
refunds_agent = Agent(
    name="Refunds Agent",
    instructions=("帮助用户处理退款。如果退款原因是价格太贵,提供用户一个退款代码。""如果用户坚持,则处理退款。"),
    functions=[process_refund, apply_discount],
)# 定义一个函数,如果用户提到的主题不在当前代理的职责范围内,则调用该函数将请求转回分诊代理
def transfer_back_to_triage():"""
    当用户的请求超出当前代理的处理范围时调用此函数,将请求转回分诊代理。    返回:
        Agent: 分诊代理实例。
    """return triage_agent# 定义一个函数,用于将请求转移到销售代理
def transfer_to_sales():"""
    将请求转移到销售代理。    返回:
        Agent: 销售代理实例。
    """return sales_agent# 定义一个函数,用于将请求转移到退款代理
def transfer_to_refunds():"""
    将请求转移到退款代理。    返回:
        Agent: 退款代理实例。
    """return refunds_agent# 为分诊代理添加转移到销售和退款代理的功能
triage_agent.functions = [transfer_to_sales, transfer_to_refunds]# 为销售代理添加转移回分诊代理的功能
sales_agent.functions.append(transfer_back_to_triage)# 为退款代理添加转移回分诊代理的功能
refunds_agent.functions.append(transfer_back_to_triage)

2.4 CrewAI

2024年

star 22.9k

文档:Introduction - CrewAI

CrewAI 是一个用于协调角色扮演、自主 AI 代理的框架。它使代理能够无缝协作,通过协作智能处理复杂任务。

crewAI中支持的任务执行顺序,顺序执行,分层执行

串行执行示例

from crewai import Crew, Process, Agent, Task, TaskOutput, CrewOutput# Define your agents
researcher = Agent(
  role='Researcher',
  goal='Conduct foundational research',
  backstory='An experienced researcher with a passion for uncovering insights'
)
analyst = Agent(
  role='Data Analyst',
  goal='Analyze research findings',
  backstory='A meticulous analyst with a knack for uncovering patterns'
)
writer = Agent(
  role='Writer',
  goal='Draft the final report',
  backstory='A skilled writer with a talent for crafting compelling narratives'
)# Define your tasks
research_task = Task(
  description='Gather relevant data...', 
  agent=researcher, 
  expected_output='Raw Data'
)
analysis_task = Task(
  description='Analyze the data...', 
  agent=analyst, 
  expected_output='Data Insights'
)
writing_task = Task(
  description='Compose the report...', 
  agent=writer, 
  expected_output='Final Report'
)# Form the crew with a sequential process
report_crew = Crew(
  agents=[researcher, analyst, writer],# 任务的顺序
  tasks=[research_task, analysis_task, writing_task],# 任务的执行顺序 顺序执行
  process=Process.sequential
)# Execute the crew
result = report_crew.kickoff()# Accessing the type-safe output
task_output: TaskOutput = result.tasks[0].output
crew_output: CrewOutput = result.output

分层执行示例

from langchain_openai import ChatOpenAI
from crewai import Crew, Process, Agent# Agents are defined with attributes for backstory, cache, and verbose mode
researcher = Agent(
    role='Researcher',
    goal='Conduct in-depth analysis',
    backstory='Experienced data analyst with a knack for uncovering hidden trends.',
    cache=True,
    verbose=False,
    # tools=[]  # This can be optionally specified; defaults to an empty list
    use_system_prompt=True,  # Enable or disable system prompts for this agent
    max_rpm=30,  # Limit on the number of requests per minute
    max_iter=5  # Maximum number of iterations for a final answer
)
writer = Agent(
    role='Writer',
    goal='Create engaging content',
    backstory='Creative writer passionate about storytelling in technical domains.',
    cache=True,
    verbose=False,
    # tools=[]  # Optionally specify tools; defaults to an empty list
    use_system_prompt=True,  # Enable or disable system prompts for this agent
    max_rpm=30,  # Limit on the number of requests per minute
    max_iter=5  # Maximum number of iterations for a final answer
)# Establishing the crew with a hierarchical process and additional configurations
project_crew = Crew(
    tasks=[...],  # Tasks to be delegated and executed under the manager's supervision
    agents=[researcher, writer],
    manager_llm=ChatOpenAI(temperature=0, model="gpt-4"),  # Mandatory if manager_agent is not set
    process=Process.hierarchical,  # Specifies the hierarchical management approach
    respect_context_window=True,  # Enable respect of the context window for tasks
    memory=True,  # Enable memory usage for enhanced task execution
    manager_agent=None,  # Optional: explicitly set a specific agent as manager instead of the manager_llm
    planning=True,  # Enable planning feature for pre-execution strategy
)

三、超级经典的案例-最近火热的deep-research

二月份初,从openai公布了deep-research开始,deep-research就开始变得非常火热。其实这个就是一个非常典型的多智能体协作的案例。定义了web查询智能体、代码执行智能体、文件检索智能体、写作智能体,还有规划问题的智能体。

auto-deep-research

特点

Auto-Deep-Research 是基于 AutoAgent多智能体框架构建的deep research产品。

评测效果

在通用AI助手评测GAIA中位列全球第三,是开源方案中的最优解。

多智能体框架

https://github.com/HKUDS/AutoAgent

系统采用模块化多Agent架构,通过Orchestrator Agent动态调度任务

模块功能技术特性
Web Agent深度网络搜索与文献抓取支持浏览器Cookies导入,突破学术资源访问限制
Coding Agent代码生成与优化(Python/R脚本调试、可视化优化、容器化部署)实现自动化编程与调试,支持Docker一键部署
Local File Agent多格式文件解析(PDF/CSV/XLSX等12种格式)自动转换为Markdown统一处理,支持200+页PDF深度解析

agent示例

def get_filesurfer_agent(model: str = "gpt-4o", **kwargs):def handle_mm_func(tool_name, tool_args):return f"After using tool {tool_name}({tool_args}), I have opened the image I want to see and prepared a question according to the image. Please answer the question based on the image."def instructions(context_variables):file_env: RequestsMarkdownBrowser = context_variables.get("file_env", None)assert file_env is not None, "file_env is required"return \
f"""
You are a file surfer agent that can handle local files.You can only access the files in the folder `{file_env.docker_workplace}` and when you want to open a file, you should use absolute path from root like `{file_env.docker_workplace}/...`.Note that `open_local_file` can read a file as markdown text and ask questions about it. And `open_local_file` can handle the following file extensions: [".html", ".htm", ".xlsx", ".pptx", ".wav", ".mp3", ".flac", ".pdf", ".docx"], and all other types of text files. But IT DOES NOT HANDLE IMAGES, you should use `visual_question_answering` to see the image. If the converted markdown text has more than 1 page, you can use `page_up`, `page_down`, `find_on_page_ctrl_f`, `find_next` to navigate through the pages.When you think you have completed the task the `System Triage Agent` asked you to do, you should use `transfer_back_to_triage_agent` to transfer the conversation back to the `System Triage Agent`. And you should not stop to try to solve the user's request by transferring to `System Triage Agent` only until the task is completed.If you are unable to open the file, you can transfer the conversation back to the `System Triage Agent`, and let the `Coding Agent` try to solve the problem by coding.
"""tool_list = [open_local_file, page_up_markdown, page_down_markdown, find_on_page_ctrl_f, find_next, visual_question_answering]return Agent(name="File Surfer Agent",model=model, instructions=instructions,functions=tool_list,handle_mm_func=handle_mm_func,tool_choice = "required", parallel_tool_calls = False)

优势

在多智能体框架下,有非常好的扩展性,只需要定义和实现一些具有特色功能的agent,就能扩展功能。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词