### Enterprise Grade Documentation --- ## AutoScaler Class from `swarms` Package The `AutoScaler` class, part of the `swarms` package, provides a dynamic mechanism to handle agents depending on the workload. This document outlines how to use it, complete with import statements and examples. --- ### Importing the AutoScaler Class Before you can use the `AutoScaler` class, you must import it from the `swarms` package: ```python from swarms import AutoScaler ``` --- ### Constructor: `AutoScaler.__init__()` **Description**: Initializes the `AutoScaler` with a predefined number of agents and sets up configurations for scaling. **Parameters**: - `initial_agents (int)`: Initial number of agents. Default is 10. - `scale_up_factor (int)`: Multiplicative factor to scale up the number of agents. Default is 2. - `idle_threshold (float)`: Threshold below which agents are considered idle. Expressed as a ratio (0-1). Default is 0.2. - `busy_threshold (float)`: Threshold above which agents are considered busy. Expressed as a ratio (0-1). Default is 0.7. **Returns**: - None **Example Usage**: ```python from swarms import AutoScaler scaler = AutoScaler(initial_agents=5, scale_up_factor=3, idle_threshold=0.1, busy_threshold=0.8) ``` --- ### Method: `AutoScaler.add_task(task)` **Description**: Enqueues the specified task into the task queue. **Parameters**: - `task`: The task to be added to the queue. **Returns**: - None **Example Usage**: ```python task_data = "Process dataset X" scaler.add_task(task_data) ``` --- ### Method: `AutoScaler.scale_up()` **Description**: Scales up the number of agents based on the specified scale-up factor. **Parameters**: - None **Returns**: - None **Example Usage**: ```python # Called internally but can be manually invoked if necessary scaler.scale_up() ``` --- ### Method: `AutoScaler.scale_down()` **Description**: Scales down the number of agents, ensuring a minimum is always present. **Parameters**: - None **Returns**: - None **Example Usage**: ```python # Called internally but can be manually invoked if necessary scaler.scale_down() ``` --- ### Method: `AutoScaler.monitor_and_scale()` **Description**: Continuously monitors the task queue and agent utilization to decide on scaling. **Parameters**: - None **Returns**: - None **Example Usage**: ```python # This method is internally used as a thread and does not require manual invocation in most scenarios. ``` --- ### Method: `AutoScaler.start()` **Description**: Initiates the monitoring process and starts processing tasks from the queue. **Parameters**: - None **Returns**: - None **Example Usage**: ```python scaler.start() ``` --- ### Full Usage ```python from swarms import AutoScaler # Initialize the scaler auto_scaler = AutoScaler(initial_agents=15, scale_up_factor=2, idle_threshold=0.2, busy_threshold=0.7) # Start the monitoring and task processing auto_scaler.start() # Simulate the addition of tasks for i in range(100): auto_scaler.add_task(f"Task {i}") ``` ### Pass in Custom Agent You can pass any agent class that adheres to the required interface (like having a run() method). If no class is passed, it defaults to using AutoBot. This makes the AutoScaler more flexible and able to handle a wider range of agent implementations. ```python from swarms import AutoScaler auto_scaler = AutoScaler(agent=YourCustomAgent) auto_scaler.start() for i in range(100): # Adding tasks auto_scaler.add_task(f"Task {i}") ``` --- **Notes**: 1. Adjust the thresholds and scaling factors as per your specific requirements and nature of the tasks. 2. The provided implementation is a baseline. Depending on your production environment, you may need additional features, error-handling, and optimizations. 3. Ensure that the `swarms` package and its dependencies are installed in your environment. ---