Skip to content

Commit

Permalink
[CLEANUP]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Mar 27, 2024
1 parent 41c5295 commit cd58ffa
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 25 deletions.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -991,9 +991,40 @@ print(out)
### Compliant Interface for Multi-Agent Collaboration

```python
from swarms import Agent, AbstractSwarm
from swarms import AutoSwarm, AutoSwarmRouter, BaseSwarm


# Build your own Swarm
class MySwarm(BaseSwarm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def run(self, task: str, *args, **kwargs):
# Add your multi-agent logic here
# agent 1
# agent 2
# agent 3
return "output of the swarm"


# Add your custom swarm to the AutoSwarmRouter
router = AutoSwarmRouter(
swarms=[MySwarm]
)


# Create an AutoSwarm instance
autoswarm = AutoSwarm(
name = "AutoSwarm, an API for all swarms",
description="A simple API to build and run swarms",
verbose=True,
router=router,
)


# Run the AutoSwarm
autoswarm.run("Analyze these financial data and give me a summary")


```

Expand Down
10 changes: 5 additions & 5 deletions docs/corporate/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ The goal of the Swarm Architecture is to provide a flexible and scalable system

## Design Components

### AbstractSwarm
### BaseSwarm

The AbstractSwarm is an abstract base class which defines the basic structure of a swarm and the methods that need to be implemented. Any new swarm should inherit from this class and implement the required methods.
The BaseSwarm is an abstract base class which defines the basic structure of a swarm and the methods that need to be implemented. Any new swarm should inherit from this class and implement the required methods.

### Swarm Classes

Various Swarm classes can be implemented inheriting from the AbstractSwarm class. Each swarm class should implement the required methods for initializing the components, worker nodes, and boss node, and running the swarm.
Various Swarm classes can be implemented inheriting from the BaseSwarm class. Each swarm class should implement the required methods for initializing the components, worker nodes, and boss node, and running the swarm.

Pre-configured swarm classes with multi-modal agents can be provided for ease of use. These classes come with a default configuration of tools and agents, which can be used out of the box.

Expand All @@ -91,7 +91,7 @@ To use a pre-configured swarm, they can simply instantiate the corresponding swa

To create a custom swarm, they need to:

1. Define a new swarm class inheriting from AbstractSwarm.
1. Define a new swarm class inheriting from BaseSwarm.
2. Implement the required methods for the new swarm class.
3. Instantiate the swarm class and call the run method.

Expand All @@ -103,7 +103,7 @@ swarm = PreConfiguredSwarm(openai_api_key)
swarm.run_swarms(objective)

# Creating custom swarm
class CustomSwarm(AbstractSwarm):
class CustomSwarm(BaseSwarm):
# Implement required methods

swarm = CustomSwarm(openai_api_key)
Expand Down
10 changes: 5 additions & 5 deletions docs/swarms/structs/abstractswarm.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `AbstractSwarm` Documentation
# `BaseSwarm` Documentation

## Table of Contents

Expand Down Expand Up @@ -41,9 +41,9 @@ The Swarms library is designed to provide a framework for swarm simulation archi

## 2. Class Definition <a name="class-definition"></a>

### `AbstractSwarm` Class
### `BaseSwarm` Class

The `AbstractSwarm` class is an abstract base class that serves as the foundation for swarm simulation architectures. It defines the core functionality and methods required to manage and interact with a swarm of workers.
The `BaseSwarm` class is an abstract base class that serves as the foundation for swarm simulation architectures. It defines the core functionality and methods required to manage and interact with a swarm of workers.

