ag2

MCP办公协作

提供方 ag2ai · 包名 ag2

办公协作 stdio · 本地进程 未标注 社区 / 第三方 Claude DesktopCursorClineClaude Code
查看接入方式

AG2 (formerly AutoGen): The Open-Source AgentOS.Join us at: https://discord.gg/sNGSwQME3x

一句话选型结论

按资料字段整理

ag2 属于办公协作类 MCP 服务器,stdio · 本地进程,鉴权方式未标注,可直接接入 Claude Desktop、Cursor、Cline 等,有可直接执行的安装命令。接入前先确认权限范围;涉及写入、删除或付款的操作,建议先在测试环境验证。

分类办公协作 传输方式stdio · 本地进程 鉴权未标注 部署方式本地部署
GitHub 星标 4,388 仓库热度,无公开仓库时显示未标注
工具数 未标注 暴露给模型的工具数量
资源 / 提示词 0 / 0 资源与提示词模板数量
维护方 社区 / 第三方 核验等级 仅资料核对

工具与能力

办公协作
数量来自来源目录的标注,具体工具清单以官方文档为准
工具数量未标注暴露给模型可调用的工具个数
资源数量0可读取的资源条目
提示词数量0内置提示词模板数量

能力标签

支持客户端

适用场景

ag2a2aag2

安装与配置

stdio · 本地进程 未标注
客户端在本机拉起子进程,数据不出本机
pip install ag2

这条命令只是入口,具体启动参数请按官方文档补齐,不要直接照搬到别的服务器。

  1. 1
    准备运行环境

    stdio 服务在本地起进程,需要先装好 Cross-platform,再按安装命令拉取依赖。

  2. 2
    安装服务

    复制上面的安装命令执行;命令里带占位符的位置,换成自己的密钥或路径。

  3. 3
    写入客户端配置

    在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,让新配置生效。

  4. 4
    验证是否可用

    连接成功后随便调一个只读工具,确认能返回结果,再接入正式流程。

典型使用场景

3 类
按分类与标签整理的常见用法,具体以官方文档为准
日程与消息

查日程、发消息、约会议。

表单与审批

填表单、走审批流。

团队协作

同步任务、汇总进展。

选择建议

选之前先看这几条
按条目字段给出的判断,不替你决定用不用

值得选的地方

  • 有现成的安装命令,不用自己找入口,照着跑就能起服务。
  • 已适配 Claude Desktop、Cursor、Cline,换客户端不用重新研究配置。
  • 仓库有一定关注度(星标 4,388),遇到问题更容易搜到资料。

先想清楚的地方

  • stdio 方式要求本地装好运行时(如 Node.js),换机器要重新装一遍。
  • 资料没标注工具数量,实际能力要装好后确认。
  • 版本更新与行为细节以官方仓库为准。

更适合

  • 需要在办公协作场景里让模型直接调用外部能力的人。
  • 已经在用 Claude Desktop、Cursor 的用户,接入路径最短。
  • 想先快速试一下、能接受在本地或自有环境跑服务的人。

不太适合

  • 完全不想在本地装环境的人。
  • 需要厂商级 SLA 和技术支持的生产环境。

同类对比

6 个同类
同分类里挑最接近的几条,字段以各自详情页为准
MCP 服务器工具数传输方式部署方式安装命令最后核验
ag2当前 未标注 stdio · 本地进程 本地部署 有 2026-04-11
CowAgent 未标注 stdio · 本地进程 本地部署 有 2026-04-11
Karakeep MCP 未标注 未标注 未标注 无 2026-05-17
agentscope 未标注 stdio · 本地进程 本地部署 有 2026-04-11
note-gen 未标注 stdio · 本地进程 本地部署 有 2026-04-11
Everywhere 未标注 stdio · 本地进程 本地部署 有 2026-04-12

服务器档案

办公协作
字段来自项目仓库与公开索引,中文说明由本站标注
提供方ag2ai上游标注的维护方 ag2ai
分类办公协作本站按上游分类展示
连接方式stdio · 本地进程客户端在本机拉起子进程,数据不出本机
鉴权方式未标注远程服务建议用最小权限凭据
维护方社区 / 第三方核验等级 仅资料核对
包名 / 运行时ag2 · Cross-platform本地安装时用到的包标识与运行时
部署类型本地部署上游给出的部署形态
最近核验2026-04-11上游最后核验时间

详细介绍

