AG2 (formerly AutoGen): Open-Source AgentOS for AI Agents

0.11.5 · active · verified Thu Apr 16

AG2, distributed via the 'autogen' PyPI package, is an open-source programming framework for building AI agents and facilitating cooperation among multiple agents to solve tasks. It aims to streamline the development and research of agentic AI, offering features such as multi-agent conversations, support for various large language models (LLMs) and tool use, autonomous and human-in-the-loop workflows. The library is actively maintained with frequent minor releases, currently at version 0.11.5, and is on a roadmap towards a major v1.0 release.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple 'ConversableAgent' with an LLM configuration and run an interaction. It uses OpenAI's API, expecting `OPENAI_API_KEY` to be set as an environment variable. The `run()` method prepares the conversation, and `process()` executes it.

import os
from autogen import ConversableAgent, LLMConfig

# Set your OpenAI API key as an environment variable
# Example: export OPENAI_API_KEY="YOUR_API_KEY"

llm_config = LLMConfig(
    {
        "api_type": "openai",
        "model": "gpt-5-nano", # or any other supported model
        "api_key": os.environ.get("OPENAI_API_KEY", "")
    }
)

# Create our LLM agent
my_agent = ConversableAgent(
    name="poetic_assistant",
    system_message="You are a poetic AI assistant, respond in rhyme.",
    llm_config=llm_config,
)

# Run the agent with a prompt and process the response
response = my_agent.run(
    message="In one sentence, what's the big deal about AI?",
    max_turns=3,
    user_input=False, # Set to True for interactive input
)

print(response.process().json())

view raw JSON →