# AG2

> Open-source framework for building and orchestrating cooperating AI agents

- Category: Agents & Automation / Multi-Agent Systems
- Language: Python
- Repository: https://github.com/ag2ai/ag2
- Website: https://ag2.ai
- Canonical page: https://ai-tldr.dev/tools/ag2/

## In short

AG2 (formerly AutoGen) is an open-source Python framework for building AI agents and coordinating several of them to work together on a task. It came out of the AutoGen project and is now maintained by a group of volunteers from several organizations, available on PyPI as `ag2` (with `autogen` as an alias). It sits in the Multi-Agent Systems category of the Agents & Automation tools and is open-source, written in Python.

## Overview

AG2 (formerly AutoGen) is an open-source Python framework for building AI agents and coordinating several of them to work together on a task. It came out of the AutoGen project and is now maintained by a group of volunteers from several organizations, available on PyPI as `ag2` (with `autogen` as an alias).

It is aimed at developers who want to go beyond a single chatbot call and instead set up multiple agents that exchange messages, call tools, run code, and bring a human into the loop when needed. Agents are built from a common `ConversableAgent` base class, so a coder agent and a reviewer agent, for example, can talk to each other through the same message-passing model.

As a multi-agent framework, AG2 provides built-in conversation patterns such as group chats, swarms, nested chats, and sequential chats, plus support for various large language models and tool use. It fits the agent-frameworks category as a building block for agentic applications rather than a finished product.

## What it does

- Conversable agents that send and receive messages and generate replies using LLMs, tools, or human input
- Built-in orchestration patterns: group chats, swarms, nested chats, and sequential chats
- Human-in-the-loop workflows to insert human input into an agent conversation
- Tool support so agents can register, invoke, and execute external functions
- Works with multiple large language models via a JSON config file (OAI_CONFIG_LIST)
- Advanced concepts including structured outputs, RAG, and code execution

## Getting started

AG2 requires Python 3.10 or newer. Install it from PyPI, add your LLM API key in a config file, then run a first agent.

1. Install AG2

   Install from PyPI with the OpenAI extra. On Windows/Linux use the unquoted form; on Mac quote the package name so the shell does not expand the brackets.

```bash
pip install ag2[openai]
```

2. Set up your API keys

   Store your keys in a config file (the examples use a file named OAI_CONFIG_LIST). Add it to .gitignore so it is never committed.

```json
[
  {
    "model": "gpt-5",
    "api_key": "<your OpenAI API key here>"
  }
]
```

3. Run your first agent

   Create a script or notebook with an assistant and a user proxy, then send the assistant a message.

```python
from autogen import AssistantAgent, UserProxyAgent, LLMConfig

llm_config = LLMConfig.from_json(path="OAI_CONFIG_LIST")

assistant = AssistantAgent("assistant", llm_config=llm_config)

user_proxy = UserProxyAgent("user_proxy", code_execution_config={"work_dir": "coding", "use_docker": False})

user_proxy.run(assistant, message="Summarize the main differences between Python lists and tuples.").process()
```

## When to use it

- Build a two-agent workflow where one agent writes code and another reviews it
- Orchestrate several agents in a group chat or swarm to break down and solve a larger task
- Add human-in-the-loop checkpoints so a person can review or guide an agent conversation
- Give agents tools and code execution to act on external systems and run generated scripts
