You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/swarms/utils
Kye c90ba1c11e
[TOOL AGENT]
1 year ago
..
README.md [CLEANUP OPERATION] 1 year ago
__init__.py [CLEANUP] 1 year ago
apa.py Revert "[WIP] Get CI Passing V2" 1 year ago
check_function_result.py [CLEANUP OPERATION] 1 year ago
class_args_wrapper.py [FEAT][print_class_parameters] 1 year ago
code_interpreter.py [FEAT][Improved Logging] 1 year ago
concurrent_utils.py [FEATS][File processing] [hackathon for agents] 1 year ago
csv_and_pandas.py [FEATS][File processing] [hackathon for agents] 1 year ago
data_to_text.py [CLEANUP OPERATION] 1 year ago
decorators.py [CODE QUALITY] 1 year ago
device_checker_cuda.py [CLEANUP OPERATION] 1 year ago
disable_logging.py [FEATS][File processing] [hackathon for agents] 1 year ago
dist_utils.py [CLEANUP OPERATION] 1 year ago
download_img.py [CLEANUP OPERATION] 1 year ago
download_weights_from_url.py [FEAT][QwenVLMultiModal] 1 year ago
execute_futures.py [CLEANUP OPERATION] 1 year ago
execution_sandbox.py [CLEANUP] 1 year ago
exponential_backoff.py [CLEANUP OPERATION] 1 year ago
fetch_init_params.py [REFACTOR][SequentialWorkflow] [Agent] [FEATS][AsyncWorkflow] [BUFG][ConcurrentWorkflow] [MISC][DOCS] 1 year ago
file_extension_seach.py [REFACTOR][SequentialWorkflow] [Agent] [FEATS][AsyncWorkflow] [BUFG][ConcurrentWorkflow] [MISC][DOCS] 1 year ago
file_processing.py [CLEANUP][No rust] 1 year ago
find_img_path.py [FIXES++] [FEATS][find_image_path] [Simple Agent] [auto_update] [check_for_update] [system_info] 1 year ago
function_calling_utils.py [CLEANUP][No rust] 1 year ago
get_logger.py [FEATS][Tokenizers] [TimmModel] [Odin] [UltralyticsModel] 1 year ago
hash.py [CLEANUP OPERATION] 1 year ago
hash_utils.py [FEATS][swarms.tokenizers][swarms.artifacts][swarms.loaders][swarms.chunkers] 1 year ago
inference_convert_utils.py [CLEANUP] [old docs] [FEATS][SamplingParam] [Inference][utils] 1 year ago
json_output_parser.py [CLEANUP OPERATION] 1 year ago
json_utils.py [TOOL AGENT] 1 year ago
jsonl_utils.py [CLEANUP OPERATION] 1 year ago
llm_metrics_decorator.py [TESTS][CLEANUP] 1 year ago
load_model_torch.py Revert "[WIP] Get CI Passing V2" 1 year ago
logger.py [LOGGING][++Misc] 1 year ago
loggers.py [CLEANUP OPERATION] 1 year ago
loguru_logger.py [FEAT][SequentialWorkflow][Fix] 1 year ago
main.py [FEATS][MultiOnAgent] [BUGF][Agent early stopping logic] 1 year ago
markdown_message.py [FIXES++] [FEATS][find_image_path] [Simple Agent] [auto_update] [check_for_update] [system_info] 1 year ago
math_eval.py [math_eval] 1 year ago
pandas_to_str.py [FEATS][File processing] [hackathon for agents] 1 year ago
parse_code.py [swarms.utils][+++][DOCS] [TESTS] 1 year ago
pdf_to_text.py Update PDF library from PyPDF2 to pypdf 1 year ago
prep_torch_model_inference.py [CLEANUP OPERATION] 1 year ago
remove_json_whitespace.py [CLEANUP OPERATION] 1 year ago
save_logs.py [CLEANUP OPERATION] 1 year ago
serializable.py [PYDANTIC UPDATE] 1 year ago
supervision_masking.py [CLEANUP] 1 year ago
supervision_visualizer.py [CLEANUP] 1 year ago
token_count_tiktoken.py [FEAT][ChromaDB] [FEAT][tool_func_doc_scraper] [FEAT][BaseVectorStore] [FEAT][memory -> short_memory] [FEAT][memory: BaseVectorDB] 1 year ago
torch_utils.py [FIXES][Fuyu] 1 year ago
try_except_wrapper.py [FEAT][Logging][All swarms.structs modules] 1 year ago
video_to_frames.py [DOCS] 1 year ago
yaml_output_parser.py [CLEANUP OPERATION] 1 year ago

