AutoGen
AutoGen is a framework that allows for the development of LLM applications using multiple agents that can converse with each other to solve tasks. The `pyautogen` PyPI package (current version 0.10.0) acts as a proxy, primarily installing `autogen-agentchat` to provide the core multi-agent conversation capabilities. It has a relatively rapid release cadence, with minor versions often released monthly or more frequently, introducing new features and breaking changes.
Warnings
- gotcha The PyPI package is `pyautogen`, but the modules are imported from the `autogen` namespace (e.g., `import autogen`). Importing from `pyautogen` will fail.
- breaking The structure of `llm_config` and `config_list` has changed multiple times between minor versions (e.g., 0.1.x, 0.2.x, 0.6.x, 0.9.x). Ensure your configuration matches the exact version's documentation.
- breaking The `autogen.oai.Completion` module and related utilities for direct OpenAI API calls were moved or refactored. In newer versions, the primary way to interact with models is through agent `llm_config`.
- gotcha `UserProxyAgent`'s `human_input_mode` defaults to `ALWAYS` or `TERMINATE` depending on the version, which can pause execution indefinitely waiting for user input. For fully autonomous execution, set `human_input_mode="NEVER"`.
- gotcha API key management requires a `config_list` where models and keys are defined. While environment variables (e.g., `OPENAI_API_KEY`) are common, they must still be referenced correctly within `config_list` or an `OAI_CONFIG_LIST` JSON file.
Install
-
pip install pyautogen -
pip install pyautogen[blend]
Imports
- UserProxyAgent
from pyautogen import UserProxyAgent
from autogen import UserProxyAgent
- AssistantAgent
from pyautogen import AssistantAgent
from autogen import AssistantAgent
- config_list_from_json
from autogen import config_list_from_json
- GroupChat
from autogen.groupchat import GroupChat
- GroupChatManager
from autogen.groupchat import GroupChatManager
Quickstart
import autogen
import os
# Configure API key from environment variable or direct config_list
config_list = [
{
"model": "gpt-4o",
"api_key": os.environ.get("OPENAI_API_KEY", None)
}
]
# Define agents
assistant = autogen.AssistantAgent(
name="Assistant",
llm_config={
"config_list": config_list,
"temperature": 0.7
}
)
user_proxy = autogen.UserProxyAgent(
name="UserProxy",
human_input_mode="NEVER", # Set to "ALWAYS" or "TERMINATE" for human interaction
max_consecutive_auto_reply=10,
is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
code_execution_config={
"work_dir": "coding", # Create a 'coding' directory for code execution
"use_docker": False # Set to True to use Docker for safer execution
}
)
# Start a chat
user_proxy.initiate_chat(
assistant,
message="What is the capital of France?"
)