Get the FREE Ultimate OpenClaw Setup Guide →

ag2

AG2 (formerly AutoGen): The Open-Source AgentOS. Join us at: https://discord.gg/sNGSwQME3x

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio ag2ai-ag2 python -m ag2 \
  --env OPENAI_API_KEY="Your OpenAI API key (alternative to using a config file)" \
  --env OAI_CONFIG_LIST="Path to a JSON file containing OpenAI API configurations"

How to use

AG2 is an open-source framework for building AI agents that can cooperate to solve tasks. The server exposes tooling to instantiate and orchestrate multiple agents, register tools, and run autonomous or human-in-the-loop workflows. With AG2 you can create conversational agents, enable tool usage, and coordinate agent teams (swarms, sequential chats, and more) to tackle complex problems. The server harnesses a Python package that supports different LLM providers and flexible configuration to run agents locally or in integration environments. Typical usage involves starting the server and interacting with agents through code or the provided examples to spawn agents, assign tasks, and monitor progress.

Once running, you can leverage AG2's capabilities to:

  • Create Conversable Agents that can send and receive messages and execute actions using registered tools.
  • Enable Human-in-the-Loop workflows where human feedback can shape or correct agent outputs.
  • Orchestrate multiple agents with built-in patterns (swarm, group chats, nested chats, etc.) to delegate sub-tasks and converge on solutions.
  • Integrate with various LLMs and external tools to extend agent capabilities, including code execution, document processing, web access, and more.

To use the server, import and configure your agents in Python, set up your API keys or config files as described, and run the ag2 module. The framework will manage agent lifecycles, message routing, and tool invocations, returning structured outputs and summaries for each conversation or task run.

How to install

Prerequisites:

  • Python 3.10 or newer (check compatibility with your environment)
  • pip (Python package installer)
  1. Create and activate a virtual environment (recommended):
  • macOS/Linux: python -m venv venv source venv/bin/activate
  • Windows: python -m venv venv .\venv\Scripts\activate
  1. Install the AG2 package from PyPI (with OpenAI extras if you plan to use OpenAI tools):
pip install 'ag2[openai]'
  1. Optional: install additional dependencies for extra features (if needed).

  2. Verify installation by running a quick import test:

python -c "import autogen  # or import ag2; print('AG2 ready')"
  1. Prepare configuration for API keys (see below) and start the server as described in the mcp_config section.

Additional notes

Configuration tips:

  • Use a dedicated JSON config file for API keys (OAI_CONFIG_LIST) to keep keys separate from code. The file should be referenced by the OAI_CONFIG_LIST environment variable.
  • If you prefer environment-based keys, set OPENAI_API_KEY directly, but avoid committing keys to source control.
  • When running locally, ensure your Python environment has network access to call external LLM providers.
  • If you encounter dependency issues, consider creating a clean virtual environment and reinstalling with the extras (pip install 'ag2[openai]').
  • The AG2 server can be extended by registering additional tools and configuring agent orchestration patterns to match your workflow requirements.

Common issues:

  • Module not found: Ensure you installed the package in the same Python environment where you run the server.
  • API key errors: Double-check the format and accessibility of your OAI_CONFIG_LIST or OPENAI_API_KEY.
  • Incompatible Python version: Confirm that the Python version falls within the supported range for the AG2 version you are using.

Related MCP Servers

Sponsor this space

Reach thousands of developers