Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mono/dev newfeatures #1040

Open
wants to merge 15 commits into
base: mono/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

documents_stores_files = [
("swarmauri_community.documents_stores.concrete.RedisDocumentStore", "RedisDocumentStore"),
]

for module_name, class_name in documents_stores_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

__all__ = [class_name for _, class_name in documents_stores_files]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader


embeddings_files = [
Expand All @@ -7,6 +7,6 @@
]

for module_name, class_name in embeddings_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

__all__ = [class_name for _, class_name in embeddings_files]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

llms_files = [
("swarmauri_community.llms.concrete.LeptonAIImgGenModel", "LeptonAIImgGenModel"),
Expand All @@ -7,6 +7,6 @@
]

for module_name, class_name in llms_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

__all__ = [class_name for _, class_name in llms_files]
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

measurement_files = [
("swarmauri_community.measurements.concrete.MutualInformationMeasurement", "MutualInformationMeasurement"),
("swarmauri_community.measurements.concrete.TokenCountEstimatorMeasurement", "TokenCountEstimatorMeasurement"),
]

for module_name, class_name in measurement_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

__all__ = [class_name for _, class_name in measurement_files]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

parsers_files = [
("swarmauri_community.parsers.concrete.BERTEmbeddingParser", "BERTEmbeddingParser"),
Expand All @@ -11,6 +11,6 @@
]

for module_name, class_name in parsers_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

__all__ = [class_name for _, class_name in parsers_files]
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

retriever_files = [
("swarmauri_community.retrievers.concrete.RedisDocumentRetriever", "RedisDocumentRetriever"),
]

for module_name, class_name in retriever_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

__all__ = [class_name for _, class_name in retriever_files]
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

state_files = [
("swarmauri_community.state.concrete.ClipboardState", "ClipboardState"),
]

for module_name, class_name in state_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

__all__ = [class_name for _, class_name in state_files]
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

toolkits_files = [
("swarmauri_community.toolkits.concrete.GithubToolkit", "GithubToolkit"),
]

for module_name, class_name in toolkits_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

__all__ = [class_name for _, class_name in toolkits_files]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

