AG2

Frameworks & SDKs 💻 Python ⚖️ Apache-2.0 🟢 Actively maintained
4.9k stars

AG2 is an open-source programming framework for building AI agents and enabling multi-agent cooperation to solve tasks. It provides agents that interact with each other, support for various LLMs and tools, and autonomous or human-in-the-loop workflows. It is for developers and researchers working on agentic AI applications.

✨ Key features

  • Async-first agent framework with Agent.ask() turns
  • Tool support via @tool decorated Python functions
  • Human-in-the-loop with context.input() and hitl_hook
  • Multi-agent orchestration via Network (Hub and channels)
  • Opt-in harness: knowledge stores and history compaction
  • Provider-agnostic configs for OpenAI, Anthropic, Gemini, Ollama

🎯 Use cases

  • Build a single assistant agent that answers questions
  • Create agents that call external APIs or functions as tools
  • Implement human approval workflows for AI-generated content
  • Coordinate multiple agents in a conversation or discussion
  • Build agents with persistent memory across sessions

📦 Installation

🧰 Requirements: Python >= 3.10, an API key for the chosen LLM provider (e.g., OPENAI_API_KEY), and pip install ag2[provider].

Windows/Linux
pip install ag2[openai]
Mac
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.

🚀 Usage

import asyncio

from ag2 import Agent
from ag2.config import OpenAIConfig

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

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

asyncio.run(main())

⚠️ Good to know

AG2 v1.0 is not a drop-in upgrade from Classic; the agent model, orchestration, and imports changed, and the autogen namespace is no longer shipped in this package.

❓ FAQ

What is the difference between AG2 and AG2 Classic?

AG2 (this repo) is the protocol-driven framework imported as ag2, while AG2 Classic is the original AutoGen-derived framework with the autogen.* namespace and classes like ConversableAgent and GroupChat. Classic is maintained in a separate repository and installable via pip install ag2-classic.

How do I set up API keys?

Each provider config reads its standard environment variable, e.g., OPENAI_API_KEY, ANTHROPIC_API_KEY, or GEMINI_API_KEY. You can also pass a key explicitly with OpenAIConfig(model=..., api_key=...).

Is AG2 async-only?

Yes, AG2 is async throughout. Agent.ask(...) is an async method that returns an AgentReply, and examples use asyncio.run().

How do I continue a conversation with the same agent?

Calling ask() on the returned reply continues the same conversation, preserving its history. For example, reply = await agent.ask(...) then follow_up = await reply.ask(...).

📊 Repository

Stars★ 4,904
Forks🍴 713
Open issues🐛 28
Last commit🕒 Sep 4, 2026
Created📅 Nov 2024
Language💻 Python
License⚖️ Apache-2.0
Websiteag2.ai

🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.