Last modified: Jun 11, 2026

Install Microsoft AutoGen in Python

Microsoft AutoGen is a powerful framework for building multi-agent AI systems. It helps you create conversational agents that work together. This guide shows you how to install it in Python.

We will cover prerequisites, installation steps, and verification. You will also see code examples. Let's get started.

What Is Microsoft AutoGen?

AutoGen simplifies building AI agents. These agents can chat, solve tasks, and use tools. It works with models like GPT-4 and Llama. You can create complex workflows easily.

The framework is open-source. It supports Python 3.8 and above. Many developers use it for automation and research.

Prerequisites for Installation

Before installing, check your system. You need Python 3.8 or newer. Use a virtual environment to avoid conflicts.

Open your terminal or command prompt. Run this to check Python version:


python --version

If you see version 3.8 or higher, you are ready. If not, download Python from the official website.

Also, ensure pip is installed. Run pip --version to verify. Pip is the package installer for Python.

Step 1: Create a Virtual Environment

Virtual environments keep dependencies separate. This prevents version conflicts. Use venv module to create one.

Run these commands in your terminal:


python -m venv autogen-env

Activate the environment. On Windows:


autogen-env\Scripts\activate

On macOS or Linux:


source autogen-env/bin/activate

You will see the environment name in your prompt. This means it is active.

Step 2: Install AutoGen Using Pip

Now install AutoGen. Use pip install with the package name.

Run this command:


pip install pyautogen

This installs the core library. It may take a few minutes. You will see progress bars and success messages.

For additional features, install extras. For example, use pip install pyautogen[teams] for team workflows. Or pip install pyautogen[web] for web tools. Check the official docs for all options.

Step 3: Verify the Installation

After installation, verify it works. Open a Python interpreter or create a script.

Run this code:


import autogen
print(autogen.__version__)

You should see the version number. For example:


0.2.0

If there are no errors, AutoGen is installed successfully. If you see an ImportError, check your environment or reinstall.

Step 4: Set Up API Keys

AutoGen uses language models. You need an API key from a provider like OpenAI. Set it as an environment variable.

On Windows (Command Prompt):


set OPENAI_API_KEY=your-key-here

On macOS/Linux:


export OPENAI_API_KEY=your-key-here

For security, never hardcode keys in scripts. Use environment variables or a .env file.

Example: Basic Agent Setup

Let's create a simple agent. This agent will respond to a message.

Create a file named test_agent.py. Add this code:


# Import AutoGen
import autogen

# Configure the language model
config_list = [
    {
        "model": "gpt-4",
        "api_key": "your-openai-api-key"  # Replace with your key
    }
]

# Create an assistant agent
assistant = autogen.AssistantAgent(
    name="Assistant",
    llm_config={"config_list": config_list}
)

# Create a user proxy agent
user_proxy = autogen.UserProxyAgent(
    name="User",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=10,
    is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
    code_execution_config={
        "work_dir": "coding",
        "use_docker": False
    }
)

# Start a conversation
user_proxy.initiate_chat(
    assistant,
    message="What is the capital of France?"
)

Replace your-openai-api-key with your actual key. Then run the script:


python test_agent.py

You should see output like this:


User (to Assistant):

What is the capital of France?

Assistant (to User):

The capital of France is Paris.

This shows a basic conversation. The agent uses GPT-4 to answer.

Troubleshooting Common Issues

Sometimes installation fails. Here are common problems and fixes.

Problem: pip not found
Solution: Install pip using python -m ensurepip --upgrade.

Problem: Version conflict
Solution: Use a fresh virtual environment. Delete the old one and recreate it.

Problem: API key error
Solution: Check your environment variable. Ensure it is set correctly. Use echo $OPENAI_API_KEY to verify.

Problem: Module not found
Solution: Ensure the virtual environment is active. Run pip list to see installed packages.

Best Practices for AutoGen

Follow these tips for smooth development.

  • Always use virtual environments.
  • Keep API keys secure. Use dotenv or key vaults.
  • Update regularly. Run pip install --upgrade pyautogen.
  • Read the official documentation for advanced features.

AutoGen is under active development. Check for breaking changes when upgrading.

Conclusion

Installing Microsoft AutoGen in Python is straightforward. You need Python, pip, and a virtual environment. Then run pip install pyautogen. Verify with a simple import.

Set up your API key and test with a basic agent. This framework opens doors to multi-agent AI systems. Start building today.

For more Python tutorials, explore related topics on our site. Happy coding.