OA0 = Omni AI 0
OA0 是一个探索 AI 的论坛
现在注册
已注册用户请  登录
OA0  ›  代码  ›  AutoGen — 多 Agent 协作框架

AutoGen — 多 Agent 协作框架

 
  fullstack ·  2026-02-28 00:42:39 · 3 次点击  · 0 条评论  

AutoGen Logo [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/cloudposse.svg?style=social&label=关注%20%40pyautogen)](https://twitter.com/pyautogen) [![LinkedIn](https://img.shields.io/badge/LinkedIn-公司?style=flat&logo=linkedin&logoColor=white)](https://www.linkedin.com/company/105812540) [![Discord](https://img.shields.io/badge/discord-聊天-green?logo=discord)](https://aka.ms/autogen-discord) [![文档](https://img.shields.io/badge/文档-AutoGen-blue?logo=read-the-docs)](https://microsoft.github.io/autogen/) [![博客](https://img.shields.io/badge/博客-AutoGen-blue?logo=blogger)](https://devblogs.microsoft.com/autogen/)

AutoGen

AutoGen 是一个用于创建多智能体 AI 应用的框架,这些智能体可以自主行动或与人类协同工作。

重要提示: 如果你是 AutoGen 的新用户,请查看 Microsoft Agent Framework。AutoGen 仍将得到维护,并继续接收错误修复和关键安全补丁。请阅读我们的公告

安装

AutoGen 需要 Python 3.10 或更高版本

# 从扩展中安装 AgentChat 和 OpenAI 客户端
pip install -U "autogen-agentchat" "autogen-ext[openai]"

当前稳定版本可在 发布页面 找到。如果你正在从 AutoGen v0.2 升级,请参考 迁移指南 获取更新代码和配置的详细说明。

# 安装 AutoGen Studio 以获得无代码 GUI
pip install -U "autogenstudio"

快速开始

以下示例需要调用 OpenAI API,因此你需要先创建账户并导出你的密钥:export OPENAI_API_KEY="sk-..."

Hello World

使用 OpenAI 的 GPT-4o 模型创建一个助手智能体。查看 其他支持的模型

import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient

async def main() -> None:
    model_client = OpenAIChatCompletionClient(model="gpt-4.1")
    agent = AssistantAgent("assistant", model_client=model_client)
    print(await agent.run(task="Say 'Hello World!'"))
    await model_client.close()

asyncio.run(main())

MCP 服务器

创建一个使用 Playwright MCP 服务器的网页浏览助手智能体。

# 首先运行 `npm install -g @playwright/mcp@latest` 来安装 MCP 服务器。
import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.tools.mcp import McpWorkbench, StdioServerParams


async def main() -> None:
    model_client = OpenAIChatCompletionClient(model="gpt-4.1")
    server_params = StdioServerParams(
        command="npx",
        args=[
            "@playwright/mcp@latest",
            "--headless",
        ],
    )
    async with McpWorkbench(server_params) as mcp:
        agent = AssistantAgent(
            "web_browsing_assistant",
            model_client=model_client,
            workbench=mcp, # 对于多个 MCP 服务器,将它们放在一个列表中。
            model_client_stream=True,
            max_tool_iterations=10,
        )
        await Console(agent.run_stream(task="Find out how many contributors for the microsoft/autogen repository"))


asyncio.run(main())

警告:只连接到受信任的 MCP 服务器,因为它们可能会在你的本地环境中执行命令或暴露敏感信息。

多智能体编排

你可以使用 AgentTool 来创建一个基础的多智能体编排设置。

import asyncio

from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.tools import AgentTool
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient


async def main() -> None:
    model_client = OpenAIChatCompletionClient(model="gpt-4.1")

    math_agent = AssistantAgent(
        "math_expert",
        model_client=model_client,
        system_message="You are a math expert.",
        description="A math expert assistant.",
        model_client_stream=True,
    )
    math_agent_tool = AgentTool(math_agent, return_value_as_last_message=True)

    chemistry_agent = AssistantAgent(
        "chemistry_expert",
        model_client=model_client,
        system_message="You are a chemistry expert.",
        description="A chemistry expert assistant.",
        model_client_stream=True,
    )
    chemistry_agent_tool = AgentTool(chemistry_agent, return_value_as_last_message=True)

    agent = AssistantAgent(
        "assistant",
        system_message="You are a general assistant. Use expert tools when needed.",
        model_client=model_client,
        model_client_stream=True,
        tools=[math_agent_tool, chemistry_agent_tool],
        max_tool_iterations=10,
    )
    await Console(agent.run_stream(task="What is the integral of x^2?"))
    await Console(agent.run_stream(task="What is the molecular weight of water?"))


asyncio.run(main())

关于更高级的多智能体编排和工作流,请阅读 AgentChat 文档

AutoGen Studio

使用 AutoGen Studio 无需编写代码即可原型化和运行多智能体工作流。

# 在 http://localhost:8080 上运行 AutoGen Studio
autogenstudio ui --port 8080 --appdir ./my-app

为什么选择 AutoGen?

AutoGen Landing

AutoGen 生态系统提供了创建 AI 智能体(尤其是多智能体工作流)所需的一切——框架、开发工具和应用程序。

框架采用分层和可扩展的设计。各层职责明确,并构建在底层之上。这种设计使你能够在不同抽象级别使用框架,从高级 API 到底层组件。

  • 核心 API 实现了消息传递、事件驱动的智能体以及本地和分布式运行时,以提供灵活性和强大功能。它还支持 .NET 和 Python 的跨语言支持。
  • AgentChat API 实现了一个更简单但具有特定风格的 API,用于快速原型设计。此 API 构建在核心 API 之上,最接近 v0.2 用户熟悉的内容,并支持常见的多智能体模式,如双智能体聊天或群聊。
  • 扩展 API 支持持续扩展框架能力的第一方和第三方扩展。它支持 LLM 客户端的特定实现(例如 OpenAI、AzureOpenAI)以及代码执行等功能。

该生态系统还支持两个重要的开发工具

AutoGen Studio Screenshot
  • AutoGen Studio 提供了一个用于构建多智能体应用程序的无代码 GUI。
  • AutoGen Bench 提供了一个用于评估智能体性能的基准测试套件。

你可以使用 AutoGen 框架和开发工具为你的领域创建应用程序。例如,Magentic-One 是一个使用 AgentChat API 和 Extensions API 构建的最先进的多智能体团队,可以处理需要网页浏览、代码执行和文件处理的各种任务。

使用 AutoGen,你将加入并贡献于一个蓬勃发展的生态系统。我们每周举办与维护者和社区的办公时间和讲座。我们还有一个用于实时聊天的 Discord 服务器、用于问答的 GitHub Discussions 以及一个发布教程和更新的博客。

下一步该做什么?

| | [![Python](https://img.shields.io/badge/AutoGen-Python-blue?logo=python&logoColor=white)](./python) | [![.NET](https://img.shields.io/badge/AutoGen-.NET-green?logo=.net&logoColor=white)](./dotnet) | [![Studio](https://img.shields.io/badge/AutoGen-Studio-purple?logo=visual-studio&logoColor=white)](./python/packages/autogen-studio) | | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | 安装 | [![安装](https://img.shields.io/badge/安装-blue)](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/installation.html) | [![安装](https://img.shields.io/badge/安装-green)](https://microsoft.github.io/autogen/dotnet/dev/core/installation.html) | [![安装](https://img.shields.io/badge/安装-purple)](https://microsoft.github.io/autogen/stable/user-guide/autogenstudio-user-guide/installation.html) | | 快速开始 | [![快速开始](https://img.shields.io/badge/快速开始-blue)](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/quickstart.html#) | [![快速开始](https://img.shields.io/badge/快速开始-green)](https://microsoft.github.io/autogen/dotnet/dev/core/index.html) | [![使用](https://img.shields.io/badge/快速开始-purple)](https://microsoft.github.io/autogen/stable/user-guide/autogenstudio-user-guide/usage.html#) | | 教程 | [![教程](https://img.shields.io/badge/教程-blue)](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/tutorial/index.html) | [![教程](https://img.shields.io/badge/教程-green)](https://microsoft.github.io/autogen/dotnet/dev/core/tutorial.html) | [![使用](https://img.shields.io/badge/教程-purple)](https://microsoft.github.io/autogen/stable/user-guide/autogenstudio-user-guide/usage.html#) | | API 参考 | [![API](https://img.shields.io/badge/文档-blue)](https://microsoft.github.io/autogen/stable/reference/index.html#) | [![API](https://img.shields.io/badge/文档-green)](https://microsoft.github.io/autogen/dotnet/dev/api/Microsoft.AutoGen.Contracts.html) | [![API](https://img.shields.io/badge/文档-purple)](https://microsoft.github.io/autogen/stable/user-guide/autogenstudio-user-guide/usage.html) | | 包 | [![PyPi autogen-core](https://img.shields.io/badge/PyPi-autogen--core-blue?logo=pypi)](https://pypi.org/project/autogen-core/)
[![PyPi autogen-agentchat](https://img.shields.io/badge/PyPi-autogen--agentchat-blue?logo=pypi)](https://pypi.org/project/autogen-agentchat/)
[![PyPi autogen-ext](https://img.shields.io/badge/PyPi-autogen--ext-blue?logo=pypi)](https://pypi.org/project/autogen-ext/) | [![NuGet Contracts](https://img.shields.io/badge/NuGet-Contracts-green?logo=nuget)](https://www.nuget.org/packages/Microsoft.AutoGen.Contracts/)
[![NuGet Core](https://img.shields.io/badge/NuGet-Core-green?logo=nuget)](https://www.nuget.org/packages/Microsoft.AutoGen.Core/)
[![NuGet Core.Grpc](https://img.shields.io/badge/NuGet-Core.Grpc-green?logo=nuget)](https://www.nuget.org/packages/Microsoft.AutoGen.Core.Grpc/)
[![NuGet RuntimeGateway.Grpc](https://img.shields.io/badge/NuGet-RuntimeGateway.Grpc-green?logo=nuget)](https://www.nuget.org/packages/Microsoft.AutoGen.RuntimeGateway.Grpc/) | [![PyPi autogenstudio](https://img.shields.io/badge/PyPi-autogenstudio-purple?logo=pypi)](https://pypi.org/project/autogenstudio/) |

有兴趣贡献吗?请参阅 CONTRIBUTING.md 了解如何开始的指南。我们欢迎各种形式的贡献,包括错误修复、新功能和文档改进。加入我们的社区,帮助我们让 AutoGen 变得更好!

有问题吗?查看我们的 常见问题解答 (FAQ) 以获取常见问题的答案。如果你没有找到所需内容,请随时在我们的 GitHub Discussions 中提问,或加入我们的 Discord 服务器 获取实时支持。你也可以阅读我们的博客获取更新。

法律声明

Microsoft 和任何贡献者根据 知识共享署名 4.0 国际公共许可证 授予你本存储库中 Microsoft 文档和其他内容的许可证,请参阅 LICENSE 文件,并根据 MIT 许可证 授予你存储库中任何代码的许可证,请参阅 LICENSE-CODE 文件。

文档中引用的 Microsoft、Windows、Microsoft Azure 和/或其他 Microsoft 产品和服务可能是 Microsoft 在美国和/或其他国家/地区的商标或注册商标。本项目的许可证不授予你使用任何 Microsoft 名称、徽标或商标的权利。Microsoft 的一般商标指南可在 http://go.microsoft.com/fwlink/?LinkID=254653 找到。

隐私信息可在 https://go.microsoft.com/fwlink/?LinkId=521839 找到。

Microsoft 和任何贡献者保留所有其他权利,无论其各自的版权、专利或商标如何,无论是通过暗示、禁止反言或其他方式。

↑ 返回顶部 ↑

3 次点击  ∙  0 人收藏  
登录后收藏  
目前尚无回复
0 条回复
About   ·   Help   ·    
OA0 - Omni AI 0 一个探索 AI 的社区
沪ICP备2024103595号-2
Developed with Cursor