```python
from abc import ABC, abstractmethod
Expand All @@ -52,7 +52,7 @@ from typing import List
from swarms.swarms.base import AbstractWorker


class AbstractSwarm(ABC):
class BaseSwarm(ABC):
"""
Abstract class for swarm simulation architectures
Expand Down Expand Up @@ -513,4 +513,4 @@ swarm.save_swarm_state()

---

This comprehensive documentation covers the Swarms library, including the `AbstractSwarm` class and its methods. You can use this documentation as a guide to understanding and effectively utilizing the Swarms framework for swarm simulation architectures. Feel free to explore further and adapt the library to your specific use cases.
This comprehensive documentation covers the Swarms library, including the `BaseSwarm` class and its methods. You can use this documentation as a guide to understanding and effectively utilizing the Swarms framework for swarm simulation architectures. Feel free to explore further and adapt the library to your specific use cases.
33 changes: 33 additions & 0 deletions playground/structs/build_your_own_swarm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from swarms import AutoSwarm, AutoSwarmRouter, BaseSwarm


# Build your own Swarm
class MySwarm(BaseSwarm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def run(self, task: str, *args, **kwargs):
# Add your multi-agent logic here
# agent 1
# agent 2
# agent 3
return "output of the swarm"


# Add your custom swarm to the AutoSwarmRouter
router = AutoSwarmRouter(
swarms=[MySwarm]
)


# Create an AutoSwarm instance
autoswarm = AutoSwarm(
name = "AutoSwarm, an API for all swarms",
description="A simple API to build and run swarms",
verbose=True,
router=router,
)


# Run the AutoSwarm
autoswarm.run("Analyze these financial data and give me a summary")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "swarms"
version = "4.6.7"
version = "4.6.8"
description = "Swarms - Pytorch"
license = "MIT"
authors = ["Kye Gomez <[email protected]>"]
Expand Down
4 changes: 2 additions & 2 deletions swarms/structs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from swarms.structs.auto_swarm import AutoSwarm, AutoSwarmRouter
from swarms.structs.autoscaler import AutoScaler
from swarms.structs.base import BaseStructure
from swarms.structs.base_swarm import AbstractSwarm
from swarms.structs.base_swarm import BaseSwarm
from swarms.structs.base_workflow import BaseWorkflow
from swarms.structs.block_wrapper import block
from swarms.structs.concurrent_workflow import ConcurrentWorkflow
Expand Down Expand Up @@ -90,7 +90,7 @@
"AutoSwarmRouter",
"AutoScaler",
"BaseStructure",
"AbstractSwarm",
"BaseSwarm",
"BaseWorkflow",
"block",
"ConcurrentWorkflow",
Expand Down
12 changes: 6 additions & 6 deletions swarms/structs/auto_swarm.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Any, Callable, Dict, Optional, Sequence

from swarms.models.base_llm import AbstractLLM
from swarms.structs.base_swarm import AbstractSwarm
from swarms.structs.base_swarm import BaseSwarm
from swarms.utils.loguru_logger import logger


class SequentialAccountingSwarm(AbstractSwarm):
class SequentialAccountingSwarm(BaseSwarm):
"""SequentialAccountingSwarm class represents a swarm of agents that can be created automatically.
Flow:
Expand Down Expand Up @@ -66,7 +66,7 @@ def run(self, task: str = None, *args, **kwargs):
return final


class AutoSwarmRouter(AbstractSwarm):
class AutoSwarmRouter(BaseSwarm):
"""AutoSwarmRouter class represents a router for the AutoSwarm class.
This class is responsible for routing tasks to the appropriate swarm based on the provided name.
Expand All @@ -77,7 +77,7 @@ class AutoSwarmRouter(AbstractSwarm):
description (str): The description of the router.
verbose (bool): Whether to enable verbose mode.
custom_params (dict): Custom parameters for the router.
swarms (list): A list of AbstractSwarm objects.
swarms (list): A list of BaseSwarm objects.
custom_preprocess (callable): Custom preprocessing function for tasks.
custom_postprocess (callable): Custom postprocessing function for task results.
custom_router (callable): Custom routing function for tasks.
Expand All @@ -96,7 +96,7 @@ def __init__(
description: Optional[str] = None,
verbose: bool = False,
custom_params: Optional[Dict[str, Any]] = None,
swarms: Sequence[AbstractSwarm] = None,
swarms: Sequence[BaseSwarm] = None,
custom_preprocess: Optional[Callable] = None,
custom_postprocess: Optional[Callable] = None,
custom_router: Optional[Callable] = None,
Expand Down Expand Up @@ -159,7 +159,7 @@ def run(self, task: str = None, *args, **kwargs):
raise e


class AutoSwarm(AbstractSwarm):
class AutoSwarm(BaseSwarm):
"""AutoSwarm class represents a swarm of agents that can be created automatically.
Flow:
Expand Down
2 changes: 1 addition & 1 deletion swarms/structs/base_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from swarms.structs.omni_agent_types import agent


class AbstractSwarm(ABC):
class BaseSwarm(ABC):
"""
Abstract Swarm Class for multi-agent systems
Expand Down
4 changes: 2 additions & 2 deletions swarms/structs/sermon_swarm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Union, Sequence, List, Callable
from swarms.structs.agent import Agent
from swarms.structs.base_swarm import AbstractSwarm
from swarms.structs.base_swarm import BaseSwarm


class SermonSwarm(AbstractSwarm):
class SermonSwarm(BaseSwarm):
"""
Represents a swarm of agents that communicate through sermons.
Expand Down
4 changes: 2 additions & 2 deletions swarms/structs/swarm_redis_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from redis.commands.graph import Graph, Node

from swarms.structs.agent import Agent
from swarms.structs.base_swarm import AbstractSwarm
from swarms.structs.base_swarm import BaseSwarm


class SwarmRelationship:
JOINED = "joined"


class RedisSwarmRegistry(AbstractSwarm):
class RedisSwarmRegistry(BaseSwarm):
"""
Initialize the SwarmRedisRegistry object.
Expand Down

0 comments on commit cd58ffa

Please sign in to comment.