AG2AG2
AG2 是 AutoGen 停更后由社区接棒的续作。 仓库描述直接写着 "AG2 (formerly AutoGen)"。
README 也自述维护方:
"a dynamic group of volunteers from several organizations"
理解它必须先分清两条线:
| AG2(本条目) | Microsoft Agent Framework | |
|---|---|---|
| 维护方 | 社区(ag2ai) | 微软官方 |
| 与 AutoGen 关系 | 社区延续 / fork 后的独立演进 | 官方把 AutoGen + Semantic Kernel 合并继任 |
| 顶层 import | import ag2 | agent_framework / Microsoft.Agents.AI |
这也是本项目的 harness 分区当初的取舍依据。
它把 AutoGen 原仓库列为「明确不收对象」。
原仓 pushed_at 停在 2026-04-15,社区已转向 AG2。
收 AG2 而非 AutoGen,正是「跟着仍在更新的那支血脉走」。
AG2 is an open-source Python framework for building AI agents and coordinating multiple agents to solve tasks, with "agents capable of interacting with each other," broad LLM support, tooling, autonomous and human-in-the-loop workflows, and multi-agent conversation patterns. It is the community continuation of AutoGen: as of v1.0 the protocol-driven framework became the top-level package (import ag2), while the classic framework (ConversableAgent, GroupChat, import autogen) moved to its own repository, ag2ai/ag2-classic. Officially, "AG2 v1.0 (pip install ag2) is not a drop-in upgrade from Classic. The agent model, orchestration, and imports all changed." v1.0 orchestrates agents through the Network — a Hub that owns the registry, write-ahead log, and audit trail, with agents talking over typed channels — and exposes an opt-in harness of composable primitives (assembly=, knowledge=, tasks=). It is licensed Apache-2.0 and runs entirely in your own process (no managed hosting), so the only cost is model calls, billed by whichever provider you install.
适合与不适合When to use it, when not to
适合:
- 用 Python 编排多 agent 会话 / 协议化网络
- 需要可审计的 durable messaging 与跨进程部署
- 要在本地模型上跑(Ollama / vLLM / LM Studio)
- 要 HITL 与受限 shell
- 需要 MCP 与 AG-UI
- 偏好 opt-in、可组合的 harness 原语
不适合:
- 期待
pip install ag2仍是老 AutoGen - 需要厂商托管后台
- 需要开箱即用的容器级沙箱
- 非 Python 技术栈
Orchestrating multi-agent conversations / a protocol-driven network in Python (Hub + channels, with consulting, discussion, and workflow adapters) Needing auditable durable messaging (write-ahead log, audit trail) and cross-process deployment (WsLink) Running on local models (Ollama / vLLM / LM Studio) Needing HITL and a restricted shell tool; MCP and AG-UI integration Preferring opt-in, composable harness primitives
Not a fit for expecting pip install ag2 to still be the classic AutoGen API (since v1.0 those classes live in ag2-classic); needing a vendor-managed backend (it is a pure library — you run the process); needing out-of-the-box container-level sandboxing (officially you get a restricted-shell allowlist, not a container); or non-Python stacks (there is no official non-Python port).
中文生态China availability 国产 / 国内可直接用 / 备案状态 · 快照domestic / direct access / CAC filing · snapshot 2026-10-20
- 出品属地Origin
- 国外出品foreign-made 国外主体(网信办公示名单未见对应备案主体)。foreign entity (no matching filing entity in the CAC registry).
- 国内使用Direct access
- 大陆可直连direct OK 官网直连实测 200。official site measured 200 direct.
- 备案状态CAC filing
- 未见于备案名单not in filing list:未见于网信办公示名单(2026-10-20 检索 13 批附件,https://www.cac.gov.cn/2024-04/02/c_1713729983803145.htm);该产品未面向大陆公众提供服务,备案不适用。not in the CAC public registry (13 batch attachments searched 2026-10-20, https://www.cac.gov.cn/2024-04/02/c_1713729983803145.htm); the product does not serve the mainland public, so filing does not apply.
备案信息以网信办《生成式人工智能服务已备案信息》公示名单为准(按批次滚动更新,本站只抄编号不解读);「大陆可直连」是本站从大陆网络直连实测的结果,不是厂商承诺。GitHub 类站点当日实测有波动,口径写在依据里。Filing status is quoted from the CAC public registry (updated batch by batch; this site copies the number and does not interpret it). "Direct access" is this site's own reachability measurement from a mainland network, not a vendor promise. GitHub-hosted sites fluctuated on the measurement day — the note says so.
固定坐标系Fixed coordinate system
8 个维度dimensions, 与同分区其他对象逐项可比each comparable item by item against others in the same section.
- 模型与开放条件Model & openness
provider 清单是显式的、类型安全的配置类,覆盖云端与本地两条路。
官方
beta/model_configuration页原文:"The AG2 framework provides an explicit, predictable, and type-safe way to configure Large Language Models"
每家 provider 一个 Config 类 + 一个 extra:
OpenAIConfig/OpenAIResponsesConfig(ag2[openai])AnthropicConfig(ag2[anthropic])GeminiConfig/VertexAIConfig(ag2[gemini])BedrockConfig(ag2[bedrock])OllamaConfig(ag2[ollama])DashScopeConfig(ag2[dashscope])XAIConfig(ag2[xai])ZAIConfig(ag2[zai])
本地 / 自托管明确支持。
官方专列一节 "Self-Hosted and OpenAI-Compatible Models(vLLM, LM Studio, etc.)", 走
OpenAIConfig的 base_url。README 亦列出ag2[ollama]。Bedrock 于 v1.1.1 改为原生异步客户端 aiobotocore。官方 release 明示为 breaking。
未知 —— 换 provider 后 tool calling / structured output 的可靠性对比,官方未说明 (已查
beta/model_configuration与 Grok 兼容页)。- 运行位置Where it runs
纯 Python 库,异步贯穿,不提供托管服务。
README 原文:
"AG2 requires Python version >= 3.10"
"AG2 is async throughout.
Agent.ask(...)starts a turn and returns anAgentReply"安装是
pip install ag2[openai]。多 agent 的调度形态官方给了两种链路(
network/overview页):- 默认
LocalLink—— 官方描述:
"same-process duplex queues"
即同进程内 hub + agents。
- 换成
WsLink—— 官方描述:
"the hub and each agent as separate OS processes connected over WebSocket"
即 hub 与每个 agent 分处不同操作系统进程。
换链路时
HubClientAPI 不变、无需改业务代码。它不运营 agent loop。
库里的一切跑在你自己的进程 / 主机上,官方无 any 托管 offer。
- 默认
- 本地文件Local files
框架不内置通用文件工具。文件能力来自 KnowledgeStore 与沙箱 shell 工具。
后者的边界写得比多数同类清楚,这是本对象最值得记的一处。
① 磁盘知识库。
官方 harness 示例用
DiskKnowledgeStore(Path("./knowledge_demo")),官方注释:"Disk-backed, so anything the agent remembers survives the process exiting"
即知识落盘位置由你指定的目录决定。
② 受限 shell(已核到,见官方 release v1.1.1)。
受限模式 "runs commands without a shell"。
SandboxShellTool/ShellAdapter传allowed=[...]或readonly=True时, 会把命令切分成 argv。然后只检查 argv 再原样执行:官方原文:"Nothing can expand after the check"
管道 / 重定向 / 通配符 / 变量在受限模式下被拒。
readonly=True只放行不可写文件、不启动其它程序的命令blocked=[...]官方明说:
"remains best-effort. It is not a security boundary."
未知 —— 框架级的默认文件访问边界与容器级隔离,官方未说明 (已查
network/overview、agent_harness与 release 页)。- 关机后的任务Tasks after shutdown
「关机后还能跑」在本站是纯库形态 —— 没有托管后台。
但 durable messaging 机制官方给了明确实现。
network/overview页列出的 Network 能力包含:"Durable messaging with replayable channel transcripts (write-ahead log)"
"Distributed / cross-process deployment: replace
LocalLinkwithWsLink"hub 持有权威状态:registry、audit log、channel table、write-ahead logs。客户端是:
"thin frontends"
官方另有 Distributed Deployment 专页。
它涵盖 WsLink、serve_ws、auth、at-least-once delivery、reconnect 与 task durability。
长期记忆可跨进程存活。 DiskKnowledgeStore 落盘,见 local_files 轴。
但没有任何厂商托管 offer。
进程必须跑在你自己的服务器上;要真后台得自己上容器 / K8s。
未知 —— 托管选项与断点续跑在崩溃场景下的具体语义,官方未说明 (已查
network/overview页)。- 工具与扩展Tools & extensions
工具、MCP、AG-UI 三项都能在官方源核到;A2A 仅见仓库 topics。
① 原生工具。
普通 Python 函数加
@tool装饰器即成为工具。官方原文:"AG2 runs the full tool-calling loop: the model decides when to call it, AG2 executes it, and the result is fed back"
agent 还可
Agent.as_tool()被别的 agent 当工具用。② MCP。
官方 release 记录持续维护
MCPToolkit与MCPServerTool:- v1.1.1 "send exactly one
Authorizationheader on every provider" - v1.1.2 "fix(mcp): derive model output schemas from serialization"
③ AG-UI。
- v1.1.2 "feat(ag-ui)!: serve AG-UI 1.0"
- v1.1.1 支持 "Human input over AG-UI"(工具内
context.input()的问题经 AG-UI 客户端以 interrupt 抛出)
④ Skills。
官方 release 有 skill 相关修复:
- "check local skill ownership before validating arguments"
- "execute nested scripts from declared paths"
A2A 目前只能在官方仓库 topics 里看到(含
a2a)。本轮未取到 v1.0 的 A2A 专页正文,故不展开。
子任务委派另有
run_subtask/run_subtasks自动注入工具(见 context 轴)。- v1.1.1 "send exactly one
- 上下文与记忆Context & memory
这是 AG2 最贴合本站「状态 ≠ 上下文」主张的设计。
它把 harness 显式拆成三组 opt-in 原语。
官方
agent_harness页原文:"A bare
Agentis just a model loop. The harness is the set of opt-in primitives you compose onto it"三个关键参数:
assembly=(上下文策略) —— 官方示例含WorkingMemoryPolicy(把memory/working.md注入 system prompt)、SlidingWindowPolicy(max_events=50)(限制历史占用)、AlertPolicy
knowledge=——KnowledgeConfig(store=..., compact=..., compact_trigger=..., aggregate=...), 配SummarizeCompact/TailWindowCompact做上下文压缩(README 示例 "18 -> 3 events");write_event_log会把流历史落到/log/{stream_id}.jsonl
tasks=(默认关闭) —— 开启后自动注入子任务工具;子 Agent 默认继承父工具, 且子任务自身tasks=False,官方原文:
官方原文:"recursive delegation is structurally impossible"
分野很清楚:
compact=管窗口压缩。KnowledgeStore管跨进程持久记忆 —— 两者官方分开描述。- 权限与限制Permissions & limits
官方机制分两层:HITL 人审 + 受限 shell 工具。两层都不等于容器沙箱。
① HITL。
README 原文如下:
- 在工具里调
context.input(...)暂停本次 run 向人提问 - 由
hitl_hook决定答案来源(CLI / web UI / 队列)
② 工具审批。
release v1.1.1 明说:
"Approval grants are keyed by tool implementation"
且同名工具每轮只暴露一个。
MCP 发现的工具排在代码声明的工具之下,不能覆盖本地工具。
③ 受限 shell。
SandboxShellTool的allowed/readonly/blocked见 local_files 轴。 官方自己声明blocked=[...]不是安全边界。v1.1.2 还修了一个 shell 命令过滤绕过漏洞(GHSA-42mf-vpmr-gw5r)。
④ 数据接口安全提示。
官方文档警告 Redis 的
Serializer.PICKLE会把代码执行能力交给任何能写该 stream 的人。 建议只用完全可信的 Redis,JSON 为默认。未知 —— 框架级的进程 / 容器沙箱默认值,官方未说明 (已查
agent_harness与 release 页)。- 在工具里调
- 适合什么任务Best for
适合。
- 要用 Python 编排多 agent 会话 / 协议化网络(Hub + channel,含咨询、讨论、工作流适配器)
- 需要可审计的 durable messaging(write-ahead log、audit trail)与跨进程部署(WsLink)
- 要在本地模型上跑(Ollama / vLLM / LM Studio)
- 要 HITL 与受限 shell 工具
- 需要 MCP 与 AG-UI 对接
- 偏好 opt-in、可组合的 harness 原语
不适合。
- 期待
pip install ag2仍是老 AutoGen API(v1.0 起经典类已移入ag2-classic) - 需要厂商托管后台(纯库,进程自负)
- 需要开箱即用的容器级沙箱隔离(官方给的是受限 shell 白名单,非容器)
- 非 Python 技术栈(无官方非 Python 端口)
头号误解Top misconception
- 以为 pip install ag2 还是老 AutoGen —— v1.0 起 ConversableAgent / GroupChat / import autogen 都搬到 ag2-classic 包Assuming
pip install ag2is still classic AutoGen — since v1.0 ConversableAgent / GroupChat /import autogenall moved to the ag2-classic package - 以为 ag2 与 autogen 可平滑升级 —— 官方明说 v1.0 不是 drop-in upgrade,agent 模型、编排与 import 全变了Assuming ag2 is a smooth upgrade from autogen — officially v1.0 is not a drop-in upgrade; the agent model, orchestration, and imports all changed
- 以为它是微软官方项目 —— 社区志愿者维护(ag2ai),与微软的 Microsoft Agent Framework 是两条线Assuming it is a Microsoft-official project — it is maintained by community volunteers (ag2ai), a different line from Microsoft's Microsoft Agent Framework
- 以为 blocked=[...] 是安全边界 —— 官方原文说它只是 best-effort,受限 shell 的隔离靠 allowed 白名单与 readonlyAssuming
blocked=[...]is a security boundary — officially it is only best-effort; isolation in the restricted shell comes from theallowedallowlist andreadonly
未知项清单Known unknowns
- 框架级默认文件访问边界与容器级隔离(官方未说明)
- 托管选项与崩溃场景下的断点续跑语义(官方未说明)
- 换 provider 后 tool calling / structured output 的可靠性对比(官方未说明)
- A2A 在 AG2 v1.0 的实现细节(官方仓库 topics 含 a2a,本轮未取到专页正文)
- 受限 shell 的完整命令白名单语义边界(官方给的是 allowed/readonly/blocked 三档,细节需实测)
- Classic 线与 v1.0 的长期并行维护策略(官方仅称 Classic "remains maintained") 各条的核验出处:
- 文件访问边界与容器隔离、托管选项:已查
network/overview与agent_harness两页 - 换 provider 后可靠性:已查
beta/model_configuration与 Grok 兼容页
证据来源Evidence sources
判断可回到以下一手源复核。本站核验日Every judgement can be rechecked against the primary sources below. Verified on 2026-10-08,内容更新日content updated on 2026-10-08。
| 类型Type | 名称Name | 链接Link |
|---|---|---|
| repo | ag2ai/ag2 · 仓库(4,983★,Apache-2.0,pushed_at 2026-10-08,topics 含 mcp/a2a/ag2,核验 2026-10-08) | https://github.com/ag2ai/ag2 |
| docs | 主 README(AG2 v1.0 与 AG2 Classic 拆分、Agent/tools/HITL/Network/harness 概念、Apache-2.0 声明) | https://github.com/ag2ai/ag2/blob/main/README.md |
| docs | 官方文档 · Network Overview(Hub + channel、四种适配器、LocalLink/WsLink、write-ahead log、audit trail、HumanClient) | https://docs.ag2.ai/docs/user-guide/network/overview/ |
| docs | 官方文档 · Agent Harness(assembly= / knowledge= / tasks= 三组原语、compaction、子任务不可能递归、turn lifecycle) | https://docs.ag2.ai/docs/user-guide/agent_harness/ |
| docs | 官方文档 · Model Configuration(provider Config 类与 extra 清单、自托管 OpenAI 兼容、Vertex/Z.AI/Bedrock 认证) | https://docs.ag2.ai/latest/docs/beta/model_configuration/ |
| docs | 官方文档 · Grok & OpenAI-API-Compatible(xAI 走 OpenAI 客户端、function calling 与结构化输出) | https://docs.ag2.ai/latest/docs/user-guide/models/grok-and-oai-compatible-models/ |
| docs | AG2 Classic 文档 · LLM Configuration(经典线的 provider 清单:OpenAI/Anthropic/Gemini/Bedrock/Mistral/Cerebras/Together/Groq + 本地 Ollama/LiteLLM/LM Studio) | https://classic.docs.ag2.ai/latest/docs/user-guide/basic-concepts/llm-configuration/ |
| changelog | Releases(最新 v1.1.2 @ 2026-10-03;v1.1.1 含受限 shell 与工具审批变更、GHSA-42mf-vpmr-gw5r 修复、Bedrock 转 aiobotocore) | https://github.com/ag2ai/ag2/releases |
| repo | ag2ai/ag2-classic · 经典框架独立仓(pip install ag2-classic,import autogen,仍维护) | https://github.com/ag2ai/ag2-classic |
实测记录Measured runs
本站尚未完成实测。测试协议见 tasks/_protocol.md。
实测建议(按编排框架 + 多 agent 会话维度定制):
| # | 测什么 | 为什么值得测 |
|---|---|---|
| 1 | 用 WorkflowAdapter 复刻一段经典 GroupChat 代码的改动量 | 验证官方「最接近 GroupChat」的说法 |
| 2 | 从 LocalLink 切到 WsLink 跨进程部署,业务代码是否真不用改 | 官方承诺 HubClient API 不变 |
| 3 | 受限 shell(allowed/readonly)在真实命令集下的可用性 | 安全变强往往牺牲可用性,需量边界 |
| 4 | 接 Ollama 跑一个多 agent 网络,观察 token 与延迟开销 | 本地模型 + 多 agent 的真实成本 |
| 5 | DiskKnowledgeStore + 压缩两次运行,验证跨进程记忆是否真生效 | README 示例宣称重启仍记得 |
| 6 | v1.1.x 连续两版的破坏性变更面 | 迭代快,选型需量化升级风险 |
一个必须讲清的版本断层:AG2 v1.0 把 Classic 拆出去了
README 顶部用醒目提示说明:
Looking forConversableAgent,GroupChat, orimport autogen? That's now AG2 Classic.
自 v1.0 起,经典框架整体搬到独立仓 ag2ai/ag2-classic。
- 经典线:
pip install ag2-classic、import autogen、文档classic.docs.ag2.ai - 新顶层包:
pip install ag2改为协议驱动的新框架
经典线仍在维护、现有代码不停止工作。
新顶层包不再附带 autogen 这个 import 名与经典 agent 类。
官方对升级路径的措辞很直接:
AG2 v1.0 (pip install ag2) is not a drop-in upgrade from Classic. The agent model, orchestration, and imports all changed.
所以「AG2 是不是 AutoGen 新版」这个问题,答案是:同一血脉。
但 v1.0 不是平移升级。
多 agent 编排:Network(Hub + channel)
v1.0 用 Network 取代经典的 GroupChat / swarm / nested chat:
a Hub that owns the registry, the write-ahead log, and the audit trail, with agents talking over typed channels.
官方原文明确:
"This replaces the classic GroupChat / swarm / nested-chat patterns."
四种内置 channel 适配器:
| 适配器 | 参与者 | 发言顺序 | 终止 |
|---|---|---|---|
conversation | 恰好 2 | 自由(任意时刻任一方) | 显式 close 或 TTL |
consulting | 恰好 2 | 严格一问一答 | 答复后自动关闭 |
discussion | 2+ | 轮转(round_robin) | 显式 close 或 TTL |
workflow | 2+ | 声明式 TransitionGraph | 图终止 |
其中 workflow 官方称「最接近经典 GroupChat 的对应物」。
部署上默认 LocalLink(同进程)。换 WsLink 即跨进程 / 跨主机,业务代码不变。
harness:三组 opt-in 原语,正好落在「状态 ≠ 上下文」上
官方 agent_harness 页原文:
A bare Agent is just a model loop. The harness is the set of opt-in primitives you compose onto it.
| 参数 | 作用 | 对应本站维度 |
|---|---|---|
assembly= | 上下文策略:WorkingMemoryPolicy / SlidingWindowPolicy / AlertPolicy | 上下文 |
knowledge= | KnowledgeStore + SummarizeCompact / TailWindowCompact 压缩 + 聚合 | 长期记忆 + 上下文压缩 |
tasks= | 子任务委派(默认关闭),子 Agent tasks=False,无法递归 | 子代理 |
这条分野很干净:压缩(compact=)管的是窗口占用。
知识库(KnowledgeStore)管的是跨进程持久记忆。
权限:HITL + 受限 shell,但不是容器沙箱
- HITL:工具里
context.input(...)暂停 run 向人提问,hitl_hook决定答案来源。 - 工具审批:官方 v1.1.1 明说审批按「工具实现」为键,同名工具每轮只暴露一个。
- 受限 shell:
SandboxShellTool的allowed=[...]/readonly=True会把命令切成 argv 后只检查 argv 再原样执行。
官方原话:
"Nothing can expand after the check"
官方同时声明 blocked=[...] :
"best-effort. It is not a security boundary."
- v1.1.2 修了一个 shell 命令过滤绕过漏洞(GHSA-42mf-vpmr-gw5r), 说明这类工具的安全面需要盯 release。
注意:这不是容器隔离 —— 官方给的是白名单与只读模式。
另一条数据接口提示。
用 Serializer.PICKLE 时,任何能写该 Redis stream 的人都会有代码执行能力。
官方建议只用完全可信的 Redis,JSON 为默认。
核验说明
confidence: partial 的依据:
为什么不是 verified:本轮已核到 v1.0 与 Classic 的拆分、Network 的 Hub/channel 抽象、 harness 三组原语、provider 清单(含本地模型)。
受限 shell 与工具审批机制也已核到。发布节奏(v1.1.1 / v1.1.2)同样在本轮核到。
但仍有多处官方确实没给的项:
- 框架级默认文件访问边界与容器级隔离
- 托管选项与崩溃续跑语义
- 换 provider 后 tool calling / structured output 的可靠性
- A2A 在 v1.0 的实现细节(仅见仓库 topics)
加上版本迭代快(数日内连发两版),故不足以升到 verified。
本轮核到的官方页:仓库与 README、network/overview、agent_harness、 beta/model_configuration、Grok 兼容页、经典线 LLM Configuration 页、releases 页、 ag2ai/ag2-classic 仓。
已核验元数据:仓库存在、★4,983、许可 Apache-2.0(经 license API)、 最近推送 2026-10-08(仍活跃)、最新版 v1.1.2(releases @ 2026-10-03)。
相关条目Related entries
- Microsoft Agent Framework同源分野:AG2 是 AutoGen 的社区延续,MAF 是微软官方把 AutoGen 与 Semantic Kernel 合并的继任线。
- CrewAI抽象层次对照:CrewAI 用 Crew(角色/目标/任务)/ Flow 的业务比喻。
- Google ADK编排与 HITL 对照:ADK 是图执行引擎 + 工具级确认。
- Filesystem MCP ServerFilesystem MCP Server另一层 · 给 AI 装工具Other layer · Tools for your AI
本页由This page is generated from the ai-agent-guide 数据层生成(CC BY 4.0)。data layer (CC BY 4.0).
方法论与坐标系定义见仓库内 METHODOLOGY.md。