Create a virtual environment (optional)

When installing AG2 locally, we recommend using a virtual environment for the installation. This will ensure that the dependencies for AG2 are isolated from the rest of your system.

Create and activate:

python3 -m venv autogen
source autogen/bin/activate

To deactivate later, run:

deactivate

Install AG2

AG2 requires Python version >= 3.9, < 3.14. It can be installed from pip:

pip install autogen
openai>=1 is required.

Install Docker for Code Execution

We recommend using Docker for code execution. To install Docker, follow the instructions for your operating system on the Docker website.

A simple example of how to use Docker for code execution is shown below:

from pathlib import Path
from autogen import UserProxyAgent
from autogen.coding import DockerCommandLineCodeExecutor

work_dir = Path("coding")
work_dir.mkdir(exist_ok=True)

with DockerCommandLineCodeExecutor(work_dir=work_dir) as code_executor:
    user_proxy = UserProxyAgent(
        name="user_proxy",
        code_execution_config={"executor": code_executor},
    )

To learn more about code executors, see the code executors tutorial.

You might have seen a different way of defining the executors without creating the executor object, please refer to FAQ for this legacy code executor.