首页
开源项目
搜索 TinyTools
AutoGen多智能体AI应用程序的框架
48.9k
在线演示
Github仓库
Gitee仓库
# AutoGen **AutoGen** 是一个用于创建可自主行动或与人类一起工作的多智能体 AI 应用程序的框架。 ## 安装 AutoGen 需要 **Python 3.10 或更高版本**。 ```bash # 从扩展程序安装 AgentChat 和 OpenAI 客户端 pip install -U "autogen-agentchat" "autogen-ext[openai]" ``` 当前稳定版本可在 [releases](https://github.com/microsoft/autogen/releases) 中找到。如果您要从 AutoGen v0.2 升级,请参阅 [迁移指南](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/migration-guide.html),了解如何更新代码和配置的详细说明。 ```bash # 安装 AutoGen Studio 以实现无代码 GUI pip install -U "autogenstudio" ``` ## 快速入门 ### Hello World 使用 OpenAI 的 GPT-4o 模型创建一个助手代理。请参阅[其他支持的模型](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/tutorial/models.html)。 ```python 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 服务器的网页浏览助手代理。 ```python # First run `npm install -g @playwright/mcp@latest` to install the MCP server. 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, # For multiple MCP servers, put them in a list. 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”创建基本的多代理编排设置。 ```python 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 文档](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/index.html)。 ### AutoGen Studio 使用 AutoGen Studio 无需编写代码即可创建原型并运行多代理工作流。 ```bash # Run AutoGen Studio on http://localhost:8080 autogenstudio ui --port 8080 --appdir ./my-app ``` ## 为什么使用 AutoGen?  AutoGen 生态系统提供创建 AI 代理(尤其是多代理工作流)所需的一切:框架、开发者工具和应用程序。 该框架采用分层且可扩展的设计。各层职责划分清晰,并构建于下一层之上。这种设计使您能够在不同的抽象级别(从高级 API 到低级组件)使用该框架。 - [核心 API](./python/packages/autogen-core/) 实现了消息传递、事件驱动代理以及本地和分布式运行时,以实现灵活性和强大功能。它还支持 .NET 和 Python 的跨语言支持。 - [AgentChat API](./python/packages/autogen-agentchat/) 实现了一个更简单但更完善的 API,用于快速原型设计。此 API 构建于核心 API 之上,与 v0.2 用户熟悉的 API 最为接近,并支持常见的多代理模式,例如双代理聊天或群聊。 - [扩展 API](./python/packages/autogen-ext/) 支持第一方和第三方扩展,持续扩展框架功能。它支持 LLM 客户端(例如 OpenAI、AzureOpenAI)的特定实现,以及代码执行等功能。 该生态系统还支持两个重要的开发者工具:  - [AutoGen Studio](./python/packages/autogen-studio/) 提供无需代码的 GUI 界面,用于构建多智能体应用程序。 - [AutoGen Bench](./python/packages/agbench/) 提供一套用于评估智能体性能的基准测试套件。 您可以使用 AutoGen 框架和开发者工具为您的领域创建应用程序。例如,[Magentic-One](./python/packages/magentic-one-cli/) 是一个先进的多智能体团队,它使用 AgentChat API 和 Extensions API 构建,可以处理各种需要网页浏览、代码执行和文件处理的任务。 使用 AutoGen,您可以加入并贡献一个蓬勃发展的生态系统。我们每周都会举办办公时间,并与维护人员和社区成员进行交流。我们还拥有一个 [Discord 服务器](https://aka.ms/autogen-discord) 用于实时聊天,一个 GitHub 讨论区用于问答,以及一个博客用于教程和更新。 ## 下一步去哪里?
| | [](./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/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/) | NuGet 契约 [](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](./CONTRIBUTING.md) 获取入门指南。我们欢迎各种贡献,包括错误修复、新功能和文档改进。加入我们的社区,帮助我们改进 AutoGen! 有疑问?请查看我们的 [常见问题解答 (FAQ)](./FAQ.md) 获取常见问题的解答。如果您找不到所需内容,欢迎在我们的 [GitHub 讨论区](https://github.com/microsoft/autogen/discussions) 中提问,或加入我们的 [Discord 服务器](https://aka.ms/autogen-discord) 获取实时支持。您也可以阅读我们的 [博客](https://devblogs.microsoft.com/autogen/) 获取最新资讯。 ## 法律声明 Microsoft 及其所有贡献者根据 [知识共享署名 4.0 国际公共许可证](https://creativecommons.org/licenses/by/4.0/legalcode) 授予您使用本存储库中 Microsoft 文档及其他内容的许可, 请参阅 [LICENSE](LICENSE) 文件;并根据 [MIT 许可证](https://opensource.org/licenses/MIT) 授予您使用本存储库中任何代码的许可, 请参阅 [LICENSE-CODE](LICENSE-CODE) 文件。 本文档中引用的 Microsoft、Windows、Microsoft Azure 和/或其他 Microsoft 产品和服务, 可能是 Microsoft 在美国和/或其他国家/地区的商标或注册商标。 本项目的许可证不授予您使用任何 Microsoft 名称、徽标或商标的权利。 Microsoft 的通用商标指南可在
找到。 隐私信息请访问
Microsoft 及所有贡献者保留所有其他权利,包括其各自的版权、专利或商标,无论是通过暗示、禁止反言还是其他方式。
tabler/tabler is licensed under the
MIT License
A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.
Permissions
Commercial use
Modification
Distribution
Private use
Limitations
Liability
Warranty
Conditions
License and copyright notice