AG2 (formerly AutoGen) is an open-source programming framework for building AI agents and facilitating their cooperation to solve tasks. AG2 supports tool use, autonomous and human-in-the-loop workflows, and multi-agent conversation patterns.

Let’s go

pip install ag2

If you have been using autogen or pyautogen, all you need to do is upgrade it using:

pip install -U autogen

or

pip install -U pyautogen

as pyautogen, autogen, and ag2 are aliases for the same PyPI package.

# 1. Import our agent class
from autogen import ConversableAgent

# 2. Define our LLM configuration for OpenAI's GPT-4o mini
#    uses the OPENAI_API_KEY environment variable
llm_config = {"model": "gpt-4o-mini"}

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

# 4. Create our human in the loop
the_human = ConversableAgent(
    name="user",
    human_input_mode="ALWAYS",
)

# 5. Get a reply from our agent
chat_result = the_human.initiate_chat(
    recipient=my_agent,
    message="In one sentence, what's the big deal about AI?"
    )

# 6. Print the chat
print(chat_result.chat_history)

Learn more about configuring LLMs for agents here.

Where to Go Next?

If you like our project, please give it a star on GitHub. If you are interested in contributing, please read Contributor’s Guide.