AG2

Framework · Last verified 2026-09-30 · Install verified 2026-09-30

TL;DR

AG2 is an Apache-2.0 Python agent framework maintained by a volunteer community; the project diverged from the AutoGen codebase in November 2024. Version 1.0 moved the classic autogen API into a separate ag2-classic package and introduced an async Agent plus a hub-based multi-agent network. It suits Python teams that want MCP, A2A and AG-UI built in.

Key facts

AG2 key facts. Data as of 2026-10-01.
Type Framework
Languages / SDKs Python
License Apache-2.0
Pricing model Unknown
Orchestration pattern Other
GitHub stars 4,970 (as of 2026-10-01)
GitHub forks 731
Last push 2026-09-30
Latest release v1.1.1
Repository ag2ai/ag2
Website ag2.ai
Documentation docs.ag2.ai
Last verified 2026-09-30

Key features

  • Async Agent API: agent.ask() starts a turn and reply.ask() continues the same conversation. (source)
  • ag2.network: a hub with registry, write-ahead logs and audit log, plus typed channels (conversation, consulting, discussion, workflow). (source)
  • Subagents: Agent.as_tool() exposes one agent as a tool of another, each call running on its own isolated stream. (source)
  • Opt-in harness pieces: a KnowledgeStore for persistent memory, context assembly policies and history compaction. (source)
  • MCP in both directions: MCPToolkit consumes MCP servers and ag2.mcp.MCPServer serves an agent to MCP clients. (source)
  • ag2.a2a: serve an agent over A2A (JSON-RPC, REST or gRPC) or call a remote A2A agent as a model provider. (source)
  • AGUIStream bridges an agent to AG-UI events, including run interrupts and tool-call approval in the frontend. (source)
  • ACP client that launches and drives CLI coding agents (Claude Code, Codex, OpenCode, Kilo Code) as AG2 agents. (source)

Architecture and orchestration pattern

Pattern: Other

AG2 v1.0 is built around an async Agent that calls a model provider, runs the tool-calling loop and publishes every step (model calls, tool calls, human-input requests) as events on a stream. Optional harness components add context assembly policies, a path-based KnowledgeStore for memory across runs, history compaction and sub-task delegation. Middleware covers retries, token budgets and similar concerns.

Multi-agent work has two routes. Within one agent, other agents can be attached as tools with Agent.as_tool(); the calling model decides when to delegate. For coordinated teams, ag2.network sets up a hub-and-spoke network: the hub holds the registry, per-channel write-ahead logs, governance rules and an audit log, and agents exchange envelopes over channels whose adapter sets the rules (free two-party conversation, one-question consulting, round-robin discussion, or a workflow driven by a declarative, JSON-serialisable TransitionGraph). The workflow adapter is the documented replacement for the classic GroupChat. The hub runs in-process by default or over WebSocket for multi-process deployments.

State is externalised behind History, Storage and Stream protocols that can be backed by Redis or a database. agent.resume() rebuilds a turn from recorded events, and network channel transcripts can be replayed from the write-ahead log.

Human in the loop

A tool can call context.input(...) to pause the run and ask a person; the agent's hitl_hook decides how the question is answered (CLI prompt, web UI, queue). The built-in approval_required() tool middleware asks the user to approve or deny a specific tool call before it runs, with an option to always allow that tool for the rest of the conversation. In a network, a HumanClient joins channels as a non-LLM participant that your UI drives. Over AG-UI, a run can end with an interrupt and be resumed by a later run on the same thread, and a gated tool call can be sent to the frontend for approval. When AG2 drives a CLI coding agent over ACP, its permission requests go to the same hook unless permission_policy is set to auto-approve or deny.

Harnesses it can drive

Protocols

MCP, A2A and AG-UI support for AG2. See the full matrix.
ProtocolSupportNote
MCP Yes evidence
checked 2026-09-30
Client and server: MCPToolkit / MCPServerTool consume MCP servers, and ag2.mcp.MCPServer exposes an AG2 agent to any MCP client (ag2[mcp] extra).
A2A Yes evidence
checked 2026-09-30
Client and server: A2AServer serves an agent over JSON-RPC, REST or gRPC and A2AConfig lets an agent call a remote A2A endpoint; needs ag2[a2a] plus a2a-sdk transport extras for serving.
AG-UI Yes evidence
checked 2026-09-30
Server side: ag2.ag_ui.AGUIStream emits AG-UI text, tool-call, state-snapshot and interrupt events (ag2[ag-ui] extra); the AG-UI README also lists AG2 under 1st-party integrations.

Best for

  • Orchestrating CLI coding agents such as Claude Code, Codex and OpenCode from Python over ACP (shortlist)
  • Multi-agent setups that need turn-order rules, an audit log and replayable transcripts (shortlist)
  • Agents that other systems must reach over MCP, A2A or AG-UI without third-party adapters
  • New Python projects that can start directly on the v1.0 async API