16.3 KB
来自项目仓库与上游目录的原文,未做删改

📚 Documentation |
💡 Playground |
💡 Examples |
🤝 Contributing |
📝 Cite paper |
💬 Join Discord |
🏛️ AG2 Classic

> [!IMPORTANT]
> Looking for ConversableAgent, GroupChat, or import autogen? That's now AG2 Classic.
>
> As of AG2 v1.0, the protocol-driven framework is the top-level package, imported as ag2. The classic framework has moved to its own repository — ag2ai/ag2-classic, documented at classic.docs.ag2.ai. It is still maintained and installable; nothing you have built stops working.
>
> This repository (pip install ag2) no longer ships the autogen import name or the classic agent classes.

AG2: Open-Source AgentOS for AI Agents

AG2 is an open-source programming framework for building AI agents and facilitating cooperation among multiple agents to solve tasks. AG2 aims to streamline the development and research of agentic AI. It offers features such as agents capable of interacting with each other, facilitates the use of various large language models (LLMs) and tool use support, autonomous and human-in-the-loop workflows, and multi-agent conversation patterns.

The project is currently maintained by a dynamic group of volunteers from several organizations. Contact project administrators Chi Wang and Qingyun Wu via support@ag2.ai if you are interested in becoming a maintainer.

Table of contents

  • AG2: Open-Source AgentOS for AI Agents
  • Table of contents
  • AG2 Classic (the autogen.* namespace)
  • Getting started
    • Installation
    • Setup your API keys
    • Run your first agent
  • Example applications
  • Introduction of different agent concepts
    • Agents
    • Tools
    • Human in the Loop
    • Orchestrating Multiple Agents
    • The agent harness: knowledge and compaction
    • Advanced agentic design patterns
  • Code style and linting
  • Contributors Wall
  • License

AG2 Classic (the autogen.* namespace)

AG2 Classic is the original AutoGen-derived framework: the autogen.* import namespace and its agent classes — ConversableAgent, AssistantAgent, UserProxyAgent, GroupChat / GroupChatManager, swarms, register_function, LLMConfig / OAI_CONFIG_LIST, and the nested- and sequential-chat patterns.

It now lives in its own repository and has its own documentation site:

AG2 Classic AG2 (this repo)
Repository ag2ai/ag2-classic ag2ai/ag2
Documentation classic.docs.ag2.ai docs.ag2.ai
Import import autogen import ag2
Core agent ConversableAgent Agent
Multi-agent GroupChat, swarms, nested chats Network (hub + channels)

Are you using AG2 Classic?

If any of the following appear in your code, you are on Classic — stay on it, and use classic.docs.ag2.ai:```python
import autogen # the autogen.* namespace
from autogen import ConversableAgent, GroupChat # classic agent classes
from autogen import AssistantAgent, UserProxyAgent


Classic remains maintained and installable. **Your existing code keeps working** — pin the classic distribution instead of `ag2>=1.0`:```bash
pip install ag2-classic

> [!NOTE]
> AG2 v1.0 (pip install ag2) is not a drop-in upgrade from Classic. The agent model, orchestration, and imports all changed. See the group chat migration guide.

The rest of this README covers AG2 v1.0 (import ag2).

Getting started

For a step-by-step walk through of AG2 concepts and code, see the Quick Start in our documentation.

Installation

AG2 requires Python version >= 3.10. AG2 is available as ag2 on PyPI.

Windows/Linux:```bash
pip install ag2[openai]


**Mac:**```bash
pip install 'ag2[openai]'

Minimal dependencies are installed by default. Install the extra that matches your model provider — ag2[openai], ag2[anthropic], ag2[gemini], ag2[ollama], and so on.

Setup your API keys

Each provider config reads its standard environment variable, so keys never need to be hardcoded or checked in:```bash
export OPENAI_API_KEY="<your-api-key>" # or ANTHROPIC_API_KEY, GEMINI_API_KEY, ...


You can also pass a key explicitly with `OpenAIConfig(model=&quot;gpt-4o-mini&quot;, api_key=...)` — useful when each request brings its own key.

### Run your first agent

AG2 is async throughout. `Agent.ask(...)` starts a turn and returns an `AgentReply`; the text is in `reply.body`.```python
import asyncio

from ag2 import Agent
from ag2.config import OpenAIConfig

agent = Agent(
    &quot;assistant&quot;,
    prompt=&quot;You are a helpful assistant.&quot;,
    config=OpenAIConfig(model=&quot;gpt-4o-mini&quot;),
)

