ag2-overview
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAG2 — capability map
AG2 — 功能映射
AG2 () is an async, protocol-driven agent framework. The full reference docs live under . This skill is the index of sibling skills that cover the common build paths.
ag2website/docs/user-guide/AG2()是一个异步、协议驱动的Agent框架。完整参考文档位于。本技能是涵盖常见构建路径的子技能索引。
ag2website/docs/user-guide/When to use
使用场景
Read this file first when a request mentions "AG2", "ag2", or building agents in this repo and you don't yet know which feature is needed. Use the table below to pick the right specialised skill, then load that skill's for the recipe.
SKILL.md当请求中提及"AG2"、"ag2"或在此仓库中构建Agent,但尚未明确所需功能时,请先阅读本文档。使用下表选择合适的专业技能,然后加载该技能的获取实现方案。
SKILL.mdBefore you start
前置准备
Anything you build with AG2 needs three things in place. Get these right once and the rest of the skills run cleanly:
- Install the right provider extra — ,
pip install "ag2[openai]",ag2[anthropic], etc. Theag2[gemini]class will raise*Configwithout it. Run the install before delivering code. If you cannot run commands, state the exactImportError: ... requires optional dependenciescommand. This is a required step.pip install - Set the matching API key — ,
OPENAI_API_KEY,ANTHROPIC_API_KEY(orGEMINI_API_KEY). Loading from a project-rootGOOGLE_API_KEYvia.envis the common pattern.from dotenv import load_dotenv; load_dotenv() - Sanity-check the install — . If you have multiple Python environments, this confirms which
python -c "import sys, ag2; from importlib.metadata import version; print(sys.executable, version('ag2'))"your script will actually import.ag2
Full per-provider table (install + env var + config class) lives in → "Prerequisites".
ag2-quickstart使用AG2构建任何内容都需要准备以下三项。配置好这些后,其余技能就能顺利运行:
- 安装对应的扩展依赖 —— 、
pip install "ag2[openai]"、ag2[anthropic]等。如果没有安装,ag2[gemini]类会抛出*Config错误。在交付代码前务必执行安装命令。如果无法执行命令,请明确给出具体的ImportError: ... requires optional dependencies指令。这是必填步骤。pip install - 设置匹配的API密钥 —— 、
OPENAI_API_KEY、ANTHROPIC_API_KEY(或GEMINI_API_KEY)。常见的做法是通过GOOGLE_API_KEY从项目根目录的from dotenv import load_dotenv; load_dotenv()文件加载密钥。.env - 验证安装正确性 —— 。如果存在多个Python环境,此命令可确认脚本实际导入的是哪个环境的
python -c "import sys, ag2; from importlib.metadata import version; print(sys.executable, version('ag2'))"。ag2
完整的各供应商对应表格(安装命令+环境变量+配置类)可在 → "Prerequisites"中查看。
ag2-quickstartPick the right skill
选择合适的技能
| User intent | Skill | What it covers |
|---|---|---|
Build an | | |
| Give the Agent a custom Python tool | | |
| Use shipped tools (web search, code exec, MCP, etc.) | | |
| Run shell commands from an agent | | |
| Get typed Pydantic / dataclass output | | |
| Multi-agent: parallel subtasks or named delegates | | |
| Pause for human input or gate a tool with approval | | |
| Logging, retry, history-trim, custom interception | | |
| Test agents and tools | | |
| Evaluate / benchmark an agent offline, CI gate, scorers | | |
| Compare models / prompts — leaderboard or head-to-head | | |
| Persistent memory across runs, history compaction, assembly | | |
| Observability, alerts, halts | | |
| Send images / audio / video / PDFs in | | |
| Web frontend via the AG-UI protocol | | |
| Serve an agent as an MCP server (server side) | | |
| Expose an agent over the A2A protocol | | |
| Realtime voice / live audio (talking agent, STT, TTS) | | |
| OpenTelemetry traces / metrics | | |
| 用户需求 | 技能 | 覆盖内容 |
|---|---|---|
从零构建 | | |
| 为Agent添加自定义Python工具 | | |
| 使用内置工具(网页搜索、代码执行、MCP等) | | |
| 通过Agent执行Shell命令 | | |
| 获取类型化的Pydantic / 数据类输出 | | |
| 多Agent:并行子任务或指定代理 | | |
| 暂停以等待人工输入或通过审批管控工具 | | |
| 日志、重试、历史截断、自定义拦截 | | |
| 测试Agent和工具 | | |
| 离线评估/基准测试Agent、CI门禁、评分器 | | |
| 对比模型/提示词——排行榜或一对一对比 | | |
| 跨会话持久化内存、历史压缩、整合 | | |
| 可观测性、告警、终止 | | |
| 传入图片/音频/视频/PDF | | |
| 通过AG-UI协议实现Web前端 | | |
| 将Agent作为MCP服务器部署(服务端) | | |
| 通过A2A协议暴露Agent | | |
| 实时语音/直播音频(对话Agent、STT、TTS) | | |
| OpenTelemetry追踪/指标 | | |
Multi-agent networks
多Agent网络
Whenever two or more agents need to interact, load first — the network is the standard multi-agent pattern in AG2. It covers the setup and the two 2-party channel adapters ( for strict 1Q1R and for free-form). After the quickstart, route to the right deep-dive:
ag2-network-quickstartHubconsultingconversation| User intent | Skill | What it covers |
|---|---|---|
| N-party round-robin / fixed turn order | | |
Declarative orchestration / | | |
| Rate limits, access policy, expectations, audit, capability tracking | | |
| Custom envelope handlers, view policies, peer discovery, the LLM-facing network tools | | adapter-owned |
Not a network task: if the user has one agent recursively spawning its own sub-tasks (via / ) or calling another agent as a lightweight tool, use — no hub, no registry, no channels. The network is for distinct, registered agents collaborating through a shared hub.
run_subtaskrun_subtasks(parallel=True)ag2-subagent-delegation当需要两个或多个Agent交互时,请先加载****——网络是AG2中的标准多Agent协作模式。它涵盖设置以及两种双向通道适配器(用于严格的一问一答模式,用于自由对话模式)。完成快速入门后,根据需求选择深入学习的方向:
ag2-network-quickstartHubconsultingconversation| 用户需求 | 技能 | 覆盖内容 |
|---|---|---|
| N方轮询/固定发言顺序 | | |
声明式编排/ | | |
| 速率限制、访问策略、预期、审计、能力跟踪 | | |
| 自定义信封处理器、视图策略、节点发现、面向LLM的网络工具 | | 适配器专属 |
非网络任务说明: 如果用户需要单个Agent递归生成自身子任务(通过 / )或调用另一个Agent作为轻量工具,请使用****——无需hub、注册中心或通道。网络模式适用于独立注册的Agent通过共享hub协作的场景。
run_subtaskrun_subtasks(parallel=True)ag2-subagent-delegation