Not for

  • Existing code built on import autogen, ConversableAgent or GroupChat that cannot absorb a rewrite; that code belongs on ag2-classic
  • Non-Python stacks; the framework is Python only
  • AG-UI deployments behind a plain round-robin load balancer, since resuming an interrupted turn needs sticky routing

Quickstart

pip install "ag2[openai]"

Install verified 2026-09-30 (uv venv, Python 3.12.13, macOS arm64: uv pip install ag2[openai] ok, from ag2 import Agent ok, ag2 1.1.0. Packages came from the mirrors.aliyun.com mirror, so the version is the one that mirror served on this date. Install and import check only; not a functional test.). What this means

import asyncio
from ag2 import Agent
from ag2.config import OpenAIConfig

config = OpenAIConfig("gpt-4o-mini")  # reads OPENAI_API_KEY
researcher = Agent("researcher", prompt="Return three short factual findings.", config=config)
writer = Agent("writer", prompt="Turn the notes you get into one clear paragraph.", config=config)
coordinator = Agent("coordinator", config=config,
    prompt="Delegate research first, then pass the findings to the writer.",
    tools=[researcher.as_tool(description="Research a topic and return findings."),
           writer.as_tool(description="Write prose from notes passed as context.")])

async def main() -> None:
    reply = await coordinator.ask("Write a short note on the A2A protocol.")
    print(reply.body)

asyncio.run(main())

Common pitfalls

  • Requires Python >= 3.10. Only minimal dependencies install by default; add the extra for your provider (ag2[openai], ag2[anthropic], ag2[gemini], ...).
  • Provider configs read the standard environment variable (OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY).
  • pip install ag2 (v1.0+) no longer ships the autogen import name or ConversableAgent / GroupChat; code using them needs pip install ag2-classic, and moving it to v1.0 is a rewrite, not an upgrade (see the group chat migration guide).
  • The API is async throughout; call ask() from inside an event loop.
  • Protocol features are extras: ag2[mcp], ag2[a2a] (serving also needs a2a-sdk[http-server] or a2a-sdk[grpc]), ag2[ag-ui], ag2[acp].

Official quickstart

Pros

  • MCP works in both directions: agents can use MCP tools and can themselves be served as MCP servers. (source)
  • A2A server and client ship in the package, with JSON-RPC, REST and gRPC bindings. (source)
  • AG-UI support is built in, including interrupts and frontend approval of tool calls. (source)
  • Can launch and supervise Claude Code, Codex and OpenCode sessions through ACP and stream their steps. (source)
  • The network hub records a write-ahead log and audit trail and enforces per-agent rules. (source)

Cons

  • AG2 v1.0 is not a drop-in upgrade from AG2 Classic: the agent model, orchestration and imports all changed. (source)
  • Older tutorials using import autogen, ConversableAgent or GroupChat target the separate ag2-classic package and do not run on ag2 1.x. (source)
  • An interrupted AG-UI turn is held in one process: resumes need sticky routing, and a restart drops held turns. (source)
  • agent.resume() can fail on providers that attach required metadata to replayed calls, such as Gemini 3.x thought signatures. (source)
  • The website promotes hosted products (AG2 Space, an AgentOS platform) behind a request-access form with no published pricing. (source)

Alternatives

FAQ

How is AG2 different from AutoGen?

AG2's docs say it diverged from the AutoGen codebase in November 2024. In v1.0 it moved the AutoGen-style API to ag2-classic and switched to an async Agent and a hub-based network, while Microsoft's AutoGen is in maintenance mode.

Can I still use `import autogen` and `ConversableAgent`?

Yes, through AG2 Classic: pip install ag2-classic, documented at classic.docs.ag2.ai. The ag2 package from v1.0 no longer includes that namespace.

Does AG2 support MCP, A2A and AG-UI?

Yes, all three are first-party. MCP works as client and server, A2A as client and server, and AGUIStream exposes agents to AG-UI frontends. Each needs its own install extra.

Can AG2 drive Claude Code or Codex?

Yes. With ag2[acp], ClaudeCodeConfig, CodexConfig and OpenCodeConfig launch those CLIs as ACP agents, and AG2 streams their messages, tool calls and permission prompts.

Is AG2 free?

The framework is Apache-2.0. The AG2 website also advertises hosted products behind a request-access form without public pricing, so the pricing model is listed as unknown.

Sources

Unknown fields: pricing_model: the framework is Apache-2.0, but ag2.ai promotes AG2 Space and an AgentOS platform behind 'Request Access' and no pricing page exists (https://ag2.ai/pricing returned 404 on 2026-09-30), so it is unclear whether a paid hosted product is offered.

Something wrong or out of date, or do you maintain AG2 and want this page removed? Report a correction or request removal.