AG2: Open-Source AgentOS for AI Agents

0.11.5 · active · verified Mon Apr 13

AG2 (formerly AutoGen) is an open-source programming framework for building AI agents and facilitating cooperation among multiple agents to solve tasks. It provides fundamental building blocks to create, deploy, and manage AI agents, supporting various LLMs, tool use, autonomous and human-in-the-loop workflows, and multi-agent conversation patterns. The current version is 0.11.5 and it maintains a rapid release cadence with frequent updates and new features.

Warnings

Install

Imports

Quickstart

This quickstart initializes a `ConversableAgent` with an OpenAI LLM configuration and runs a single-turn conversation. It demonstrates basic agent creation and interaction, requiring the `OPENAI_API_KEY` environment variable to be set.

import os
from autogen import ConversableAgent, LLMConfig

# Ensure your OpenAI API key is set as an environment variable
# For example: export OPENAI_API_KEY="YOUR_API_KEY"

openai_api_key = os.environ.get("OPENAI_API_KEY", "")

if not openai_api_key:
    print("Error: OPENAI_API_KEY environment variable is not set.")
    exit()

llm_config = LLMConfig(
    {
        "api_type": "openai",
        "model": "gpt-5-nano",
        "api_key": openai_api_key
    }
)

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

# Run the agent with a prompt
response = my_agent.run(
    message="In one sentence, what's the big deal about AI?",
    max_turns=1, # Limit turns for a quick, non-interactive example
    user_input=False, # Disable human input for automatic execution
)

# Print the agent's final response
if response.chat_history:
    print(response.chat_history[-1]["content"])
else:
    print("No response generated.")

view raw JSON →