async def main() -&gt; None:
    reply = await agent.ask(&quot;Summarize the main differences between Python lists and tuples.&quot;)
    print(reply.body)

asyncio.run(main())

Example applications

We maintain both a live playground and a dedicated repository with a wide range of applications to help you get started with various use cases, and a set of runnable code examples in the documentation.

  • AG2 Playground
  • Build with AG2
  • Code Examples

Introduction of different agent concepts

We have several agent concepts in AG2 to help you build your AI agents. We introduce the most common ones here.

  • Agents: Agent is the core building block — it talks to a model provider, calls tools, and returns a reply.
  • Tools: Plain Python functions, decorated with @tool, that the agent can invoke.
  • Human in the loop: Pause a run to collect confirmation or missing information from a person.
  • Orchestrating multiple agents: Coordinate several agents over a hub and typed channels using the Network.
  • The agent harness: Opt-in primitives layered onto an agent — persistent knowledge, context assembly, and history compaction.
  • Advanced Concepts: Structured outputs, middleware, observers, telemetry, evaluation, and more.

Agents

The Agent is the fundamental building block of AG2. ask() runs a turn; calling ask() on the returned reply continues the same conversation, preserving its history.```python
import asyncio

from ag2 import Agent
from ag2.config import OpenAIConfig

reviewer = Agent(
"reviewer",
prompt=(
"You are a code reviewer. Analyze the provided code and suggest improvements. "
"Do not generate code, only suggest improvements."
),
config=OpenAIConfig(model="gpt-4o-mini"),
)

async def main() -> None:
reply = await reviewer.ask("def fib(n): return n if n < 2 else fib(n-1) + fib(n-2)")
print(reply.body)

# Continue the same conversation — prior turns stay in scope.
follow_up = await reply.ask(&quot;Which of those matters most for large n?&quot;)
print(follow_up.body)

asyncio.run(main())


---

### Tools

Agents gain significant utility through **tools**, which extend their capabilities with external data, APIs, or functions. Decorate a Python function with `@tool` and pass it to the agent — AG2 runs the full tool-calling loop: the model decides when to call it, AG2 executes it, and the result is fed back.```python
import asyncio
from datetime import datetime

from ag2 import Agent, tool
from ag2.config import OpenAIConfig

@tool
async def get_weekday(date_string: str) -&gt; str:
    &quot;&quot;&quot;Get the day of the week for a given date, formatted as YYYY-MM-DD.&quot;&quot;&quot;
    return datetime.strptime(date_string, &quot;%Y-%m-%d&quot;).strftime(&quot;%A&quot;)

date_agent = Agent(
    &quot;date_agent&quot;,
    prompt=&quot;You find the day of the week for a given date.&quot;,
    config=OpenAIConfig(model=&quot;gpt-4o-mini&quot;),
    tools=[get_weekday],
)

async def main() -&gt; None:
    reply = await date_agent.ask(&quot;I was born on 1995-03-25, what day was it?&quot;)
    print(reply.body)

asyncio.run(main())

Human in the Loop

Human oversight is often essential for validating or guiding AI outputs. Call context.input(...) inside a tool to pause the run and ask a person — your hitl_hook decides how that question is answered (CLI prompt, web UI, queue, …).```python
import asyncio

from ag2 import Agent, Context, tool
from ag2.config import OpenAIConfig
from ag2.events import HumanInputRequest, HumanMessage

@tool
async def publish_lesson_plan(context: Context, plan: str) -> str:
"""Publish a lesson plan, once a human educator has approved it."""
answer = await context.input(f"Approve this lesson plan?\n\n{plan}")
if answer.strip().lower().startswith("y"):
return "Published."
return f"Rejected by the educator: {answer}"

def hitl_hook(event: HumanInputRequest) -> HumanMessage:
# Block here for real input — a CLI prompt, a web UI, a queue.
return HumanMessage(content=input(f"{event.content}\n> "))

teacher = Agent(
"teacher",
prompt=(
"Draft a short lesson plan, then call the publish_lesson_plan tool to have it published. "
"Approval is collected by the tool — never ask for approval in plain text."
),
config=OpenAIConfig(model="gpt-4o-mini"),
tools=[publish_lesson_plan],
hitl_hook=hitl_hook,
)

async def main() -> None:
reply = await teacher.ask("Let's introduce our kids to the solar system.")
print(reply.body)

asyncio.run(main())


---

### Orchestrating Multiple Agents

When two or more agents need to work together, AG2 uses the **Network**: 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.

Here a `conversation` channel — a free-form two-party session where either side may speak at any time — connects a planner and a reviewer:```python
import asyncio

