Skip to content

Swarms Framework Environment Configuration

This guide details the environment variables used in the Swarms framework for configuration and customization of your agent-based applications.

Configuration Setup

Create a .env file in your project's root directory to configure the Swarms framework. This file will contain all necessary environment variables for customizing your agent's behavior, logging, and analytics.

Environment Variables

Core Variables

WORKSPACE_DIR

  • Purpose: Defines the directory where all agent states and execution logs are stored
  • Type: String (path)
  • Default: ./workspace
  • Example:
    WORKSPACE_DIR=/path/to/your/workspace
    
  • Usage:
  • Stores JSON files containing agent states
  • Maintains execution history
  • Keeps track of agent interactions
  • Preserves conversation logs

SWARMS_AUTOUPDATE_ON

  • Purpose: Controls automatic updates of the Swarms framework
  • Type: Boolean
  • Default: false
  • Example:
    SWARMS_AUTOUPDATE_ON=true
    
  • Features:
  • Automatically updates to the latest stable version
  • Ensures you have the newest features
  • Maintains compatibility with the latest improvements
  • Handles dependency updates
  • Considerations:
  • Set to false if you need version stability
  • Recommended true for development environments
  • Consider system requirements for auto-updates
  • May require restart after updates

Telemetry Configuration

USE_TELEMETRY

  • Purpose: Controls whether telemetry data is collected
  • Type: Boolean
  • Default: false
  • Example:
    USE_TELEMETRY=true
    
  • Data Collected:
  • Agent performance metrics
  • Execution time statistics
  • Memory usage
  • Error rates
  • System health indicators

Analytics Integration

SWARMS_API_KEY

  • Purpose: Authentication key for the Swarms Analytics Suite
  • Type: String
  • Required: Yes, for analytics features
  • Example:
    SWARMS_API_KEY=your_api_key_here
    
  • Features:
  • Real-time agent execution tracking
  • Usage analytics
  • Performance monitoring
  • Cost tracking
  • Custom metrics

Getting Started

  1. Create a new .env file:

    touch .env
    

  2. Add your configuration:

    # Basic configuration
    WORKSPACE_DIR=./my_workspace
    
    # Enable auto-updates
    SWARMS_AUTOUPDATE_ON=true
    
    # Enable telemetry
    USE_TELEMETRY=true
    
    # Add your Swarms API key
    SWARMS_API_KEY=your_api_key_here
    

  3. Obtain your API key:

  4. Visit swarms.ai
  5. Create an account or log in
  6. Navigate to the API section
  7. Generate your unique API key

Best Practices

  1. Security:
  2. Never commit your .env file to version control
  3. Add .env to your .gitignore file
  4. Keep your API keys secure and rotate them periodically

  5. Workspace Organization:

  6. Use descriptive workspace directory names
  7. Implement regular cleanup of old logs
  8. Monitor workspace size to prevent disk space issues

  9. Telemetry Management:

  10. Enable telemetry in development for debugging
  11. Consider privacy implications in production
  12. Review collected data periodically

  13. Auto-Update Management:

  14. Test updates in development before enabling in production
  15. Keep backups before enabling auto-updates
  16. Monitor system resources during updates
  17. Schedule updates during low-traffic periods

Examples

Basic Development Setup

WORKSPACE_DIR=./dev_workspace
SWARMS_AUTOUPDATE_ON=true
USE_TELEMETRY=true
SWARMS_API_KEY=sk_test_xxxxxxxxxxxx

Production Setup

WORKSPACE_DIR=/var/log/swarms/prod_workspace
SWARMS_AUTOUPDATE_ON=false
USE_TELEMETRY=true
SWARMS_API_KEY=sk_prod_xxxxxxxxxxxx

Testing Environment

WORKSPACE_DIR=./test_workspace
SWARMS_AUTOUPDATE_ON=true
USE_TELEMETRY=false
SWARMS_API_KEY=sk_test_xxxxxxxxxxxx

Troubleshooting

Common issues and solutions:

  1. Workspace Access Issues:
  2. Ensure proper file permissions
  3. Verify the directory exists
  4. Check disk space availability

  5. API Key Problems:

  6. Confirm key is properly formatted
  7. Verify key hasn't expired
  8. Check for proper environment variable loading

  9. Telemetry Issues:

  10. Confirm network connectivity
  11. Verify firewall settings
  12. Check for proper boolean values

  13. Auto-Update Issues:

  14. Check internet connectivity
  15. Verify sufficient disk space
  16. Ensure proper permissions for updates
  17. Check system compatibility requirements

Additional Resources