tool_files = [
("swarmauri_community.tools.concrete.CaptchaGeneratorTool", "CaptchaGeneratorTool"),
Expand Down Expand Up @@ -27,7 +27,7 @@

# Lazy loading of tools, storing them in variables
for module_name, class_name in tool_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

# Adding the lazy-loaded tools to __all__
__all__ = [class_name for _, class_name in tool_files]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

vector_store_files = [
("swarmauri_community.vector_stores.concrete.AnnoyVectorStore", "AnnoyVectorStore"),
Expand All @@ -15,6 +15,6 @@
]

for module_name, class_name in vector_store_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

__all__ = [class_name for _, class_name in vector_store_files]
1 change: 1 addition & 0 deletions pkgs/core/swarmauri_core/ComponentBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ResourceTypes(Enum):
SERVICE_REGISTRY = "ServiceRegistry"
CONTROL_PANEL = "ControlPanel"
TASK_MGT_STRATEGY = "TaskMgtStrategy"
MAS = "Mas"

def generate_id() -> str:
return str(uuid4())
Expand Down
2 changes: 1 addition & 1 deletion pkgs/core/swarmauri_core/control_panels/IControlPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class IControlPlane(ABC):
"""

@abstractmethod
def create_agent(self, name: str, role: str) -> Any:
def create_agent(self, name: str, role: str, **kwarg: Any) -> Any:
"""
Create an agent with the given name and role.
"""
Expand Down
10 changes: 10 additions & 0 deletions pkgs/core/swarmauri_core/factories/IFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ def create(self, type: str, *args: Any, **kwargs: Any) -> Any:
def register(self, type: str, resource_class: Callable) -> None:
"""Register a class with the factory."""
pass

@abstractmethod
def get(self):
"""Return a list of registered agent types."""
pass

@abstractmethod
def unregister(self, type: str) -> None:
"""Unregister a class from the factory."""
pass
39 changes: 39 additions & 0 deletions pkgs/core/swarmauri_core/mas/IMas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from typing import List, Any
from abc import ABC, abstractmethod


class IMas(ABC):
@abstractmethod
def broadcast(self, message: Any) -> None:
"""Send message to all agents in the system."""
pass

@abstractmethod
def multicast(self, message: Any, recipient_ids: List[str]) -> None:
"""Send message to a specific group of agents."""
pass

@abstractmethod
def unicast(self, message: Any, recipient_id: str) -> None:
"""Send message to a single agent."""
pass

@abstractmethod
def dispatch_task(self, task: Any, agent_id: str) -> None:
"""Assign a single task to a specific agent."""
pass

@abstractmethod
def dispatch_tasks(self, tasks: List[Any], agent_ids: List[str]) -> None:
"""Assign multiple tasks to multiple agents."""
pass

@abstractmethod
def add_agent(self, agent_id: str, agent: Any) -> None:
"""Add an agent to the system."""
pass

@abstractmethod
def remove_agent(self, agent_id: str) -> None:
"""Remove an agent from the system."""
pass
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ def get_service(self, name: str) -> Optional[Dict[str, Any]]:
"""
pass

@abstractmethod
def get_services_by_roles(self, roles: List[str]) -> List[str]:
"""
Get services filtered by their roles.
"""
pass

@abstractmethod
def unregister_service(self, name: str) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ def process_tasks(self, task: Dict[str, Any]) -> None:
Abstract method to process a task.
"""
pass

@abstractmethod
def get_tasks(self) -> Dict[str, Any]:
"""
Abstract method to get tasks.
"""
pass
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

# List of agent factory names (file names without the ".py" extension) and corresponding class names
agent_factory_files = [
Expand All @@ -16,7 +16,7 @@

# Lazy loading of agent factories storing them in variables
for module_name, class_name in agent_factory_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

# Adding the lazy-loaded agent factories to __all__
__all__ = [class_name for _, class_name in agent_factory_files]
4 changes: 2 additions & 2 deletions pkgs/swarmauri/swarmauri/agents/concrete/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

# List of agent names (file names without the ".py" extension) and corresponding class names
agent_files = [
Expand All @@ -10,7 +10,7 @@

# Lazy loading of agent classes, storing them in variables
for module_name, class_name in agent_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

# Adding the lazy-loaded agent classes to __all__
__all__ = [class_name for _, class_name in agent_files]
4 changes: 2 additions & 2 deletions pkgs/swarmauri/swarmauri/chains/concrete/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

chains_files = [
("swarmauri.chains.concrete.CallableChain import", "CallableChain"),
Expand All @@ -9,7 +9,7 @@

# Lazy loading of chain classes, storing them in variables
for module_name, class_name in chains_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

# Adding the lazy-loaded chain classes to __all__
__all__ = [class_name for _, class_name in chains_files]
4 changes: 2 additions & 2 deletions pkgs/swarmauri/swarmauri/chunkers/concrete/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

# List of chunker names (file names without the ".py" extension) and corresponding class names
chunkers_files = [
Expand All @@ -11,7 +11,7 @@

# Lazy loading of chunker classes, storing them in variables
for module_name, class_name in chunkers_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

# Adding the lazy-loaded chunker classes to __all__
__all__ = [class_name for _, class_name in chunkers_files]
40 changes: 20 additions & 20 deletions pkgs/swarmauri/swarmauri/control_panels/base/ControlPanelBase.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
from swarmauri_core.control_panels.IControlPanel import IControlPlane
from typing import Any, List, Literal
from typing import Any, Callable, Dict, List, Literal
from pydantic import Field, ConfigDict
from swarmauri.service_registries.base.ServiceRegistryBase import ServiceRegistryBase
from swarmauri.factories.base.FactoryBase import FactoryBase
Expand All @@ -27,33 +27,33 @@ class ControlPanelBase(IControlPlane, ComponentBase):
transport: SubclassUnion[TransportBase]

# Agent management methods
def create_agent(self, name: str, role: str) -> Any:
def create_agent(self, name: str, role: str, **kwargs) -> Any:
"""
Create an agent with the given name and role, and register it in the service registry.
"""
agent = self.agent_factory.create_agent(name, role)
self.service_registry.register_service(name, {"role": role, "status": "active"})
agent = self.agent_factory.create(name, **kwargs)
self.service_registry.register_service(agent, name)
logging.info(f"Agent '{name}' with role '{role}' created and registered.")
return agent

def remove_agent(self, name: str) -> None:
"""
Remove the agent with the specified name and unregister it from the service registry.
"""
agent = self.agent_factory.get_agent_by_name(name)
if not agent:
raise ValueError(f"Agent '{name}' not found.")
self.agent_factory.unregister(name)
self.service_registry.unregister_service(name)
self.agent_factory.delete_agent(name)
logging.info(f"Agent '{name}' removed and unregistered.")

def list_active_agents(self) -> List[str]:
def list_active_agents(self) -> Dict[str, Callable]:
"""
List all active agent names.
"""
agents = self.agent_factory.get_agents()
active_agents = [agent.name for agent in agents if agent]
logging.info(f"Active agents listed: {active_agents}")
agents = self.agent_factory.get()
active_agents = {
agent: self.service_registry.get_service(agent)
for agent in agents
if agent and self.service_registry.get_service(agent)
}
return active_agents

# Task management methods
Expand All @@ -72,22 +72,23 @@ def process_tasks(self) -> None:
Process and assign tasks from the queue, then transport them to their assigned services.
"""
try:
self.task_mgt_strategy.process_tasks(
self.service_registry.get_services, self.transport
)
logging.info("Tasks processed and transported successfully.")
services = self.service_registry.get_services()

self.task_mgt_strategy.process_tasks(services, self.transport)
except Exception as e:
logging.error(f"Error while processing tasks: {e}")
raise ValueError(f"Error processing tasks: {e}")

def distribute_tasks(self, task: Any) -> None:
"""
Distribute tasks using the task strategy (manual or on-demand assignment).
"""
self.task_mgt_strategy.assign_task(task, self.service_registry.get_services)
service = self.task_mgt_strategy.assign_task(
task, self.service_registry.get_services()
)
logging.info(
f"Task '{task.get('task_id', 'unknown')}' distributed to a service."
f"Task '{task.get('task_id', 'unknown')}' distributed to a {service}."
)
return service

# Orchestration method
def orchestrate_agents(self, tasks: List[Any]) -> None:
Expand All @@ -96,4 +97,3 @@ def orchestrate_agents(self, tasks: List[Any]) -> None:
"""
self.submit_tasks(tasks) # Add task to the strategy
self.process_tasks() # Process and transport the task
logging.info("Agents orchestrated successfully.")
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from swarmauri.utils._lazy_import import _lazy_import
from swarmauri.utils.LazyLoader import LazyLoader

# List of control_panels names (file names without the ".py" extension) and corresponding class names
control_panels_files = [
Expand All @@ -7,7 +7,7 @@

# Lazy loading of task_mgt_strategies classes, storing them in variables
for module_name, class_name in control_panels_files:
globals()[class_name] = _lazy_import(module_name, class_name)
globals()[class_name] = LazyLoader(module_name, class_name)

# Adding the lazy-loaded state classes to __all__
__all__ = [class_name for _, class_name in control_panels_files]
Loading
Loading