from ag2 import Agent
from ag2.config import OpenAIConfig
from ag2.knowledge import MemoryKnowledgeStore
from ag2.network import EV_TEXT, Hub

MAX_MESSAGES = 4

async def wait_for_messages(hub: Hub, channel_id: str, expected: int, timeout: float = 120.0) -&gt; None:
    &quot;&quot;&quot;Poll the hub&#x27;s write-ahead log until `expected` messages have been exchanged.&quot;&quot;&quot;
    deadline = asyncio.get_event_loop().time() + timeout
    while asyncio.get_event_loop().time() &lt; deadline:
        wal = await hub.read_wal(channel_id)
        if sum(1 for e in wal if e.event_type == EV_TEXT) &gt;= expected:
            return
        await asyncio.sleep(0.05)
    raise TimeoutError(f&quot;only reached {expected} messages before timing out&quot;)

async def main() -&gt; None:
    config = OpenAIConfig(model=&quot;gpt-4o-mini&quot;)
    hub = await Hub.open(MemoryKnowledgeStore(), ttl_sweep_interval=0)

    planner = await hub.register(
        Agent(&quot;planner&quot;, prompt=&quot;You plan school lessons. Reply in one short sentence.&quot;, config=config),
    )
    reviewer = await hub.register(
        Agent(&quot;reviewer&quot;, prompt=&quot;You critique lesson plans. Reply in one short sentence.&quot;, config=config),
    )

    # Free-form 2-party channel: either side may speak at any time.
    channel = await planner.open(type=&quot;conversation&quot;, target=&quot;reviewer&quot;)
    await channel.send(&quot;What should a fourth-grade solar system lesson lead with?&quot;, audience=[reviewer.agent_id])

    # Both default handlers reply to every inbound message, so the conversation
    # auto-drives. `conversation` never auto-closes — we bound it and close it.
    await wait_for_messages(hub, channel.channel_id, expected=MAX_MESSAGES)
    await channel.close()

    # Replay the exchange from the hub&#x27;s write-ahead log.
    names = {planner.agent_id: &quot;planner&quot;, reviewer.agent_id: &quot;reviewer&quot;}
    for envelope in await hub.read_wal(channel.channel_id):
        if envelope.event_type == EV_TEXT:
            print(f&quot;{names[envelope.sender_id]}: {envelope.event_data[&#x27;text&#x27;]}&quot;)

    await hub.close()

asyncio.run(main())

Channels come in several shapes — conversation (free-form, two parties), consulting (strict one-question-one-reply, auto-closing), discussion (round-robin across N agents), and workflow (a declarative TransitionGraph for conditional handoffs, which is the closest analogue to a classic GroupChat). See the Network guide.

The agent harness: knowledge and compaction

A bare Agent is just a model loop. The harness is the set of opt-in primitives you compose onto it. Two of the most useful:

  • knowledge= — a KnowledgeStore the agent can read and write, so it remembers across runs.
  • compact= — a strategy that caps history growth. SummarizeCompact folds the dropped turns into a summary rather than discarding them outright.

Pair the store with a WorkingMemoryPolicy in assembly= and the agent's memory is injected into the system prompt on every turn — recall no longer depends on the model choosing to look it up.```python
import asyncio
from pathlib import Path

from ag2 import Agent, KnowledgeConfig, MemoryStream
from ag2.compact import CompactTrigger, SummarizeCompact
from ag2.config import OpenAIConfig
from ag2.events import CompactionCompleted, CompactionFailed
from ag2.knowledge import DiskKnowledgeStore
from ag2.policies import WorkingMemoryPolicy

config = OpenAIConfig(model="gpt-4o-mini")

Disk-backed, so anything the agent remembers survives the process exiting.

STORE_DIR = Path("./knowledge_demo")
store = DiskKnowledgeStore(STORE_DIR)

agent = Agent(
"tutor",
prompt=(
"You are a science tutor for a fourth-grade teacher. "
"Whenever you learn a durable fact about the teacher or their class, use the knowledge "
"tool to read memory/working.md, then write it back with the new fact appended as "
"a bullet. Never drop a fact that is already there. "
"Keep every reply to one or two sentences."
),
config=config,
knowledge=KnowledgeConfig(
store=store,
# Summarize the dropped history instead of forgetting it outright.
compact=SummarizeCompact(target=4, config=config),
compact_trigger=CompactTrigger(max_events=8),
),
# Injects memory/working.md into the system prompt on every turn, so recall
# does not depend on the model choosing to call the knowledge tool.
assembly=[WorkingMemoryPolicy()],
)

stream = MemoryStream()

Subscribe to both outcomes — watching only Completed would hide a failing strategy.

@stream.where(CompactionCompleted).subscribe()
async def on_compacted(event: CompactionCompleted) -> None:
print(f" [compacted: {event.events_before} -> {event.events_after} events via {event.strategy}]")

@stream.where(CompactionFailed).subscribe()
async def on_compaction_failed(event: CompactionFailed) -> None:
print(f" [compaction FAILED: {event.strategy}]")

async def main() -> None:
# A returning session: no conversation history at all, so anything the agent
# recalls here came off disk, via the knowledge store.
if STORE_DIR.exists():
reply = await agent.ask("What do you remember about me and my class?", stream=stream)
print(f"tutor: {reply.body}")
return

reply = await agent.ask(&quot;I&#x27;m Dana. I teach 4th grade at Rosewood Elementary, 26 students.&quot;, stream=stream)
print(f&quot;tutor: {reply.body}&quot;)

for turn in [&quot;My class struggles most with why we have seasons.&quot;, &quot;Suggest one hands-on demo for that.&quot;]:
    reply = await reply.ask(turn)
    print(f&quot;tutor: {reply.body}&quot;)

asyncio.run(main())


Run it twice. The first run fills `memory/working.md` and trips compaction; the second starts with an empty history and still knows who Dana is:```text
  [compacted: 18 -&gt; 3 events via SummarizeCompact]
tutor: I remember that you, Dana, teach 4th grade at Rosewood Elementary with 26 students,
       and your class struggles the most with understanding why we have seasons.

See the Agent Harness guide for assembly=, tasks=, aggregation, and the full turn lifecycle.

Advanced agentic design patterns

AG2 supports more advanced concepts to help you build your AI agent workflows. You can find more information in the documentation.

  • Structured Output
  • Multi-Agent Network
  • Knowledge & Memory
  • Middleware
  • Telemetry
  • Evaluation
  • Testing

Code style and linting

This project uses prek hooks to maintain code quality. Before contributing:

  1. Install prek:```bash
    pip install prek
    prek install

2. The hooks will run automatically on commit, or you can run them manually:```bash
prek run --all-files

Contributors Wall

License

This project is licensed under the Apache License, Version 2.0 (Apache-2.0).

  • Modifications and additions made in this fork are licensed under the Apache License, Version 2.0. See the LICENSE file for the full license text.

We have documented these changes for clarity and to ensure transparency with our user and contributor community. For more details, please see the NOTICE file.

常见问题

8 问
答案由本站依据条目字段整理,不引用上游原文
ag2 怎么安装?

在客户端按下面的安装命令接入:pip install ag2。对应的包名是 ag2。装完在客户端配置里引用同一个包或端点。

ag2 怎么在 Claude Desktop、Cursor、Cline 里配置?

它的传输方式是stdio · 本地进程,在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,配置才会生效。

ag2 收费吗?

本站不代收费用,也没有标注具体价格。是否收费取决于服务本身和背后的接口额度,正式使用前按官方说明确认。

ag2 需要 API Key 吗?

资料没有标注鉴权方式,是否需要密钥取决于服务本身,接入前按官方文档确认。

ag2 支持哪些客户端?

资料标注支持 Claude Desktop、Cursor、Cline、Claude Code;其他客户端只要能配置 MCP Server,也能用同样的命令或地址接入。

ag2 能提供哪些能力?

资料显示能力标签包括 ag2、a2a、agent-framework、agentic。具体工具清单以官方文档为准。

ag2 需要什么运行环境?

运行时为 Cross-platform;属于本地进程,需要在本机装好运行环境。

ag2 是本地还是远程?

它是本地进程(stdio),由客户端在本机拉起。传输方式为stdio · 本地进程。

热门专题

按标签挑服务器
全部专题 →

服务器信息以作者仓库与官方文档为准;分类、传输方式与鉴权方式的中文说明为中文整理,最近核验 2026-04-11。