AG2 is a Python programming framework for building AI agents and coordinating multiple agents to solve tasks together. It supports agents that interact with each other, use of various large language models (LLMs) and tools, autonomous and human-in-the-loop workflows, and multi-agent conversation patterns, and is aimed at both application development and agentic AI research.
As of v1.0 the protocol-driven framework is the top-level ag2 package. The original AutoGen-derived framework — the autogen.* namespace with ConversableAgent, GroupChat, swarms, and nested chats — now lives in a separate ag2-classic distribution with its own documentation and remains maintained. AG2 v1.0 is not a drop-in upgrade: the agent model, orchestration, and imports all changed.
The framework is async throughout. Agent is the core building block: it talks to a model provider, calls tools, and returns an AgentReply; calling ask() on a reply continues the same conversation. Provider configs (OpenAIConfig and equivalents for Anthropic, Gemini, Ollama, and others) read their standard environment variables. Tools are plain Python functions decorated with @tool, and a hitl_hook lets a tool pause the run to ask a person for confirmation or missing information.
Multi-agent coordination uses the Network: a Hub that owns the registry, a write-ahead log, and an audit trail, with agents exchanging messages over typed channels such as a two-party conversation channel. An opt-in harness layers persistent knowledge stores, context assembly policies, and history compaction onto an agent so it remembers across runs and bounds history growth.
Features
- Agent: a model loop that runs turns via ask(), calls tools, and preserves conversation history across follow-up calls on the reply
- Tools: Python functions decorated with @tool; the model decides when to call them, AG2 executes them, and the result is fed back
- Human in the loop: context.input(...) inside a tool pauses the run and routes the question through a hitl_hook (CLI prompt, web UI, queue)
- Network: a Hub with registry, write-ahead log, and audit trail, connecting agents over typed channels
- Knowledge stores: memory- or disk-backed KnowledgeStore instances the agent can read and write across runs
- Compaction: strategies such as SummarizeCompact that fold dropped turns into a summary once a CompactTrigger fires
- Context assembly: policies such as WorkingMemoryPolicy that inject stored memory into the system prompt on every turn
- Event streams: subscribe to events such as CompactionCompleted and CompactionFailed during a run
- Provider configs: OpenAIConfig and provider extras for Anthropic, Gemini, Ollama, and others
- Further capabilities: structured output, middleware, observers, telemetry, evaluation, and testing utilities
- AG2 Classic: the autogen namespace and classic agent classes, still installable as ag2-classic
Built with this
Integrates with
Integrated by
AgentOps
Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI.
MLflow
Open-source platform to trace, evaluate, monitor, and deploy LLM applications, agents, and ML models
OpenLIT
Open-source AI engineering platform with OpenTelemetry-native LLM observability, evaluations, and prompt management
Zep
Examples, framework integrations, and ingestion tooling for the Zep Cloud agent memory platform
