From 4b1c7a76fb42b9370e632f13c41b8a91460afeee Mon Sep 17 00:00:00 2001 From: AG2AI-Admin Date: Fri, 18 Jul 2025 08:55:23 -0400 Subject: [PATCH] Migrate from pyautogen to ag2 library --- APPLE_SILICON_SETUP.md | 8 ++++---- AUTOGEN_FIX_README.md | 20 ++++++++++---------- autogen_compat/__init__.py | 18 +++++++++--------- backup_files/APPLE_SILICON_SETUP.md | 8 ++++---- backup_files/requirements.txt | 2 +- backup_files/setup.sh | 6 +++--- fix_anaconda.sh | 2 +- fix_autogen_dependency.sh | 20 ++++++++++---------- requirements.txt | 2 +- setup.sh | 2 +- setup_implementation_details.md | 2 +- test_autogen_compat.py | 10 +++++----- test_setup.sh | 2 +- 13 files changed, 51 insertions(+), 51 deletions(-) diff --git a/APPLE_SILICON_SETUP.md b/APPLE_SILICON_SETUP.md index c0c1438..4d075e3 100644 --- a/APPLE_SILICON_SETUP.md +++ b/APPLE_SILICON_SETUP.md @@ -242,11 +242,11 @@ If you encounter errors related to code analysis tools like radon or flake8: ### Autogen/Pyautogen Issues -If you encounter errors related to autogen or pyautogen: +If you encounter errors related to autogen or ag2: 1. Make sure both packages are installed: ```bash - poetry run pip install autogen==0.2.35 pyautogen==0.2.35 + poetry run pip install autogen==0.2.35 ag2==0.2.35 ``` 2. The codebase uses autogen, so make sure to use the correct import statements: ```python @@ -259,7 +259,7 @@ If you encounter errors related to autogen or pyautogen: # Check if autogen is installed poetry run pip list | grep autogen ``` -4. Note that autogen and pyautogen are different packages with similar functionality. The project uses autogen. +4. Note that autogen and ag2 are different packages with similar functionality. The project uses autogen. ### Streamlit Extensions Issues @@ -339,7 +339,7 @@ If Ollama server checks fail: - flake8: 7.1.1 - streamlit-extras: 0.3.6 - autogen: 0.2.35 -- pyautogen: 0.2.35 +- ag2: 0.2.35 ### Architecture Changes diff --git a/AUTOGEN_FIX_README.md b/AUTOGEN_FIX_README.md index a569322..1c803fd 100644 --- a/AUTOGEN_FIX_README.md +++ b/AUTOGEN_FIX_README.md @@ -11,13 +11,13 @@ ERROR: No matching distribution found for autogen==0.2.35 ### Root Causes -1. **Package Name Confusion**: The project is trying to install `autogen==0.2.35`, but this version doesn't exist in PyPI. The correct package name for version 0.2.35 is `pyautogen`. +1. **Package Name Confusion**: The project is trying to install `autogen==0.2.35`, but this version doesn't exist in PyPI. The correct package name for version 0.2.35 is `ag2`. 2. **Import Namespace Mismatch**: The code imports from the `autogen` namespace: ```python from autogen import ConversableAgent, UserProxyAgent, GroupChat, GroupChatManager ``` - But when installing `pyautogen`, the imports need to be from the `pyautogen` namespace. + But when installing `ag2`, the imports need to be from the `ag2` namespace. 3. **Strict Version Requirements**: The requirements.txt file specifies exact versions for many packages, which can cause compatibility issues across different systems. @@ -25,9 +25,9 @@ ERROR: No matching distribution found for autogen==0.2.35 This fix addresses these issues by: -1. **Updating requirements.txt**: Using more flexible version specifications and correcting the package name from `autogen` to `pyautogen`. +1. **Updating requirements.txt**: Using more flexible version specifications and correcting the package name from `autogen` to `ag2`. -2. **Creating a Compatibility Layer**: A Python module that redirects imports from `autogen` to `pyautogen`, allowing the code to work without modifications. +2. **Creating a Compatibility Layer**: A Python module that redirects imports from `autogen` to `ag2`, allowing the code to work without modifications. 3. **Providing a Helper Script**: A shell script that sets up the environment correctly to use the compatibility layer. @@ -74,9 +74,9 @@ Run your application using the compatibility layer: The compatibility layer creates a Python module named `autogen_compat` that: -1. Imports `pyautogen` when code tries to import `autogen` -2. Adds the imported `pyautogen` module to `sys.modules['autogen']` -3. Also redirects submodule imports (e.g., `autogen.oai` → `pyautogen.oai`) +1. Imports `ag2` when code tries to import `autogen` +2. Adds the imported `ag2` module to `sys.modules['autogen']` +3. Also redirects submodule imports (e.g., `autogen.oai` → `ag2.oai`) This allows your code to continue using `import autogen` statements without modification. @@ -84,9 +84,9 @@ This allows your code to continue using `import autogen` statements without modi If you encounter issues: -1. **Verify pyautogen is installed**: +1. **Verify ag2 is installed**: ```bash - pip show pyautogen + pip show ag2 ``` 2. **Check PYTHONPATH**: Make sure the current directory is in your PYTHONPATH: @@ -108,7 +108,7 @@ If you encounter issues: While this compatibility layer provides an immediate fix, consider these long-term solutions: -1. **Update imports**: Gradually update your codebase to import from `pyautogen` directly +1. **Update imports**: Gradually update your codebase to import from `ag2` directly 2. **Use Poetry**: Consider using Poetry for dependency management, which handles these issues more gracefully 3. **Loosen version requirements**: Use version ranges (e.g., `>=0.2.0,<0.3.0`) instead of exact versions diff --git a/autogen_compat/__init__.py b/autogen_compat/__init__.py index 86fc34d..22fccc7 100644 --- a/autogen_compat/__init__.py +++ b/autogen_compat/__init__.py @@ -1,6 +1,6 @@ """ Compatibility layer for autogen imports. -This module redirects imports from 'autogen' to 'pyautogen'. +This module redirects imports from 'autogen' to 'ag2'. """ import sys @@ -9,21 +9,21 @@ # Show a warning about the compatibility layer warnings.warn( - "Using autogen_compat layer: 'autogen' package is not available, redirecting to 'pyautogen'", + "Using autogen_compat layer: 'autogen' package is not available, redirecting to 'ag2'", ImportWarning ) -# Try to import pyautogen +# Try to import ag2 try: - import pyautogen + import ag2 except ImportError: raise ImportError( - "Neither 'autogen' nor 'pyautogen' package is installed. " - "Please install pyautogen with: pip install pyautogen>=0.2.0" + "Neither 'autogen' nor 'ag2' package is installed. " + "Please install ag2 with: pip install ag2>=0.2.0" ) # Add the module to sys.modules -sys.modules['autogen'] = pyautogen +sys.modules['autogen'] = ag2 # Also make submodules available for submodule_name in [ @@ -32,8 +32,8 @@ 'function_utils', 'graph_utils', 'retrieve_utils', 'runtime_logging', 'types' ]: try: - submodule = importlib.import_module(f'pyautogen.{submodule_name}') + submodule = importlib.import_module(f'ag2.{submodule_name}') sys.modules[f'autogen.{submodule_name}'] = submodule except ImportError: - # If the submodule doesn't exist in pyautogen, just skip it + # If the submodule doesn't exist in ag2, just skip it pass diff --git a/backup_files/APPLE_SILICON_SETUP.md b/backup_files/APPLE_SILICON_SETUP.md index c0c1438..4d075e3 100644 --- a/backup_files/APPLE_SILICON_SETUP.md +++ b/backup_files/APPLE_SILICON_SETUP.md @@ -242,11 +242,11 @@ If you encounter errors related to code analysis tools like radon or flake8: ### Autogen/Pyautogen Issues -If you encounter errors related to autogen or pyautogen: +If you encounter errors related to autogen or ag2: 1. Make sure both packages are installed: ```bash - poetry run pip install autogen==0.2.35 pyautogen==0.2.35 + poetry run pip install autogen==0.2.35 ag2==0.2.35 ``` 2. The codebase uses autogen, so make sure to use the correct import statements: ```python @@ -259,7 +259,7 @@ If you encounter errors related to autogen or pyautogen: # Check if autogen is installed poetry run pip list | grep autogen ``` -4. Note that autogen and pyautogen are different packages with similar functionality. The project uses autogen. +4. Note that autogen and ag2 are different packages with similar functionality. The project uses autogen. ### Streamlit Extensions Issues @@ -339,7 +339,7 @@ If Ollama server checks fail: - flake8: 7.1.1 - streamlit-extras: 0.3.6 - autogen: 0.2.35 -- pyautogen: 0.2.35 +- ag2: 0.2.35 ### Architecture Changes diff --git a/backup_files/requirements.txt b/backup_files/requirements.txt index 372f3d6..b4047be 100644 --- a/backup_files/requirements.txt +++ b/backup_files/requirements.txt @@ -1,6 +1,6 @@ langchain-community==0.2.15 langchain==0.2.15 -pyautogen==0.2.35 +ag2==0.2.35 Flask-Cors==5.0.0 Flask==3.0.3 Requests==2.32.3 diff --git a/backup_files/setup.sh b/backup_files/setup.sh index 64308ff..8aeaad6 100755 --- a/backup_files/setup.sh +++ b/backup_files/setup.sh @@ -205,7 +205,7 @@ if [ $? -ne 0 ]; then $POETRY_CMD run pip install "langchain==0.2.15" # Install missing dependencies from requirements.txt echo "Debug: Installing missing dependencies" - $POETRY_CMD run pip install "ollama==0.2.0" "chromadb==0.5.5" "psutil==6.0.0" "pdfkit==1.0.0" "matplotlib==3.9.2" "beautifulsoup4==4.12.3" "bs4==0.0.2" "selenium==4.24.0" "webdriver-manager==4.0.2" "PyPDF2==3.0.1" "streamlit-extras==0.3.6" "autogen==0.2.35" "pyautogen==0.2.35" "fpdf==1.7.2" "radon==6.0.1" "flake8==7.1.1" + $POETRY_CMD run pip install "ollama==0.2.0" "chromadb==0.5.5" "psutil==6.0.0" "pdfkit==1.0.0" "matplotlib==3.9.2" "beautifulsoup4==4.12.3" "bs4==0.0.2" "selenium==4.24.0" "webdriver-manager==4.0.2" "PyPDF2==3.0.1" "streamlit-extras==0.3.6" "autogen==0.2.35" "ag2==0.2.35" "fpdf==1.7.2" "radon==6.0.1" "flake8==7.1.1" # Install additional dependencies from requirements.txt that might be missing echo "Debug: Installing additional dependencies from requirements.txt" @@ -307,12 +307,12 @@ dependencies = [ "streamlit", "langchain", "transformers", "ollama", "chromadb", "pandas", "psutil", "requests", "matplotlib", "beautifulsoup4", "bs4", "selenium", "webdriver_manager", "PyPDF2", - "streamlit_extras", "autogen", "pyautogen", "fpdf", "radon", "flake8" + "streamlit_extras", "autogen", "ag2", "fpdf", "radon", "flake8" ] # Add detailed error checking for critical dependencies print("\n=== Critical Dependencies Check ===") -critical_deps = ["ollama", "chromadb", "psutil", "pdfkit", "matplotlib", "bs4", "selenium", "webdriver_manager", "PyPDF2", "streamlit_extras", "autogen", "pyautogen", "fpdf", "radon", "flake8"] +critical_deps = ["ollama", "chromadb", "psutil", "pdfkit", "matplotlib", "bs4", "selenium", "webdriver_manager", "PyPDF2", "streamlit_extras", "autogen", "ag2", "fpdf", "radon", "flake8"] for dep in critical_deps: try: module = __import__(dep) diff --git a/fix_anaconda.sh b/fix_anaconda.sh index 8e54bc0..ae046ca 100755 --- a/fix_anaconda.sh +++ b/fix_anaconda.sh @@ -59,7 +59,7 @@ PACKAGES=( "gtts==2.5.4" "pygame==2.6.1" "autogen==0.2.35" - "pyautogen==0.2.35" + "ag2==0.2.35" "fake-useragent==1.5.1" ) diff --git a/fix_autogen_dependency.sh b/fix_autogen_dependency.sh index 0088c81..1758075 100755 --- a/fix_autogen_dependency.sh +++ b/fix_autogen_dependency.sh @@ -58,7 +58,7 @@ mkdir -p autogen_compat cat > autogen_compat/__init__.py << 'EOL' """ Compatibility layer for autogen imports. -This module redirects imports from 'autogen' to 'pyautogen'. +This module redirects imports from 'autogen' to 'ag2'. """ import sys @@ -67,21 +67,21 @@ import warnings # Show a warning about the compatibility layer warnings.warn( - "Using autogen_compat layer: 'autogen' package is not available, redirecting to 'pyautogen'", + "Using autogen_compat layer: 'autogen' package is not available, redirecting to 'ag2'", ImportWarning ) -# Try to import pyautogen +# Try to import ag2 try: - import pyautogen + import ag2 except ImportError: raise ImportError( - "Neither 'autogen' nor 'pyautogen' package is installed. " - "Please install pyautogen with: pip install pyautogen>=0.2.0" + "Neither 'autogen' nor 'ag2' package is installed. " + "Please install ag2 with: pip install ag2>=0.2.0" ) # Add the module to sys.modules -sys.modules['autogen'] = pyautogen +sys.modules['autogen'] = ag2 # Also make submodules available for submodule_name in [ @@ -90,10 +90,10 @@ for submodule_name in [ 'function_utils', 'graph_utils', 'retrieve_utils', 'runtime_logging', 'types' ]: try: - submodule = importlib.import_module(f'pyautogen.{submodule_name}') + submodule = importlib.import_module(f'ag2.{submodule_name}') sys.modules[f'autogen.{submodule_name}'] = submodule except ImportError: - # If the submodule doesn't exist in pyautogen, just skip it + # If the submodule doesn't exist in ag2, just skip it pass EOL @@ -129,4 +129,4 @@ fi print_header "Fix Complete" print_info "To run your application with the compatibility layer, use:" echo -e "${YELLOW}./use_autogen_compat.sh streamlit run main.py${NC}" -print_info "This will ensure that 'import autogen' statements are redirected to 'pyautogen'" \ No newline at end of file +print_info "This will ensure that 'import autogen' statements are redirected to 'ag2'" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f113204..1bdb2e7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,7 +24,7 @@ torch>=2.0.0 transformers>=4.30.0 # Language Models & AI -pyautogen>=0.2.0 # Using pyautogen which provides the autogen namespace +ag2>=0.2.0 # Using ag2 which provides the autogen namespace groq>=0.9.0 langchain>=0.2.0 langchain-community>=0.2.0 diff --git a/setup.sh b/setup.sh index 0f877bc..0fa2ade 100755 --- a/setup.sh +++ b/setup.sh @@ -381,7 +381,7 @@ print_info "Installing development and testing packages..." # Install autogen packages print_info "Installing autogen packages..." -"$VENV_PIP" install autogen==0.2.35 pyautogen==0.2.35 +"$VENV_PIP" install autogen==0.2.35 ag2==0.2.35 # Install audio packages print_info "Installing audio packages..." diff --git a/setup_implementation_details.md b/setup_implementation_details.md index 1aaa6d9..7268c7c 100644 --- a/setup_implementation_details.md +++ b/setup_implementation_details.md @@ -270,7 +270,7 @@ authors = ["Your Name "] python = "^3.11" langchain-community = "0.2.15" langchain = "0.2.15" -pyautogen = "0.2.35" +ag2 = "0.2.35" Flask-Cors = "5.0.0" Flask = "3.0.3" Requests = "2.32.3" diff --git a/test_autogen_compat.py b/test_autogen_compat.py index 823f00e..57b1d94 100755 --- a/test_autogen_compat.py +++ b/test_autogen_compat.py @@ -51,12 +51,12 @@ def check_environment(): print(f"Python version: {sys.version}") print(f"PYTHONPATH: {os.environ.get('PYTHONPATH', 'Not set')}") - # Check if pyautogen is installed + # Check if ag2 is installed try: - import pyautogen - print(f"✓ pyautogen is installed (version: {pyautogen.__version__ if hasattr(pyautogen, '__version__') else 'unknown'})") + import ag2 + print(f"✓ ag2 is installed (version: {ag2.__version__ if hasattr(ag2, '__version__') else 'unknown'})") except ImportError: - print("✗ pyautogen is not installed") + print("✗ ag2 is not installed") # Check if the compatibility layer directory is in the path current_dir = os.path.dirname(os.path.abspath(__file__)) @@ -91,7 +91,7 @@ def check_environment(): if not success: print("\nTo fix this issue:") - print("1. Make sure pyautogen is installed: pip install pyautogen>=0.2.0") + print("1. Make sure ag2 is installed: pip install ag2>=0.2.0") print("2. Run the script with the compatibility layer: ./use_autogen_compat.sh python test_autogen_compat.py") sys.exit(0 if success else 1) \ No newline at end of file diff --git a/test_setup.sh b/test_setup.sh index 753cb59..8216a2a 100755 --- a/test_setup.sh +++ b/test_setup.sh @@ -405,7 +405,7 @@ print_info "Installing development and testing packages..." # Install autogen packages print_info "Installing autogen packages..." -"$VENV_PIP" install autogen==0.2.35 pyautogen==0.2.35 +"$VENV_PIP" install autogen==0.2.35 ag2==0.2.35 # Install audio packages print_info "Installing audio packages..."