DEV Community

Alex Spinov
Alex Spinov

Posted on

AG2 Has a Free API: Microsoft's Framework for Multi-Agent AI Systems

What if you could have AI agents debate, collaborate, and solve problems together — without writing orchestration code? That's AG2 (formerly AutoGen).

What Is AG2?

AG2 (evolved from Microsoft's AutoGen) is a framework for building multi-agent AI systems. Instead of one AI doing everything, you create specialized agents that work together:

from ag2 import ConversableAgent

# Create a coder agent
coder = ConversableAgent(
    name="coder",
    system_message="You write Python code to solve problems.",
    llm_config={"model": "gpt-4"}
)

# Create a reviewer agent
reviewer = ConversableAgent(
    name="reviewer",
    system_message="You review code for bugs and improvements.",
    llm_config={"model": "gpt-4"}
)

# They collaborate automatically
result = reviewer.initiate_chat(
    coder,
    message="Write a function to find prime numbers up to N, optimized for large N."
)
Enter fullscreen mode Exit fullscreen mode

The coder writes code. The reviewer reviews it. They iterate until the code is good. No orchestration code needed.

Key Patterns

1. Two-agent chat — Agent A talks to Agent B until task is done.

2. Group chat — Multiple agents discuss, with a manager routing messages:

from ag2 import GroupChat, GroupChatManager

group = GroupChat(agents=[coder, reviewer, tester], messages=[], max_round=10)
manager = GroupChatManager(groupchat=group, llm_config=llm_config)
Enter fullscreen mode Exit fullscreen mode

3. Human-in-the-loop — Agents can ask humans for input:

human = ConversableAgent("human", human_input_mode="ALWAYS")
Enter fullscreen mode Exit fullscreen mode

4. Tool use — Agents can call functions:

@coder.register_for_execution()
@reviewer.register_for_llm(description="Run Python code")
def execute_code(code: str) -> str:
    return exec_and_capture(code)
Enter fullscreen mode Exit fullscreen mode

Why AG2

  • Conversation-driven — agents collaborate through natural dialogue
  • Code execution — built-in sandboxed code execution (Docker)
  • Model agnostic — OpenAI, Anthropic, local models, Azure
  • Teachable agents — agents learn from interactions and remember
  • Nested chats — agents can spawn sub-conversations
pip install ag2
Enter fullscreen mode Exit fullscreen mode

Building AI agent systems or data pipelines? Check out my AI tools or email spinov001@gmail.com.

Top comments (0)