diff --git a/README.md b/README.md index 3a868771..aaec0ba8 100644 --- a/README.md +++ b/README.md @@ -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") + ``` diff --git a/docs/corporate/design.md b/docs/corporate/design.md index 3e739ad3..9a0e8590 100644 --- a/docs/corporate/design.md +++ b/docs/corporate/design.md @@ -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. @@ -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. @@ -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) diff --git a/docs/swarms/structs/abstractswarm.md b/docs/swarms/structs/abstractswarm.md index 6bdf736b..82ebf44e 100644 --- a/docs/swarms/structs/abstractswarm.md +++ b/docs/swarms/structs/abstractswarm.md @@ -1,4 +1,4 @@ -# `AbstractSwarm` Documentation +# `BaseSwarm` Documentation ## Table of Contents @@ -41,9 +41,9 @@ The Swarms library is designed to provide a framework for swarm simulation archi ## 2. Class Definition -### `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 @@ -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 @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/playground/structs/build_your_own_swarm.py b/playground/structs/build_your_own_swarm.py new file mode 100644 index 00000000..8bb47b9c --- /dev/null +++ b/playground/structs/build_your_own_swarm.py @@ -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") \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 4f54b588..de204024 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] diff --git a/swarms/structs/__init__.py b/swarms/structs/__init__.py index 39e8057e..3dbf5488 100644 --- a/swarms/structs/__init__.py +++ b/swarms/structs/__init__.py @@ -7,7 +7,7 @@ from swarms.structs.agent_process import ( 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 @@ -90,7 +90,7 @@ __all__ = [ "AutoSwarmRouter", "AutoScaler", "BaseStructure", - "AbstractSwarm", + "BaseSwarm", "BaseWorkflow", "block", "ConcurrentWorkflow", diff --git a/swarms/structs/auto_swarm.py b/swarms/structs/auto_swarm.py index 97aaf7e4..10946331 100644 --- a/swarms/structs/auto_swarm.py +++ b/swarms/structs/auto_swarm.py @@ -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: @@ -66,7 +66,7 @@ class SequentialAccountingSwarm(AbstractSwarm): 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. @@ -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. @@ -96,7 +96,7 @@ class AutoSwarmRouter(AbstractSwarm): 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, @@ -159,7 +159,7 @@ class AutoSwarmRouter(AbstractSwarm): raise e -class AutoSwarm(AbstractSwarm): +class AutoSwarm(BaseSwarm): """AutoSwarm class represents a swarm of agents that can be created automatically. Flow: diff --git a/swarms/structs/base_swarm.py b/swarms/structs/base_swarm.py index ade0624a..f2f30b86 100644 --- a/swarms/structs/base_swarm.py +++ b/swarms/structs/base_swarm.py @@ -19,7 +19,7 @@ from swarms.utils.loguru_logger import logger from swarms.structs.omni_agent_types import agent -class AbstractSwarm(ABC): +class BaseSwarm(ABC): """ Abstract Swarm Class for multi-agent systems diff --git a/swarms/structs/sermon_swarm.py b/swarms/structs/sermon_swarm.py index 895670ad..59522b9a 100644 --- a/swarms/structs/sermon_swarm.py +++ b/swarms/structs/sermon_swarm.py @@ -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. diff --git a/swarms/structs/swarm_redis_registry.py b/swarms/structs/swarm_redis_registry.py index a17549cd..a15ce55f 100644 --- a/swarms/structs/swarm_redis_registry.py +++ b/swarms/structs/swarm_redis_registry.py @@ -6,14 +6,14 @@ import redis 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.