README.md

A high-level pseudocode for creating the classes and functions for your desired system:

  1. Swarms
    • The main class. It initializes the swarm with a specified number of worker nodes and sets up self-scaling if required.
    • Methods include add_worker, remove_worker, execute, and scale.
  2. WorkerNode
    • Class for each worker node in the swarm. It has a task_queue and a completed_tasks queue.
    • Methods include receive_task, complete_task, and communicate.
  3. HierarchicalSwarms
    • Inherits from Swarms and overrides the execute method to execute tasks in a hierarchical manner.
  4. CollaborativeSwarms
    • Inherits from Swarms and overrides the execute method to execute tasks in a collaborative manner.
  5. CompetitiveSwarms
    • Inherits from Swarms and overrides the execute method to execute tasks in a competitive manner.
  6. MultiAgentDebate
    • Inherits from Swarms and overrides the execute method to execute tasks in a debating manner.

To implement this in Python, you would start by setting up the base Swarm class and WorkerNode class. Here's a simplified Python example:

class WorkerNode:
    def __init__(self, llm: BaseLLM):
        self.llm = llm
        self.task_queue = deque()
        self.completed_tasks = deque()

    def receive_task(self, task):
        self.task_queue.append(task)

    def complete_task(self):
        task = self.task_queue.popleft()
        result = self.llm.execute(task)
        self.completed_tasks.append(result)
        return result

    def communicate(self, other_node):
        # Placeholder for communication method
        pass


class Swarms:
    def __init__(self, num_nodes: int, llm: BaseLLM, self_scaling: bool):
        self.nodes = [WorkerNode(llm) for _ in range(num_nodes)]
        self.self_scaling = self_scaling

    def add_worker(self, llm: BaseLLM):
        self.nodes.append(WorkerNode(llm))

    def remove_worker(self, index: int):
        self.nodes.pop(index)

    def execute(self, task):
        # Placeholder for main execution logic
        pass

    def scale(self):
        # Placeholder for self-scaling logic
        pass

Then, you would build out the specialized classes for each type of swarm:

class HierarchicalSwarms(Swarms):
    def execute(self, task):
        # Implement hierarchical task execution
        pass


class CollaborativeSwarms(Swarms):
    def execute(self, task):
        # Implement collaborative task execution
        pass


class CompetitiveSwarms(Swarms):
    def execute(self, task):
        # Implement competitive task execution
        pass


class MultiAgentDebate(Swarms):
    def execute(self, task):
        # Implement debate-style task execution
        pass

WorkerNode class

Here's the pseudocode algorithm for a WorkerNode class that includes a vector embedding database for communication:

  1. WorkerNode
    • Initialize a worker node with an LLM and a connection to the vector embedding database.
    • The worker node maintains a task_queue and completed_tasks queue. It also keeps track of the status of tasks (e.g., "pending", "completed").
    • The receive_task method accepts a task and adds it to the task_queue.
    • The complete_task method takes the oldest task from the task_queue, executes it, and then stores the result in the completed_tasks queue. It also updates the task status in the vector embedding database to "completed".
    • The communicate method uses the vector embedding database to share information with other nodes. It inserts the task result into the vector database and also queries for tasks marked as "completed".

In Python, this could look something like:

from collections import deque
from typing import Any, Dict

import faiss
from langchain.docstore import InMemoryDocstore
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import FAISS

from swarms.workers.auto_agent import AutoGPT


class WorkerNode:
    def __init__(self, llm: AutoGPT, vectorstore: FAISS):
        self.llm = llm
        self.vectorstore = vectorstore
        self.task_queue = deque()
        self.completed_tasks = deque()
        self.task_status: Dict[Any, str] = {}

    def receive_task(self, task):
        self.task_queue.append(task)
        self.task_status[task] = "pending"

    def complete_task(self):
        task = self.task_queue.popleft()
        result = self.llm.run(task)
        self.completed_tasks.append(result)
        self.task_status[task] = "completed"
        # Insert task result into the vectorstore
        self.vectorstore.insert(task, result)
        return result

    def communicate(self):
        # Share task results and status through vectorstore
        completed_tasks = [
            (task, self.task_status[task])
            for task in self.task_queue
            if self.task_status[task] == "completed"
        ]
        for task, status in completed_tasks:
            self.vectorstore.insert(task, status)

This example assumes that tasks are hashable and can be used as dictionary keys. The vectorstore.insert method is used to share task results and status with other nodes, and you can use methods like vectorstore.query or vectorstore.regex_search to retrieve this information. Please remember this is a simplified implementation and might need changes according to your exact requirements.