This package contains everything needed to deploy AgentSystem as a Celery worker on a Raspberry Pi 5 with AI HAT+. The Pi5 functions as a distributed worker alongside a primary CPU in the AgentSystem distributed AI architecture.
pi5_deployment_package/
├── README.md # This file
├── .env.pi5 # Pi5-specific environment template
├── pi5_requirements.txt # Optimized dependencies for Pi5
├── agentsystem-pi5-worker.service # Systemd service file
├── pi5_health_check.py # Health monitoring script
├── scripts/ # Deployment and setup scripts
│ ├── install.sh # Main installation script
│ └── setup_environment.sh # Environment setup script
└── AgentSystem/ # Complete AgentSystem codebase
├── pi5_worker.py # Main Pi5 worker entry point
├── core/ # Core system modules
├── modules/ # Feature modules
├── services/ # AI and external services
├── utils/ # Utility functions
├── config/ # Configuration files
├── docs/ # Documentation
├── examples/ # Usage examples
└── tests/ # Test suite
# Copy the entire package to your Pi5
scp -r pi5_deployment_package/ pi@your-pi5-ip:/home/pi/
# SSH into your Pi5
ssh pi@your-pi5-ip
# Navigate to the package directory
cd /home/pi/pi5_deployment_package
# Make scripts executable
chmod +x scripts/*.sh
# Run the installation script
sudo ./scripts/install.sh
# Copy and edit the environment file
sudo cp .env.pi5 /opt/agentsystem/.env
sudo nano /opt/agentsystem/.env
# Update the following required settings:
# - CELERY_BROKER_URL=redis://YOUR_MAIN_SERVER_IP:6379/0
# - CELERY_RESULT_BACKEND=redis://YOUR_MAIN_SERVER_IP:6379/0
# - MAIN_SERVER_HOST=YOUR_MAIN_SERVER_IP
# - OPENAI_API_KEY=your_api_key (or other AI provider)
# Enable and start the systemd service
sudo systemctl enable agentsystem-pi5-worker
sudo systemctl start agentsystem-pi5-worker
# Check status
sudo systemctl status agentsystem-pi5-worker
The .env.pi5 file contains Pi5-optimized settings. Key configurations include:
Celery Worker Settings:
CELERY_WORKER_CONCURRENCY=2 - Optimized for Pi5 CPU coresCELERY_WORKER_PREFETCH_MULTIPLIER=1 - Prevents memory overloadCELERY_WORKER_LOGLEVEL=INFO - Appropriate logging levelResource Constraints:
MAX_MEMORY_USAGE=6GB - Prevents OOM on 8GB Pi5MAX_CPU_USAGE=80 - Leaves headroom for system processesTHREAD_POOL_SIZE=4 - Optimized for Pi5 architectureHardware Optimization:
ENABLE_AI_HAT=true - Enables AI HAT+ integrationVIDEO_RESOLUTION=320x240 - Reduced for Pi5 performanceAUDIO_CHUNK_SIZE=512 - Optimized buffer sizeThe pi5_requirements.txt file contains ARM64-optimized packages:
# Install with specific optimizations
pip install -r pi5_requirements.txt --no-cache-dir
# For better performance, consider system packages:
sudo apt install python3-opencv python3-numpy python3-scipy
The systemd service provides automatic startup and monitoring:
# Service management commands
sudo systemctl start agentsystem-pi5-worker # Start
sudo systemctl stop agentsystem-pi5-worker # Stop
sudo systemctl restart agentsystem-pi5-worker # Restart
sudo systemctl status agentsystem-pi5-worker # Check status
# View logs
sudo journalctl -u agentsystem-pi5-worker -f # Follow logs
sudo journalctl -u agentsystem-pi5-worker -n 50 # Last 50 lines
Use the health check script to monitor system status:
# Basic health check
python3 /opt/agentsystem/pi5_health_check.py
# Verbose output
python3 /opt/agentsystem/pi5_health_check.py --verbose
# JSON output for monitoring systems
python3 /opt/agentsystem/pi5_health_check.py --json
# Set up automated monitoring (crontab)
# Add to crontab (crontab -e):
*/5 * * * * /opt/agentsystem/venv/bin/python3 /opt/agentsystem/pi5_health_check.py --json >> /opt/agentsystem/logs/health_check.log 2>&1
The Pi5 worker operates as part of a distributed AgentSystem:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Main Server │ │ Pi5 Worker │ │ Other Workers │
│ │ │ │ │ │
│ • Task Queue │◄──►│ • Celery Worker │ │ • Additional │
│ • Redis Broker │ │ • AI HAT+ │ │ Pi5 Units │
│ • Orchestrator │ │ • Local Tasks │ │ • Cloud Workers │
│ • Web Interface │ │ • Monitoring │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
The Pi5 worker handles specific task types:
# Add to /boot/config.txt for better memory allocation
gpu_mem=128
arm_boost=1
# Set performance governor
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# Enable zram for better memory management
sudo apt install zram-tools
Monitor these Pi5-specific metrics:
1. Worker Not Connecting to Broker:
# Test Redis connection
redis-cli -h YOUR_MAIN_SERVER_IP ping
# Check firewall on main server
sudo ufw status
2. High CPU Temperature:
# Check temperature
vcgencmd measure_temp
# Improve cooling or reduce concurrency in .env
CELERY_WORKER_CONCURRENCY=1
3. Memory Issues:
# Check memory usage
free -h
# Reduce memory limits in .env
MAX_MEMORY_USAGE=4GB
4. Service Won’t Start:
# Check detailed logs
sudo journalctl -u agentsystem-pi5-worker -f
# Verify file permissions
sudo chown -R agentsystem:agentsystem /opt/agentsystem
Important log locations:
sudo journalctl -u agentsystem-pi5-worker/opt/agentsystem/logs//opt/agentsystem/logs/health_check.log/var/log/syslog# Activate development mode in .env
DEVELOPMENT_MODE=true
ENABLE_DEBUGGING=true
# Run worker manually for testing
cd /opt/agentsystem
source venv/bin/activate
celery -A AgentSystem.pi5_worker worker --loglevel=debug
# Test basic functionality
python3 -c "
import sys
sys.path.append('/opt/agentsystem')
from AgentSystem.pi5_worker import app
print('Pi5 worker imported successfully')
"
# Test Celery connection
python3 -c "
import sys
sys.path.append('/opt/agentsystem')
from AgentSystem.pi5_worker import app
result = app.control.inspect().stats()
print('Celery connection test:', 'SUCCESS' if result else 'FAILED')
"
# Secure the installation
sudo chown -R agentsystem:agentsystem /opt/agentsystem
sudo chmod 750 /opt/agentsystem
sudo chmod 600 /opt/agentsystem/.env
# Regular system updates
sudo apt update && sudo apt upgrade
# Update Python packages
pip install --upgrade -r pi5_requirements.txt
# Backup configuration before updates
sudo cp /opt/agentsystem/.env /opt/agentsystem/.env.backup
AgentSystem/docs/ directoryAgentSystem/docs/pi5_setup_guide.mdAgentSystem/docs/api/AgentSystem/examples/This project is licensed under the same terms as the main AgentSystem project. See AgentSystem/LICENSE for details.
Note: This deployment package is specifically optimized for Raspberry Pi 5 with AI HAT+. For other platforms, use the standard AgentSystem installation process.