# Class Name: SwarmNetwork## Overview and IntroductionThe `SwarmNetwork` class is responsible for managing the agents pool and the task queue. It also monitors the health of the agents and scales the pool up or down based on the number of pending tasks and the current load of the agents.
## Class DefinitionThe `SwarmNetwork` class has the following parameters:
| Parameter | Type | Description |
|-------------------|-------------------|-------------------------------------------------------------------------------|
| idle_threshold | float | Threshold for idle agents to trigger scaling down |
| busy_threshold | float | Threshold for busy agents to trigger scaling up |
| agents | List[Agent] | List of agent instances to be added to the pool |
| api_enabled | Optional[bool] | Flag to enable/disable the API functionality |
| logging_enabled | Optional[bool] | Flag to enable/disable logging |
| other arguments | *args | Additional arguments |
| other keyword | **kwargs | Additional keyword arguments |
## Function Explanation and Usage### Function: `add_task`-Adds a task to the task queue
-Parameters:
-`task`: The task to be added to the queue
-Example:
```pythonfromswarms.structs.agentimportAgentfromswarms.structs.swarm_netimportSwarmNetworkagent=Agent()swarm=SwarmNetwork(agents=[agent])swarm.add_task("task") ```### Function: `async_add_task`-Asynchronous function to add a task to the task queue
-Parameters:
-`task`: The task to be added to the queue
-Example:
```pythonfromswarms.structs.agentimportAgentfromswarms.structs.swarm_netimportSwarmNetworkagent=Agent()swarm=SwarmNetwork(agents=[agent])awaitswarm.async_add_task("task") ```### Function: `run_single_agent`-Executes a task on a single agent
-Parameters:
-`agent_id`: ID of the agent to run the task on
-`task`: The task to be executed by the agent (optional)
-Returns:
-Result of the task execution
-Example:
```pythonfromswarms.structs.agentimportAgentfromswarms.structs.swarm_netimportSwarmNetworkagent=Agent()swarm=SwarmNetwork(agents=[agent])swarm.run_single_agent(agent_id,"task") ```### Function: `run_many_agents`-Executes a task on all the agents in the pool
-Parameters:
-`task`: The task to be executed by the agents (optional)
-Returns:
-List of results from each agent
-Example:
```pythonfromswarms.structs.agentimportAgentfromswarms.structs.swarm_netimportSwarmNetworkagent=Agent()swarm=SwarmNetwork(agents=[agent])swarm.run_many_agents("task") ```### Function: `list_agents`-Lists all the agents in the pool
-Returns:
-List of active agents
-Example:
```pythonfromswarms.structs.agentimportAgentfromswarms.structs.swarm_netimportSwarmNetworkagent=Agent()swarm=SwarmNetwork(agents=[agent])swarm.list_agents() ```### Function: `add_agent`-Adds an agent to the agent pool
-Parameters:
-`agent`: Agent instance to be added to the pool
-Example:
```pythonfromswarms.structs.agentimportAgentfromswarms.structs.swarm_netimportSwarmNetworkagent=Agent()swarm=SwarmNetwork()swarm.add_agent(agent) ```### Function: `remove_agent`-Removes an agent from the agent pool
-Parameters:
-`agent_id`: ID of the agent to be removed from the pool
-Example:
```pythonfromswarms.structs.agentimportAgentfromswarms.structs.swarm_netimportSwarmNetworkagent=Agent()swarm=SwarmNetwork(agents=[agent])swarm.remove_agent(agent_id) ```### Function: `scale_up`-Scales up the agent pool by adding new agents
-Parameters:
-`num_agents`: Number of agents to be added (optional)
-Example:
```pythonfromswarms.structs.agentimportAgentfromswarms.structs.swarm_netimportSwarmNetworkswarm=SwarmNetwork()swarm.scale_up(num_agents=5) ```### Function: `scale_down`-Scales down the agent pool by removing existing agents
-Parameters:
-`num_agents`: Number of agents to be removed (optional)
-Example:
```pythonfromswarms.structs.agentimportAgentfromswarms.structs.swarm_netimportSwarmNetworkswarm=SwarmNetwork(agents=[agent1,agent2,agent3,agent4,agent5])swarm.scale_down(num_agents=2) ```### Function: `create_apis_for_agents`-Creates APIs for each agent in the pool (optional)
-Example:
```pythonfromswarms.structs.agentimportAgentfromswarms.structs.swarm_netimportSwarmNetworkagent=Agent()swarm=SwarmNetwork(agents=[agent])swarm.create_apis_for_agents() ```## Additional Information-The `SwarmNetwork` class is an essential part of the swarms.structs library, enabling efficient management and scaling of agent pools.