|
|
|
|
|
""" |
|
|
Setup script for Secure AI Agents Suite |
|
|
Initializes the environment and prepares all components |
|
|
""" |
|
|
|
|
|
import os |
|
|
import sys |
|
|
import subprocess |
|
|
import logging |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
def setup_logging(): |
|
|
"""Set up logging for the setup process.""" |
|
|
logging.basicConfig( |
|
|
level=logging.INFO, |
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' |
|
|
) |
|
|
return logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
def check_python_version(): |
|
|
"""Check if Python version is compatible.""" |
|
|
if sys.version_info < (3, 8): |
|
|
print("β Python 3.8 or higher is required") |
|
|
return False |
|
|
print(f"β
Python version: {sys.version}") |
|
|
return True |
|
|
|
|
|
|
|
|
def install_dependencies(): |
|
|
"""Install required dependencies.""" |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
logger.info("Installing dependencies from requirements.txt...") |
|
|
try: |
|
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) |
|
|
logger.info("β
Dependencies installed successfully") |
|
|
return True |
|
|
except subprocess.CalledProcessError as e: |
|
|
logger.error(f"β Failed to install dependencies: {e}") |
|
|
return False |
|
|
|
|
|
|
|
|
def create_directories(): |
|
|
"""Create necessary directories.""" |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
directories = [ |
|
|
"logs", |
|
|
"data", |
|
|
"temp", |
|
|
"cache", |
|
|
"exports" |
|
|
] |
|
|
|
|
|
for directory in directories: |
|
|
dir_path = Path(directory) |
|
|
dir_path.mkdir(exist_ok=True) |
|
|
logger.info(f"β
Created directory: {directory}") |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
def setup_configuration(): |
|
|
"""Set up configuration files.""" |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
env_example = Path(".env.example") |
|
|
env_file = Path(".env") |
|
|
|
|
|
if not env_file.exists() and env_example.exists(): |
|
|
import shutil |
|
|
shutil.copy(env_example, env_file) |
|
|
logger.info("β
Created .env file from .env.example") |
|
|
logger.info("β οΈ Please update .env file with your API keys and configuration") |
|
|
elif env_file.exists(): |
|
|
logger.info("β
.env file already exists") |
|
|
else: |
|
|
logger.warning("β οΈ No .env.example found to create .env file") |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
def create_launcher_scripts(): |
|
|
"""Create convenient launcher scripts.""" |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
launch_script = """#!/bin/bash |
|
|
# Secure AI Agents Suite Launcher |
|
|
|
|
|
echo "π Starting Secure AI Agents Suite..." |
|
|
echo "Available agents:" |
|
|
echo " 1. Enterprise Agent (Port 7860)" |
|
|
echo " 2. Consumer Agent (Port 7861)" |
|
|
echo " 3. Creative Agent (Port 7862)" |
|
|
echo " 4. Voice Agent (Port 7863)" |
|
|
echo "" |
|
|
read -p "Select agent to launch (1-4) or 'all': " choice |
|
|
|
|
|
case $choice in |
|
|
1) |
|
|
echo "π’ Starting Enterprise Agent..." |
|
|
python enterprise/enterprise_app.py |
|
|
;; |
|
|
2) |
|
|
echo "π₯ Starting Consumer Agent..." |
|
|
python consumer/consumer_app.py |
|
|
;; |
|
|
3) |
|
|
echo "π¨ Starting Creative Agent..." |
|
|
python creative/creative_app.py |
|
|
;; |
|
|
4) |
|
|
echo "π€ Starting Voice Agent..." |
|
|
python voice/voice_app.py |
|
|
;; |
|
|
all) |
|
|
echo "π Starting all agents..." |
|
|
echo "β οΈ Note: This will try to start all agents simultaneously" |
|
|
echo "You may need to run them in separate terminals" |
|
|
echo "" |
|
|
echo "To start all agents, run these commands in separate terminals:" |
|
|
echo " Terminal 1: python enterprise/enterprise_app.py" |
|
|
echo " Terminal 2: python consumer/consumer_app.py" |
|
|
echo " Terminal 3: python creative/creative_app.py" |
|
|
echo " Terminal 4: python voice/voice_app.py" |
|
|
;; |
|
|
*) |
|
|
echo "Invalid choice" |
|
|
;; |
|
|
esac |
|
|
""" |
|
|
|
|
|
with open("launch_agents.sh", "w") as f: |
|
|
f.write(launch_script) |
|
|
|
|
|
|
|
|
os.chmod("launch_agents.sh", 0o755) |
|
|
logger.info("β
Created launch script: launch_agents.sh") |
|
|
|
|
|
|
|
|
batch_script = """@echo off |
|
|
REM Secure AI Agents Suite Launcher |
|
|
|
|
|
echo π Starting Secure AI Agents Suite... |
|
|
echo Available agents: |
|
|
echo 1. Enterprise Agent (Port 7860) |
|
|
echo 2. Consumer Agent (Port 7861) |
|
|
echo 3. Creative Agent (Port 7862) |
|
|
echo 4. Voice Agent (Port 7863) |
|
|
echo. |
|
|
set /p choice="Select agent to launch (1-4) or 'all': " |
|
|
|
|
|
if "%choice%"=="1" ( |
|
|
echo π’ Starting Enterprise Agent... |
|
|
python enterprise/enterprise_app.py |
|
|
) else if "%choice%"=="2" ( |
|
|
echo π₯ Starting Consumer Agent... |
|
|
python consumer/consumer_app.py |
|
|
) else if "%choice%"=="3" ( |
|
|
echo π¨ Starting Creative Agent... |
|
|
python creative/creative_app.py |
|
|
) else if "%choice%"=="4" ( |
|
|
echo π€ Starting Voice Agent... |
|
|
python voice/voice_app.py |
|
|
) else if "%choice%"=="all" ( |
|
|
echo π Starting all agents... |
|
|
echo β οΈ Note: This will try to start all agents simultaneously |
|
|
echo You may need to run them in separate command prompts |
|
|
echo. |
|
|
echo To start all agents, run these commands in separate terminals: |
|
|
echo Terminal 1: python enterprise/enterprise_app.py |
|
|
echo Terminal 2: python consumer/consumer_app.py |
|
|
echo Terminal 3: python creative/creative_app.py |
|
|
echo Terminal 4: python voice/voice_app.py |
|
|
) else ( |
|
|
echo Invalid choice |
|
|
) |
|
|
|
|
|
pause |
|
|
""" |
|
|
|
|
|
with open("launch_agents.bat", "w") as f: |
|
|
f.write(batch_script) |
|
|
|
|
|
logger.info("β
Created Windows launcher: launch_agents.bat") |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
def run_tests(): |
|
|
"""Run basic tests to ensure components work.""" |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
logger.info("Running component tests...") |
|
|
|
|
|
|
|
|
test_imports = [ |
|
|
("app_base", "Core application base"), |
|
|
("mcp_client", "MCP client"), |
|
|
("config_manager", "Configuration manager") |
|
|
] |
|
|
|
|
|
for module_name, description in test_imports: |
|
|
try: |
|
|
__import__(module_name) |
|
|
logger.info(f"β
{description} - Import successful") |
|
|
except ImportError as e: |
|
|
logger.error(f"β {description} - Import failed: {e}") |
|
|
return False |
|
|
|
|
|
|
|
|
agent_imports = [ |
|
|
("enterprise.enterprise_agent", "Enterprise Agent"), |
|
|
("consumer.consumer_agent", "Consumer Agent"), |
|
|
("creative.creative_agent", "Creative Agent"), |
|
|
("voice.voice_agent", "Voice Agent") |
|
|
] |
|
|
|
|
|
for module_name, description in agent_imports: |
|
|
try: |
|
|
__import__(module_name) |
|
|
logger.info(f"β
{description} - Import successful") |
|
|
except ImportError as e: |
|
|
logger.error(f"β {description} - Import failed: {e}") |
|
|
return False |
|
|
|
|
|
logger.info("β
All tests passed!") |
|
|
return True |
|
|
|
|
|
|
|
|
def print_next_steps(): |
|
|
"""Print next steps for the user.""" |
|
|
print("\n" + "="*60) |
|
|
print("π SECURE AI AGENTS SUITE SETUP COMPLETE!") |
|
|
print("="*60) |
|
|
|
|
|
print("\nπ Next Steps:") |
|
|
print("1. Update your .env file with API keys:") |
|
|
print(" β’ OpenAI API key for GPT-4o integration") |
|
|
print(" β’ Google API key for Gemini integration") |
|
|
print(" β’ ElevenLabs API key for voice synthesis") |
|
|
print(" β’ Configure MCP server URLs (optional for demo)") |
|
|
|
|
|
print("\n2. Launch agents:") |
|
|
print(" β’ Use the launcher script: ./launch_agents.sh (Linux/Mac)") |
|
|
print(" β’ Or launch_agents.bat (Windows)") |
|
|
print(" β’ Or run individual agents:") |
|
|
print(" - python enterprise/enterprise_app.py") |
|
|
print(" - python consumer/consumer_app.py") |
|
|
print(" - python creative/creative_app.py") |
|
|
print(" - python voice/voice_app.py") |
|
|
|
|
|
print("\n3. Access the web interfaces:") |
|
|
print(" β’ Enterprise: http://localhost:7860") |
|
|
print(" β’ Consumer: http://localhost:7861") |
|
|
print(" β’ Creative: http://localhost:7862") |
|
|
print(" β’ Voice: http://localhost:7863") |
|
|
|
|
|
print("\n4. Deploy to production:") |
|
|
print(" β’ Configure production MCP servers") |
|
|
print(" β’ Set up Modal deployment for Voice Agent") |
|
|
print(" β’ Deploy to Hugging Face Spaces") |
|
|
|
|
|
print("\nπ Documentation:") |
|
|
print(" β’ README.md - Main documentation") |
|
|
print(" β’ docs/ - Additional documentation") |
|
|
|
|
|
print("\nπ§ Support:") |
|
|
print(" β’ Check logs in logs/ directory") |
|
|
print(" β’ Validate configuration with config_manager.py") |
|
|
print(" β’ Run setup.py --test to verify installation") |
|
|
|
|
|
|
|
|
def main(): |
|
|
"""Main setup function.""" |
|
|
logger = setup_logging() |
|
|
|
|
|
print("π§ Secure AI Agents Suite - Setup Script") |
|
|
print("="*50) |
|
|
|
|
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "--test": |
|
|
print("π§ͺ Running tests only...") |
|
|
success = run_tests() |
|
|
sys.exit(0 if success else 1) |
|
|
|
|
|
|
|
|
steps = [ |
|
|
("Checking Python version", check_python_version), |
|
|
("Installing dependencies", install_dependencies), |
|
|
("Creating directories", create_directories), |
|
|
("Setting up configuration", setup_configuration), |
|
|
("Creating launcher scripts", create_launcher_scripts), |
|
|
("Running tests", run_tests) |
|
|
] |
|
|
|
|
|
success = True |
|
|
for step_name, step_func in steps: |
|
|
print(f"\nπ {step_name}...") |
|
|
try: |
|
|
if not step_func(): |
|
|
print(f"β {step_name} failed!") |
|
|
success = False |
|
|
break |
|
|
except Exception as e: |
|
|
print(f"β {step_name} failed with exception: {e}") |
|
|
success = False |
|
|
break |
|
|
|
|
|
if success: |
|
|
print("\nβ
Setup completed successfully!") |
|
|
print_next_steps() |
|
|
else: |
|
|
print("\nβ Setup failed! Please check the errors above.") |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |