
[](https://twitter.com/pyautogen)
[](https://www.linkedin.com/company/105812540)
[](https://aka.ms/autogen-discord)
[](https://microsoft.github.io/autogen/)
[](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 生态系统提供了创建 AI 智能体(尤其是多智能体工作流)所需的一切——框架、开发工具和应用程序。
该框架采用分层和可扩展的设计。各层职责明确,并构建在底层之上。这种设计使你能够在不同抽象级别使用框架,从高级 API 到底层组件。
- 核心 API 实现了消息传递、事件驱动的智能体以及本地和分布式运行时,以提供灵活性和强大功能。它还支持 .NET 和 Python 的跨语言支持。
- AgentChat API 实现了一个更简单但具有特定风格的 API,用于快速原型设计。此 API 构建在核心 API 之上,最接近 v0.2 用户熟悉的内容,并支持常见的多智能体模式,如双智能体聊天或群聊。
- 扩展 API 支持持续扩展框架能力的第一方和第三方扩展。它支持 LLM 客户端的特定实现(例如 OpenAI、AzureOpenAI)以及代码执行等功能。
该生态系统还支持两个重要的开发工具:
你可以使用 AutoGen 框架和开发工具为你的领域创建应用程序。例如,Magentic-One 是一个使用 AgentChat API 和 Extensions API 构建的最先进的多智能体团队,可以处理需要网页浏览、代码执行和文件处理的各种任务。
使用 AutoGen,你将加入并贡献于一个蓬勃发展的生态系统。我们每周举办与维护者和社区的办公时间和讲座。我们还有一个用于实时聊天的 Discord 服务器、用于问答的 GitHub Discussions 以及一个发布教程和更新的博客。
下一步该做什么?
| | [](./python) | [](./dotnet) | [](./python/packages/autogen-studio) |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 安装 | [](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/installation.html) | [](https://microsoft.github.io/autogen/dotnet/dev/core/installation.html) | [](https://microsoft.github.io/autogen/stable/user-guide/autogenstudio-user-guide/installation.html) |
| 快速开始 | [](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/quickstart.html#) | [](https://microsoft.github.io/autogen/dotnet/dev/core/index.html) | [](https://microsoft.github.io/autogen/stable/user-guide/autogenstudio-user-guide/usage.html#) |
| 教程 | [](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/tutorial/index.html) | [](https://microsoft.github.io/autogen/dotnet/dev/core/tutorial.html) | [](https://microsoft.github.io/autogen/stable/user-guide/autogenstudio-user-guide/usage.html#) |
| API 参考 | [](https://microsoft.github.io/autogen/stable/reference/index.html#) | [](https://microsoft.github.io/autogen/dotnet/dev/api/Microsoft.AutoGen.Contracts.html) | [](https://microsoft.github.io/autogen/stable/user-guide/autogenstudio-user-guide/usage.html) |
| 包 | [](https://pypi.org/project/autogen-core/)
[](https://pypi.org/project/autogen-agentchat/)
[](https://pypi.org/project/autogen-ext/) | [](https://www.nuget.org/packages/Microsoft.AutoGen.Contracts/)
[](https://www.nuget.org/packages/Microsoft.AutoGen.Core/)
[](https://www.nuget.org/packages/Microsoft.AutoGen.Core.Grpc/)
[](https://www.nuget.org/packages/Microsoft.AutoGen.RuntimeGateway.Grpc/) | [](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 和任何贡献者保留所有其他权利,无论其各自的版权、专利或商标如何,无论是通过暗示、禁止反言或其他方式。
↑ 返回顶部 ↑