Deploying to Production

Step 1: Prepare for 24/7 Operation

Create a production-ready script with error handling and logging:

# production_agent.py
from xynae import Xynae
import os
import logging
from dotenv import load_dotenv
from datetime import datetime

# Setup logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s',
    handlers=[
        logging.FileHandler(f'defi_sage_{datetime.now().strftime("%Y%m%d")}.log'),
        logging.StreamHandler()
    ]
)

logger = logging.getLogger(__name__)

load_dotenv()

AGENT_PERSONALITY = """
[Your refined personality prompt]
"""

def main():
    logger.info("πŸš€ Starting DeFi Sage in production mode")
    
    try:
        # Initialize agent
        agent = Xynae(
            personality=AGENT_PERSONALITY,
            llm_provider="auto",
            mongodb_uri=os.getenv("MONGODB_URI"),
            database_name="defi_sage_production",
            use_database=True
        )
        
        logger.info("βœ… Agent initialized successfully")
        logger.info(f"πŸ“Š Database: {agent.db.is_connected()}")
        logger.info(f"πŸ€– LLM Providers: {agent.llm_manager.list_available_providers()}")
        
        # Run agent
        logger.info("🎯 Starting autonomous operation")
        agent.run(tweet_interval=1200, check_interval=300)
        
    except KeyboardInterrupt:
        logger.info("πŸ‘‹ Shutting down gracefully")
    except Exception as e:
        logger.error(f"❌ Fatal error: {e}", exc_info=True)
        raise

if __name__ == "__main__":
    main()

Step 2: Set Up Process Management

Option A: Using systemd (Linux)

Create a systemd service file:

Add configuration:

Enable and start:

Option B: Using PM2 (Cross-platform)

Option C: Using Docker

Create Dockerfile:

Create docker-compose.yml:

Deploy:

Step 3: Set Up Monitoring and Alerts

Create a health check script:

Set up cron job for monitoring:


Last updated