Skip to content

Agent Zero AI framework

Added: Cuda Dockerfile. Edit: Initialize.sh to fix perms issue by adding -f force.

decib2d1aacd03e2
diff --git a/.gitignore b/.gitignore
index c67214458..421e53075 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,12 @@
**/__pycache__/
**/.conda/
+# Ignore docker/run/agent-zero directory
+docker/run/agent-zero/
+
+#Ignore cursor rules
+.cursor/
+
# ignore test files in root dir
/*.test.py
diff --git a/docker/run/Dockerfile.cuda b/docker/run/Dockerfile.cuda
new file mode 100644
index 000000000..85cc0ca64
--- /dev/null
+++ b/docker/run/Dockerfile.cuda
@@ -0,0 +1,152 @@
+# Use the NVIDIA CUDA base image with Ubuntu
+FROM nvidia/cuda:12.8.1-base-ubuntu22.04
+
+# Set non-interactive installation and timezone
+ENV DEBIAN_FRONTEND=noninteractive
+ENV TZ=UTC
+
+# Check if the argument is provided, else throw an error
+ARG BRANCH
+RUN if [ -z "$BRANCH" ]; then echo "ERROR: BRANCH is not set!" >&2; exit 1; fi
+ENV BRANCH=$BRANCH
+
+# Set locale to en_US.UTF-8 and timezone to UTC (matching main Dockerfile)
+RUN apt-get update && apt-get install -y locales tzdata
+RUN sed -i -e 's/# \(en_US\.UTF-8 .*\)/\1/' /etc/locale.gen && \
+ dpkg-reconfigure --frontend=noninteractive locales && \
+ update-locale LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8
+RUN ln -sf /usr/share/zoneinfo/UTC /etc/localtime
+RUN echo "UTC" > /etc/timezone
+RUN dpkg-reconfigure -f noninteractive tzdata
+ENV LANG=en_US.UTF-8
+ENV LANGUAGE=en_US:en
+ENV LC_ALL=en_US.UTF-8
+ENV TZ=UTC
+
+# Copy contents of the project to root directory
+COPY ./fs/ /
+
+# Fix permissions for cron files from pre_install.sh
+RUN chmod 0644 /etc/cron.d/*
+
+# Install essential packages (from pre_install.sh but avoiding supervisor from apt)
+RUN apt-get update && apt-get upgrade -y && apt-get install -y \
+ python3 \
+ python3-venv \
+ python3-pip \
+ nodejs \
+ openssh-server \
+ sudo \
+ curl \
+ wget \
+ git \
+ ffmpeg \
+ cron
+
+# Prepare SSH daemon (from pre_install.sh)
+RUN bash /ins/setup_ssh.sh $BRANCH
+
+# Configure Python 3.12 (specific to Ubuntu-based CUDA image)
+RUN apt-get update && apt-get install -y \
+ software-properties-common && \
+ add-apt-repository -y ppa:deadsnakes/ppa && \
+ apt-get update && \
+ apt-get install -y python3.12 python3.12-venv python3.12-dev && \
+ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \
+ update-alternatives --set python3 /usr/bin/python3.12
+
+# Bootstrap pip for Python 3.12 and install supervisor
+RUN python3 -m ensurepip --upgrade && \
+ python3 -m pip install --upgrade pip setuptools wheel && \
+ python3 -m pip install supervisor
+
+# Create supervisor directories
+RUN mkdir -p /var/log/supervisor /etc/supervisor/conf.d
+
+# Create root dotfiles with appropriate permissions
+RUN touch /root/.bashrc /root/.profile && \
+ chmod 644 /root/.bashrc /root/.profile
+
+# Create a symlink for supervisord to the expected location
+RUN ln -sf $(which supervisord) /usr/bin/supervisord
+
+# Install additional software
+RUN bash /ins/install_additional.sh $BRANCH
+
+# Install core CUDA dependencies (minimized to essentials)
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ cuda-cudart-dev-12-8 \
+ libcublas-dev-12-8 \
+ libcudnn8 \
+ && apt-get clean \
+ && rm -rf /var/lib/apt/lists/*
+
+# Set CUDA environment variables
+ENV PATH=/usr/local/cuda/bin:${PATH}
+ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}
+ENV CUDA_HOME=/usr/local/cuda
+ENV CUDA_VERSION=12.8.1
+
+# Install A0
+RUN bash /ins/install_A0.sh $BRANCH
+
+# Create and set up the shared instruments virtual environment
+ENV INSTRUMENTS_VENV_PATH=/opt/instruments_venv
+RUN python3 -m venv $INSTRUMENTS_VENV_PATH
+
+# Switch to bash for the next RUN step (required for set -o pipefail)
+SHELL ["/bin/bash", "-c"]
+
+# Install all heavy dependencies into the instruments venv, with explicit checks
+RUN set -euxo pipefail; \
+ . $INSTRUMENTS_VENV_PATH/bin/activate; \
+ echo "=== Upgrading pip, setuptools, wheel ==="; \
+ pip install --upgrade pip setuptools wheel; \
+ echo "=== Installing PyTorch with CUDA ==="; \
+ pip install --no-cache-dir torch==2.6.0+cu124 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124; \
+ echo "=== Installing other heavy dependencies ==="; \
+ pip install --no-cache-dir \
+ huggingface-hub==0.20.3 \
+ safetensors==0.4.1 \
+ accelerate==0.21.0 \
+ diffusers==0.25.0 \
+ transformers==4.38.2 \
+ scipy==1.15.2 \
+ xformers==0.0.29.post3; \
+ echo "=== Checking all critical imports ==="; \
+ python -c "import torch; print(f'PyTorch {torch.__version__} imported successfully. CUDA: {getattr(torch, 'cuda', None) and torch.cuda.is_available()}')" || (echo 'PyTorch import failed!' && exit 1); \
+ python -c "import torchvision; print(f'Torchvision {torchvision.__version__} imported successfully.')" || (echo 'Torchvision import failed!' && exit 1); \
+ python -c "import torchaudio; print(f'Torchaudio {torchaudio.__version__} imported successfully.')" || (echo 'Torchaudio import failed!' && exit 1); \
+ python -c "import diffusers; print(f'Diffusers {diffusers.__version__} imported successfully.')" || (echo 'Diffusers import failed!' && exit 1); \
+ python -c "import transformers; print(f'Transformers {transformers.__version__} imported successfully.')" || (echo 'Transformers import failed!' && exit 1); \
+ python -c "import xformers; print(f'Xformers {xformers.__version__} imported successfully.')" || (echo 'Xformers import failed!' && exit 1); \
+ python -c "import accelerate; print(f'Accelerate {accelerate.__version__} imported successfully.')" || (echo 'Accelerate import failed!' && exit 1); \
+ python -c "import safetensors; print(f'Safetensors {safetensors.__version__} imported successfully.')" || (echo 'Safetensors import failed!' && exit 1); \
+ python -c "import scipy; print(f'Scipy {scipy.__version__} imported successfully.')" || (echo 'Scipy import failed!' && exit 1); \
+ python -c "import huggingface_hub; print(f'Huggingface_hub {huggingface_hub.__version__} imported successfully.')" || (echo 'Huggingface_hub import failed!' && exit 1); \
+ echo "=== All critical imports succeeded ==="
+
+# Optionally revert to sh for subsequent steps if needed
+SHELL ["/bin/sh", "-c"]
+
+# The existing global PyTorch install for /opt/venv (A0's main venv) is below.
+# It might be used by other core A0 components, so we keep it.
+# Our instruments will use the dedicated $INSTRUMENTS_VENV_PATH.
+RUN . /opt/venv/bin/activate && \
+ pip uninstall -y torch torchvision && \
+ pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cu124
+
+# Cleanup repo and install A0 without caching, this speeds up builds
+ARG CACHE_DATE=none
+RUN echo "cache buster $CACHE_DATE" && bash /ins/install_A02.sh $BRANCH
+
+# Post installation steps
+RUN bash /ins/post_install.sh $BRANCH
+
+# Expose ports
+EXPOSE 22 80
+
+RUN chmod +x /exe/initialize.sh /exe/run_A0.sh /exe/run_searxng.sh
+
+# Initialize runtime
+CMD ["/exe/initialize.sh", "$BRANCH"]
\ No newline at end of file
diff --git a/docker/run/README.cuda.md b/docker/run/README.cuda.md
new file mode 100644
index 000000000..08359307b
--- /dev/null
+++ b/docker/run/README.cuda.md
@@ -0,0 +1,104 @@
+# Agent Zero: CUDA GPU Support 🚀
+
+This guide explains how to build and run Agent Zero with NVIDIA GPU acceleration using CUDA. Running with CUDA enables faster performance for AI workloads by leveraging your GPU.
+
+---
+
+## Prerequisites
+
+Before you begin, ensure you have:
+
+1. **NVIDIA GPU** with CUDA capability
+2. **NVIDIA Driver** installed on your host system
+3. **NVIDIA Container Toolkit** ([Install Guide](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html))
+ _This enables Docker to access your GPU_
+4. **Docker** and **Docker Compose** installed
+
+---
+
+## 1. Build the CUDA Docker Image
+
+Open a terminal in this directory and run:
+
+```bash
+# Set the branch you want to build from (default: main)
+$branch="main"
+docker build --no-cache -t frdel/agent-zero-run-cuda:testing --build-arg BRANCH=$branch -f Dockerfile.cuda .
+```
+
+---
+
+## 2. Run Agent Zero with CUDA Support
+
+You can start Agent Zero with GPU support using Docker Compose:
+
+```bash
+# On Linux, macOS, or Windows PowerShell:
+docker-compose -f docker-compose.cuda.yml up -d
+```
+
+- This will launch Agent Zero in the background with GPU acceleration enabled.
+
+---
+
+## 3. Access Agent Zero
+
+Once the container is running, open your browser and go to:
+
+[http://localhost:50080](http://localhost:50080)
+
+---
+
+## 4. Stopping Agent Zero
+
+To stop the CUDA-enabled Agent Zero container:
+
+```bash
+docker-compose -f docker-compose.cuda.yml down
+```
+
+---
+
+## 5. Switching Between CPU and GPU Versions
+
+You can easily switch between the CPU and GPU versions:
+
+1. **Stop the currently running version:**
+ ```bash
+ # For CPU version:
+ docker-compose down
+ # For GPU version:
+ docker-compose -f docker-compose.cuda.yml down
+ ```
+
+2. **Start the version you want:**
+ ```bash
+ # CPU version:
+ docker-compose -f docker-compose.yml up -d
+
+ # GPU (CUDA) version:
+ docker-compose -f docker-compose.cuda.yml up -d
+ ```
+
+---
+
+## Troubleshooting & Tips
+
+- **First time setup may take several minutes** as dependencies are downloaded and installed.
+- If you encounter issues with GPU access, verify your NVIDIA drivers and the NVIDIA Container Toolkit are correctly installed.
+- To check if CUDA is available inside the container, you can run:
+ ```bash
+ docker exec -it <container_name> python3 -c "import torch; print(torch.cuda.is_available())"
+ ```
+- For advanced configuration, see the comments in [`Dockerfile.cuda`](mdc:docker/run/Dockerfile.cuda).
+
+---
+
+## More Information
+
+- [NVIDIA Container Toolkit Documentation](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html)
+- [Agent Zero Project](https://github.com/frdel/agent-zero) (replace with your actual repo link if different)
+
+---
+
+**Enjoy accelerated AI with Agent Zero and CUDA!**
diff --git a/docker/run/docker-compose.cuda.yml b/docker/run/docker-compose.cuda.yml
new file mode 100644
index 000000000..2f3d7754b
--- /dev/null
+++ b/docker/run/docker-compose.cuda.yml
@@ -0,0 +1,20 @@
+services:
+ agent-zero-cuda:
+ container_name: agent-zero-cuda
+ image: frdel/agent-zero-run-cuda:testing
+ volumes:
+ - ./agent-zero:/a0
+ - ./agent-zero/work_dir:/root
+ ports:
+ - "50080:80"
+ environment:
+ - NVIDIA_VISIBLE_DEVICES=all
+ - NVIDIA_DRIVER_CAPABILITIES=compute,utility
+ - PYTHONUNBUFFERED=1
+ deploy:
+ resources:
+ reservations:
+ devices:
+ - driver: nvidia
+ count: all
+ capabilities: [gpu]
\ No newline at end of file
diff --git a/docker/run/fs/exe/initialize.sh b/docker/run/fs/exe/initialize.sh
index 170a162b2..438b2082b 100644
--- a/docker/run/fs/exe/initialize.sh
+++ b/docker/run/fs/exe/initialize.sh
@@ -8,7 +8,7 @@ fi
BRANCH="$1"
# Copy all contents from persistent /per to root directory (/) without overwriting
-cp -r --no-preserve=ownership,mode /per/* /
+cp -r -f --no-preserve=ownership,mode /per/* /
# allow execution of /root/.bashrc and /root/.profile
chmod 444 /root/.bashrc