pull/296/head
elder-plinius 1 year ago
commit fd1a492420

37
.github/action.yml vendored

@ -0,0 +1,37 @@
name: "Init Environment"
description: "Initialize environment for tests"
runs:
using: "composite"
steps:
- name: Checkout actions
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --with test --with dev --all-extras
shell: bash
- name: Activate venv
run: |
source .venv/bin/activate
echo PATH=$PATH >> $GITHUB_ENV
shell: bash

@ -56,6 +56,6 @@ jobs:
# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif

@ -50,7 +50,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@ -64,7 +64,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3
# Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@ -77,6 +77,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"

@ -1,5 +1,3 @@
---
# This is a basic workflow to help you get started with Actions
name: Lint

@ -11,5 +11,5 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v4
- uses: actions/labeler@v5
if: ${{ github.event.pull_request.draft == false }}

@ -1,4 +1,3 @@
---
name: Pull Request Checks
on:
@ -22,6 +21,7 @@ jobs:
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install swarms
pip install pytest
- name: Run tests and checks

@ -26,7 +26,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install flake8 pytest swarms
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |

@ -28,7 +28,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade swarms
python -m pip install flake8 pytest
python -m pip install flake8 pytest swarms
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |

@ -1,4 +1,3 @@
---
name: Upload Python Package
on: # yamllint disable-line rule:truthy

@ -19,7 +19,7 @@ jobs:
pull-requests: write
steps:
- uses: actions/stale@v5
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-issue-stale: 14

@ -1,4 +1,3 @@
---
name: test
on:
@ -10,6 +9,7 @@ on:
env:
POETRY_VERSION: "1.4.2"
jobs:
test:
runs-on: ubuntu-latest
strategy:
@ -30,7 +30,7 @@ env:
python-version: ${{ matrix.python-version }}
poetry-version: "1.4.2"
cache-key: ${{ matrix.test_type }}
install-command: |
install-command:
if [ "${{ matrix.test_type }}" == "core" ]; then
echo "Running core tests, installing dependencies with poetry..."
poetry install

@ -16,8 +16,8 @@ jobs:
name: Test Py3.11
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Run tests
@ -29,8 +29,8 @@ jobs:
name: Test Py3.10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Run tests
@ -42,8 +42,8 @@ jobs:
name: Test Py3.9
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Run tests
@ -55,8 +55,8 @@ jobs:
name: pytype 3.10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Run pytype
@ -69,8 +69,8 @@ jobs:
name: Check format with black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Check format

@ -16,7 +16,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.x
python-version: "3.10"
- name: Install dependencies
run: |

@ -24,6 +24,7 @@ jobs:
run: |
pip install -r requirements.txt
pip install pytest
pip install swarms
- name: Run Python unit tests
run: pytest

3
.gitignore vendored

@ -10,6 +10,7 @@ dataframe/
static/generated
runs
chroma
swarms/__pycache__
venv
.DS_Store
@ -18,6 +19,7 @@ venv
swarms/agents/.DS_Store
_build
conversation.txt
stderr_log.txt
.vscode
@ -27,6 +29,7 @@ __pycache__/
*.py[cod]
*$py.class
.grit
swarm-worker-01_state.json
error.txt
# C extensions

File diff suppressed because it is too large Load Diff

@ -0,0 +1,49 @@
# Release Notes
## 3.7.5
2024-01-21
### Bug Fixes
Fix imports of Agent, SequentialWorkflow, ModelParallelizer, Task, OpenAIChat, Gemini, GPT4VisionAPI
### New Features
New model: Odin for Object Detection and tracking
New mode: Ultralytics Object recognition YOLO
New Tokenizers
Schema generator for prompts.
New prompt for worker agent.
New structure: plan, step
New tool: execute tool
New logger: get_logger
Example for worker_agent
## 3.6.8
2024-01-19
### Bug Fixes
Removed ModelScope
Removed CogAgent
### New Features
Added ultralytics vision models
Added TimmModel to wrap timm models
### Other
Loosened version of timm

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

@ -0,0 +1,95 @@
# Swarms Data Room
## Table of Contents
**Introduction**
- Overview of the Company
- Vision and Mission Statement
- Executive Summary
**Corporate Documents**
- Articles of Incorporation
- Bylaws
- Shareholder Agreements
- Board Meeting Minutes
- Company Structure and Org Chart
**Financial Information**
- Historical Financial Statements
- Income Statements
- Balance Sheets
- Cash Flow Statements
- Financial Projections and Forecasts
- Cap Table
- Funding History and Use of Funds
**Products and Services**
- Detailed Descriptions of Products/Services
- Product Development Roadmap
- User Manuals and Technical Specifications
- Case Studies and Use Cases
## **Introdution**
Swarms provides automation-as-a-service through swarms of autonomous agents that work together as a team. We enable our customers to build, deploy, and scale production-grade multi-agent applications to automate real-world tasks.
### **Vision**
Our vision for 2024 is to provide the most reliable infrastructure for deploying autonomous agents into the real world through the Swarm Cloud, our premier cloud platform for the scalable deployment of Multi-Modal Autonomous Agents. The platform focuses on delivering maximum value to users by only taking a small fee when utilizing the agents for the hosted compute power needed to host the agents.
### **Executive Summary**
The Swarm Corporation aims to enable AI models to automate complex workflows and operations, not just singular low-value tasks. We believe collaboration between multiple agents can overcome limitations of individual agents for reasoning, planning, etc. This will allow automation of processes in mission-critical industries like security, logistics, and manufacturing where AI adoption is currently low.
We provide an open source framework to deploy production-grade multi-modal agents in just a few lines of code. This builds our user base, recruits talent, gets customer feedback to improve products, gains awareness and trust.
Our business model focuses on customer satisfaction, openness, integration with other tools/platforms, and production-grade reliability.
Go-to-market strategy is to get the framework to product-market fit with over 50K weekly recurring users, then secure high-value contracts in target industries. Long-term monetization via microtransactions, usage-based pricing, subscriptions.
The team has thousands of hours building and optimizing autonomous agents. Leadership includes AI engineers, product experts, open source contributors and community builders.
Key milestones: get 80K framework users in January 2024, start contracts in target verticals, introduce commercial products in 2025 with various pricing models.
### **The Swarm Corporation Memo**
To learn more about our mission, vision, plans for GTM, and much more please refer to the [Swarm Memo here](https://docs.google.com/document/d/1hS_nv_lFjCqLfnJBoF6ULY9roTbSgSuCkvXvSUSc7Lo/edit?usp=sharing)
## **Product**
Swarms is an open source framework for developers in python to enable seamless, reliable, and scalable multi-agent orchestration through modularity, customization, and precision.
[Here is the official Swarms Github Page:](https://github.com/kyegomez/swarms)
### Product Growth Metrics
| Name | Description | Link |
|----------------------------------|---------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
| Total Downloads of all time | Total number of downloads for the product over its entire lifespan. | [![Downloads](https://static.pepy.tech/badge/swarms)](https://pepy.tech/project/swarms) |
| Downloads this month | Number of downloads for the product in the current month. | [![Downloads](https://static.pepy.tech/badge/swarms/month)](https://pepy.tech/project/swarms) |
| Total Downloads this week | Total number of downloads for the product in the current week. | [![Downloads](https://static.pepy.tech/badge/swarms/week)](https://pepy.tech/project/swarms) |
| Github Forks | Number of times the product's codebase has been copied for optimization, contribution, or usage. | [![GitHub forks](https://img.shields.io/github/forks/kyegomez/swarms)](https://github.com/kyegomez/swarms/network) |
| Github Stars | Number of users who have 'liked' the project. | [![GitHub stars](https://img.shields.io/github/stars/kyegomez/swarms)](https://github.com/kyegomez/swarms/stargazers) |
| Pip Module Metrics | Various project statistics such as watchers, number of contributors, date repository was created, and more. | [CLICK HERE](https://libraries.io/github/kyegomez/swarms) |
| Contribution Based Statistics | Statistics like number of contributors, lines of code changed, etc. | [HERE](https://github.com/kyegomez/swarms/graphs/contributors) |
| Github Community insights | Insights into the Github community around the product. | [Github Community insights](https://github.com/kyegomez/swarms/graphs/community) |
| Github Traffic Metrics | Metrics related to traffic, such as views and clones on Github. | [Github Traffic Metrics](https://github.com/kyegomez/swarms/graphs/traffic) |
| Issues with the framework | Current open issues for the product on Github. | [![GitHub issues](https://img.shields.io/github/issues/kyegomez/swarms)](https://github.com/kyegomez/swarms/issues) |

@ -0,0 +1,21 @@
# [Go To Market Strategy][GTM]
Our vision is to become the world leader in real-world production grade autonomous agent deployment through open-source product development, Deep Verticalization, and unmatched value delivery to the end user.
We will focus on first accelerating the open source framework to PMF where it will serve as the backend for upstream products and services such as the Swarm Cloud which will enable enterprises to deploy autonomous agents with long term memory and tools in the cloud and a no-code platform for users to build their own swarm by dragging and dropping blocks.
Our target user segment for the framework is AI engineers looking to deploy agents into high risk environments where reliability is crucial.
Once PMF has been achieved and the framework has been extensively benchmarked we aim to establish high value contracts with customers in Security, Logistics, Manufacturing, Health and various other untapped industries.
Our growth strategy for the OS framework can be summarized by:
- Educating developers on value of autonomous agent usage.
- Tutorial Walkthrough on various applications like deploying multi-modal agents through cameras or building custom swarms for a specific business operation.
- Demonstrate unmatched reliability by delighting users.
- Staying up to date with trends and integrating the latest models, frameworks, and methodologies.
- Building a loyal and devoted community for long term user retention. [Join here](https://codex.apac.ai)
As we continuously deliver value with the open framework we will strategically position ourselves to acquire leads for high value contracts by demonstrating the power, reliability, and performance of our framework openly.
Acquire Full Access to the memo here: [TSC Memo](https://docs.google.com/document/d/1hS_nv_lFjCqLfnJBoF6ULY9roTbSgSuCkvXvSUSc7Lo/edit?usp=sharing)

@ -1,19 +1,74 @@
# Swarms Docs
<div align="center">
<p>
<a align="center" href="" target="_blank">
<img
width="850"
src="https://github.com/kyegomez/swarms/raw/master/images/swarmslogobanner.png"
>
</a>
</p>
</div>
Welcome to Swarm's Documentation!
## 👋 Hello
Swarms is a modular framework that enables reliable and useful multi-agent collaboration at scale to automate real-world tasks.
Swarms provides you with all the building blocks you need to build reliable, production-grade, and scalable multi-agent apps!
Swarms is transforming the landscape of AI from siloed AI agents to a unified 'swarm' of intelligence. Through relentless iteration and the power of collective insight from our 1500+ Agora researchers, we're developing a groundbreaking framework for AI collaboration. Our mission is to catalyze a paradigm shift, advancing Humanity with the power of unified autonomous AI agent swarms.
## 💻 Install
You can install `swarms` with pip in a
[**Python>=3.8**](https://www.python.org/) environment.
This documentation covers the fundamentals of the **Swarms** framework and describes how to use **Swarms Tools**.
!!! example "pip install (recommended)"
## Swarms
=== "headless"
The headless installation of `swarms` is designed for environments where graphical user interfaces (GUI) are not needed, making it more lightweight and suitable for server-side applications.
The Swarms framework provides developers with the ability to create AI systems that operate across two dimensions: predictability and creativity. For predictability, Swarms enforces structures like sequential pipelines, DAG-based workflows, and long-term memory. To facilitate creativity, Swarms safely prompts LLMs with [tools](https://github.com/kyegomez/swarms-tools) and short-term memory connecting them to external APIs and data stores. The framework allows developers to transition between those two dimensions effortlessly based on their use case.
```bash
pip install swarms
```
Swarms not only helps developers harness the potential of LLMs but also enforces trust boundaries, schema validation, and tool activity-level permissions. By doing so, Swarms maximizes LLMs reasoning while adhering to strict policies regarding their capabilities.
!!! example "git clone (for development)"
=== "virtualenv"
```bash
# clone repository and navigate to root directory
git clone https://github.com/kyegomez/swarms.git
cd swarms
# setup python environment and activate it
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
# headless install
pip install -e "."
# desktop install
pip install -e ".[desktop]"
```
=== "poetry"
```bash
# clone repository and navigate to root directory
git clone https://github.com/kyegomez/swarms.git
cd swarms
# setup python environment and activate it
poetry env use python3.10
poetry shell
# headless install
poetry install
# desktop install
poetry install --extras "desktop"
```
## Documentation
[Learn more about swarms →](swarms/)

@ -1,83 +0,0 @@
# Contributing to Swarms
Thank you for your interest in contributing to Swarms! We welcome contributions from the community to help improve usability and readability. By contributing, you can be a part of creating a dynamic and interactive AI system.
To get started, please follow the guidelines below.
## Join the Swarms Community
Join the Swarms community on Discord to connect with other contributors, coordinate work, and receive support.
- [Join the Swarms Discord Server](https://discord.gg/qUtxnK2NMf)
## Taking on Tasks
We have a growing list of tasks and issues that you can contribute to. To get started, follow these steps:
1. Visit the [Swarms GitHub repository](https://github.com/kyegomez/swarms) and browse through the existing issues.
2. Find an issue that interests you and make a comment stating that you would like to work on it. Include a brief description of how you plan to solve the problem and any questions you may have.
3. Once a project coordinator assigns the issue to you, you can start working on it.
If you come across an issue that is unclear but still interests you, please post in the Discord server mentioned above. Someone from the community will be able to help clarify the issue in more detail.
We also welcome contributions to documentation, such as updating markdown files, adding docstrings, creating system architecture diagrams, and other related tasks.
## Submitting Your Work
To contribute your changes to Swarms, please follow these steps:
1. Fork the Swarms repository to your GitHub account. You can do this by clicking on the "Fork" button on the repository page.
2. Clone the forked repository to your local machine using the `git clone` command.
3. Before making any changes, make sure to sync your forked repository with the original repository to keep it up to date. You can do this by following the instructions [here](https://docs.github.com/en/github/collaborating-with-pull-requests/syncing-a-fork).
4. Create a new branch for your changes. This branch should have a descriptive name that reflects the task or issue you are working on.
5. Make your changes in the branch, focusing on a small, focused change that only affects a few files.
6. Run any necessary formatting or linting tools to ensure that your changes adhere to the project's coding standards.
7. Once your changes are ready, commit them to your branch with descriptive commit messages.
8. Push the branch to your forked repository.
9. Create a pull request (PR) from your branch to the main Swarms repository. Provide a clear and concise description of your changes in the PR.
10. Request a review from the project maintainers. They will review your changes, provide feedback, and suggest any necessary improvements.
11. Make any required updates or address any feedback provided during the review process.
12. Once your changes have been reviewed and approved, they will be merged into the main branch of the Swarms repository.
13. Congratulations! You have successfully contributed to Swarms.
Please note that during the review process, you may be asked to make changes or address certain issues. It is important to engage in open and constructive communication with the project maintainers to ensure the quality of your contributions.
## Developer Setup
If you are interested in setting up the Swarms development environment, please follow the instructions provided in the [developer setup guide](docs/developer-setup.md). This guide provides an overview of the different tools and technologies used in the project.
## Optimization Priorities
To continuously improve Swarms, we prioritize the following design objectives:
1. **Usability**: Increase the ease of use and user-friendliness of the swarm system to facilitate adoption and interaction with basic input.
2. **Reliability**: Improve the swarm's ability to obtain the desired output even with basic and un-detailed input.
3. **Speed**: Reduce the time it takes for the swarm to accomplish tasks by improving the communication layer, critiquing, and self-alignment with meta prompting.
4. **Scalability**: Ensure that the system is asynchronous, concurrent, and self-healing to support scalability.
Our goal is to continuously improve Swarms by following this roadmap while also being adaptable to new needs and opportunities as they arise.
## Join the Agora Community
Swarms is brought to you by Agora, the open-source AI research organization. Join the Agora community to connect with other researchers and developers working on AI projects.
- [Join the Agora Discord Server](https://discord.gg/qUtxnK2NMf)
Thank you for your contributions and for being a part of the Swarms and Agora community! Together, we can advance Humanity through the power of AI.

@ -1,368 +0,0 @@
# Swarms Documentation
## ClassName
Swarms
## Purpose
The Swarms module provides a powerful framework for creating and managing swarms of autonomous agents to accomplish complex tasks. It consists of the `WorkerNode` and `BossNode` classes, along with the `LLM` utility class, which allow you to easily set up and run a swarm of agents to tackle any objective. The module is highly configurable and extensible, providing flexibility to accommodate various use cases.
## Usage example
```python
from swarms import Swarms
api_key = "your_openai_api_key"
# Initialize Swarms with your API key
swarm = Swarms(api_key=api_key)
# Define an objective
objective = "Please make a web GUI for using HTTP API server..."
# Run Swarms
result = swarm.run(objective)
print(result)
```
## Constructor
```python
def __init__(self, openai_api_key)
```
- `openai_api_key` (required): The API key for OpenAI's models.
## Methods
### run(objective)
Runs the swarm with the given objective by initializing the worker and boss nodes.
- `objective` (required): The objective or task to be accomplished by the swarm.
Returns the result of the swarm execution.
## Example Usage
```python
from swarms import Swarms
api_key = "your_openai_api_key"
# Initialize Swarms with your API key
swarm = Swarms(api_key=api_key)
# Define an objective
objective = "Please make a web GUI for using HTTP API server..."
# Run Swarms
result = swarm.run(objective)
print(result)
```
## WorkerNode
The `WorkerNode` class represents an autonomous agent instance that functions as a worker to accomplish complex tasks. It has the ability to search the internet, process and generate images, text, audio, and more.
### Constructor
```python
def __init__(self, llm, tools, vectorstore)
```
- `llm` (required): The language model used by the worker node.
- `tools` (required): A list of tools available to the worker node.
- `vectorstore` (required): The vector store used by the worker node.
### Methods
- `create_agent(ai_name, ai_role, human_in_the_loop, search_kwargs)`: Creates an agent within the worker node.
- `add_tool(tool)`: Adds a tool to the worker node.
- `run(prompt)`: Runs the worker node to complete a task specified by the prompt.
### Example Usage
```python
from swarms import worker_node
# Your OpenAI API key
api_key = "your_openai_api_key"
# Initialize a WorkerNode with your API key
node = worker_node(api_key)
# Define an objective
objective = "Please make a web GUI for using HTTP API server..."
# Run the task
task = node.run(objective)
print(task)
```
## BossNode
The `BossNode` class represents an agent responsible for creating and managing tasks for the worker agent(s). It interacts with the worker node(s) to delegate tasks and monitor their progress.
### Constructor
```python
def __init__(self, llm, vectorstore, agent_executor, max_iterations)
```
- `llm` (required): The language model used by the boss node.
- `vectorstore` (required): The vector store used by the boss node.
- `agent_executor` (required): The agent executor used to execute tasks.
- `max_iterations` (required): The maximum number of iterations for task execution.
### Methods
- `create_task(objective)`: Creates a task with the given objective.
- `execute_task(task)`: Executes the given task by interacting with the worker agent(s).
## LLM
The `LLM` class is a utility class that provides an interface to different language models (LLMs) such as OpenAI's ChatGPT and Hugging Face models. It is used to initialize the language model for the worker and boss nodes.
### Constructor
```python
def __init__(self, openai_api_key=None, hf_repo_id=None, hf_api_token=None, model_kwargs=None)
```
- `openai_api_key` (optional): The API key for OpenAI's models.
- `hf_repo_id` (optional): The repository ID for the Hugging Face model.
- `hf_api_token` (optional): The API token for the Hugging Face model.
- `model_kwargs` (optional): Additional keyword arguments to pass to the language model.
### Methods
- `run(prompt)`: Runs the language model with the given prompt and returns the generated response.
## Configuration
The Swarms module can be configured by modifying the following parameters:
### WorkerNode
- `llm_class`: The language model class to use for the worker node (default: `ChatOpenAI`).
- `temperature`: The temperature parameter for the language model (default: `0.5`).
### BossNode
- `llm_class`: The language model class to use for the boss node (default: `OpenAI`).
- `max_iterations`: The maximum number of iterations for task execution (default: `5`).
### LLM
- `openai_api_key`: The API key for OpenAI's models.
- `hf_repo_id`: The repository ID for the Hugging Face model.
- `hf_api_token`: The API token for the Hugging Face model.
- `model_kwargs`: Additional keyword arguments to pass to the language model.
## Tool Configuration
The Swarms module supports various tools that can be added to the worker node for performing specific tasks. The following tools are available:
- `DuckDuckGoSearchRun`: A tool for performing web searches.
- `WriteFileTool`: A tool for writing files.
- `ReadFileTool`: A tool for reading files.
- `process_csv`: A tool for processing CSV files.
- `WebpageQATool`: A tool for performing question answering using web pages.
Additional tools can be added by extending the functionality of the `Tool` class.
## Advanced Usage
For more advanced usage, you can customize the tools and parameters according to your specific requirements. The Swarms module provides flexibility and extensibility to accommodate various use cases.
For example, you can add your own custom tools by extending the `Tool` class and adding them to the worker node. You can also modify the prompt templates used by the boss node to customize the interaction between the boss and worker agents.
Please refer to the source code and documentation of the Swarms module for more details and examples.
## Conclusion
The Swarms module provides a powerful framework for creating and managing swarms of autonomous agents to accomplish complex tasks. With the `WorkerNode` and `BossNode` classes, along with the `LLM` utility class, you can easily set up and run a swarm of agents to tackle any objective. The module is highly configurable and extensible, allowing you to tailor it to your specific needs.
## LLM
### Purpose
The `LLM` class provides an interface to different language models (LLMs) such as OpenAI's ChatGPT and Hugging Face models. It allows you to initialize and run a language model with a given prompt and obtain the generated response.
### Systems Understanding
The `LLM` class takes an OpenAI API key or Hugging Face repository ID and API token as input. It uses these credentials to initialize the language model, either from OpenAI's models or from a specific Hugging Face repository. The language model can then be run with a prompt, and the generated response is returned.
### Usage Example
```python
from swarms import LLM
# Create an instance of LLM with OpenAI API key
llm_instance = LLM(openai_api_key="your_openai_key")
# Run the language model with a prompt
result = llm_instance.run("Who won the FIFA World Cup in 1998?")
print(result)
# Create an instance of LLM with Hugging Face repository ID and API token
llm_instance = LLM(hf_repo_id="google/flan-t5-xl", hf_api_token="your_hf_api_token")
# Run the language model with a prompt
result = llm_instance.run("Who won the FIFA World Cup in 1998?")
print(result)
```
### Constructor
```python
def __init__(self, openai_api_key: Optional[str] = None,
hf_repo_id: Optional[str] = None,
hf_api_token: Optional[str] = None,
model_kwargs: Optional[dict] = None)
```
- `openai_api_key` (optional): The API key for OpenAI's models.
- `hf_repo_id` (optional): The repository ID for the Hugging Face model.
- `hf_api_token` (optional): The API token for the Hugging Face model.
- `model_kwargs` (optional): Additional keyword arguments to pass to the language model.
### Methods
- `run(prompt: str) -> str`: Runs the language model with the given prompt and returns the generated response.
### Args
- `prompt` (str): The prompt to be passed to the language model.
### Returns
- `result` (str): The generated response from the language model.
## Conclusion
The `LLM` class provides a convenient way to initialize and run different language models using either OpenAI's API or Hugging Face models. By providing the necessary credentials and a prompt, you can obtain the generated response from the language model.
# `GooglePalm` class:
### Example 1: Using Dictionaries as Messages
```python
from google_palm import GooglePalm
# Initialize the GooglePalm instance
gp = GooglePalm(
client=your_client,
model_name="models/chat-bison-001",
temperature=0.7,
top_p=0.9,
top_k=10,
n=5
)
# Create some messages
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
]
# Generate a response
response = gp.generate(messages)
# Print the generated response
print(response)
```
### Example 2: Using BaseMessage and Its Subclasses as Messages
```python
from google_palm import GooglePalm
from langchain.schema.messages import SystemMessage, HumanMessage
# Initialize the GooglePalm instance
gp = GooglePalm(
client=your_client,
model_name="models/chat-bison-001",
temperature=0.7,
top_p=0.9,
top_k=10,
n=5
)
# Create some messages
messages = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="Who won the world series in 2020?"),
]
# Generate a response
response = gp.generate(messages)
# Print the generated response
print(response)
```
### Example 3: Using GooglePalm with Asynchronous Function
```python
import asyncio
from google_palm import GooglePalm
from langchain.schema.messages import SystemMessage, HumanMessage
# Initialize the GooglePalm instance
gp = GooglePalm(
client=your_client,
model_name="models/chat-bison-001",
temperature=0.7,
top_p=0.9,
top_k=10,
n=5
)
# Create some messages
messages = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="Who won the world series in 2020?"),
]
# Define an asynchronous function
async def generate_response():
response = await gp._agenerate(messages)
print(response)
# Run the asynchronous function
asyncio.run(generate_response())
```
Remember to replace `your_client` with an actual instance of your client. Also, ensure the `model_name` is the correct name of the model that you want to use.
The `temperature`, `top_p`, `top_k`, and `n` parameters control the randomness and diversity of the generated responses. You can adjust these parameters based on your application's requirements.
## `CodeInterpreter`:
```python
tool = CodeInterpreter("Code Interpreter", "A tool to interpret code and generate useful outputs.")
tool.run("Plot the bitcoin chart of 2023 YTD")
# Or with file inputs
tool.run("Analyze this dataset and plot something interesting about it.", ["examples/assets/iris.csv"])
```
To use the asynchronous version, simply replace `run` with `arun` and ensure your calling code is in an async context:
```python
import asyncio
tool = CodeInterpreter("Code Interpreter", "A tool to interpret code and generate useful outputs.")
asyncio.run(tool.arun("Plot the bitcoin chart of 2023 YTD"))
# Or with file inputs
asyncio.run(tool.arun("Analyze this dataset and plot something interesting about it.", ["examples/assets/iris.csv"]))
```
The `CodeInterpreter` class is a flexible tool that uses the `CodeInterpreterSession` from the `codeinterpreterapi` package to run the code interpretation and return the result. It provides both synchronous and asynchronous methods for convenience, and ensures that exceptions are handled gracefully.

@ -1,225 +0,0 @@
# Getting Started with Swarms: A Simple Introduction to State-of-the-Art Language Models
======================================================================================
Welcome to the universe of Swarms! 🚀
Today, you're embarking on a thrilling journey through the ever-evolving realm of state-of-the-art language models.
As you might know, we're in the early days of this adventure, and every step we take is building from the ground up.
Our foundation is set on five levels of abstraction.
Each level adds complexity and capability, but worry not!
We'll walk you through each step, making sure you have fun and learn along the way.
So, ready to swarm?
Let's dive right in!
Installation 😊
===============
To get started with Swarms, run the following command:
pip install swarms
1\. OpenAI
==========
Ah, OpenAI, where the magic of GPT series lives.
With Swarms, you can tap into this magic in a straightforward way.
Think of it as having a chat with one of the smartest beings ever created by humankind!
Features ✨
----------
- Direct Interface: Seamless interaction with OpenAI's GPT models.
- Synchronous & Asynchronous Interaction: Flexibility to interact in real-time or in the background.
- Multi-query Support: Enables querying multiple IDs simultaneously.
- Streaming Capability: Stream multiple responses for dynamic conversations.
- Console Logging: Gives users visibility and traceability of their interactions.
How It Works:
=============
1. Initiate: Set up your agent using your OpenAI API key and other customizable parameters.
2. Converse: Use methods like `generate` to converse with the model. Got a list of queries? No worries, methods like `ask_multiple` got you covered.
3. Marvel: Witness the intelligence in the responses and interact in real-time!
Quick Start:
============
Imagine a scenario where you want to know how multiple IDs (say products, books, or places) are perceived. It's just two lines of code away!
from swarms import OpenAI()\
chat = OpenAI()\
response = chat.generate("Hello World")\
print(response)
2\. HuggingFace
===============
HuggingFace is a name that's changed the game in the NLP world. And with Swarms, you can easily harness the power of their vast model repository.
Features ✨
----------
- Access to a Vast Model Repository: Directly tap into HuggingFace's expansive model hub.
- Intuitive Text Generation: Prompt-based text generation that's straightforward.
- High Customizability: Users can set device preferences, maximum length of generated text, and more.
- Speed Boost: Our implementation offers up to a 9x speed increase by leveraging model quantization.
- Less Memory Consumption: Quantization reduces the model size significantly.
- Maintained Accuracy: Despite the reduction in model size and increased speed, the quality of the output remains top-tier.
- Superior to Other Packages: Unlike many other packages that simply wrap around the HuggingFace API, Swarms has built-in support for advanced features like quantization, making it both faster and more efficient.
How It Works:
=============
1. Pick Your Model: From BERT to GPT-2, choose from a myriad of options.
2. Chat Away: Generate thought-provoking text based on your prompts.
Quick Start:
============
Ready to create a story?
from swarms import HuggingFaceLLM
hugging_face_model = HuggingFaceLLM(model_id="amazon/FalconLite")\
generated_text = hugging_face_model.generate("In a world where AI rules,"
3\. Google PaLM
===============
Google's venture into conversational AI, the PaLM Chat API, can now be effortlessly integrated into your projects with Swarms.
Features ✨
----------
- Easy Integration: Quickly set up interactions with Google's PaLM Chat API.
- Dynamic Conversations: Engage in back-and-forth chat-like conversations with the model.
- Customizable Sampling Techniques: Set temperature, top-p, and top-k values for diverse and controlled outputs.
How It Works:
=============
1. Set Up: Initialize with your preferred model and Google API key.
2. Engage: Engage in back-and-forth conversations with the model.
Quick Start:
============
Looking for a quick joke? Google's got you:
from swarms import GooglePalm
google_palm = GooglePalm()\
messages = [{"role": "system", "content": "You are a funny assistant"}, {"role": "user", "content": "Crack me a joke"}]\
response = google_palm.generate(messages)
4\. Anthropic (swarms.models.Anthropic)
==============================================
Anthropic's models, with their mysterious allure, are now at your fingertips.
Features ✨
----------
- Simplified Access: Straightforward interaction with Anthropic's large language models.
- Dynamic Text Generation: Generate intriguing content based on user prompts.
- Streaming Mode: Enable real-time streaming of responses for dynamic use-cases.
How It Works:
=============
1. Initialize: Get started with your preferred Anthropic model.
2. Generate: Whether you're crafting a story or looking for answers, you're in for a treat.
Quick Start:
============
Dive into a fairy tale:
from swarms import Anthropic
anthropic = Anthropic()\
generated_text = anthropic.generate("In a kingdom far away,")
Building with the Five Levels of Abstraction
============================================
From the individual model, right up to the hivemind, we've crafted a layered approach that scales and diversifies your interactions:
1. Model: Start with a base model like OpenAI.
2. Agent Level: Integrate the model with vector stores and tools.
3. Worker Infrastructure: Assign tasks to worker nodes with specific tools.
4. Swarm Level: Coordinate multiple worker nodes for a symphony of intelligence.
5. Hivemind: The pinnacle! Integrate multiple swarms for unparalleled capability.
And, our master plan is...
The Master Plan
===============
Phase 1: Building the Foundation
--------------------------------
In the first phase, our focus is on building the basic infrastructure of Swarms.
This includes developing key components like the Swarms class, integrating essential tools, and establishing task completion and evaluation logic.
We'll also start developing our testing and evaluation framework during this phase.
If you're interested in foundational work and have a knack for building robust, scalable systems, this phase is for you.
Phase 2: Optimizing the System
------------------------------
In the second phase, we'll focus on optimizing Swarms by integrating more advanced features, improving the system's efficiency, and refining our testing and evaluation framework.
This phase involves more complex tasks, so if you enjoy tackling challenging problems and contributing to the development of innovative features, this is the phase for you.
Phase 3: Towards Super-Intelligence
-----------------------------------
The third phase of our bounty program is the most exciting --- this is where we aim to achieve super-intelligence.
In this phase, we'll be working on improving the swarm's capabilities, expanding its skills, and fine-tuning the system based on real-world testing and feedback.
If you're excited about the future of AI and want to contribute to a project that could potentially transform the digital world, this is the phase for you.
Remember, our roadmap is a guide, and we encourage you to bring your own ideas and creativity to the table.
We believe that every contribution, no matter how small, can make a difference.
So join us on this exciting journey and help us create the future of Swarms.
Hiring:
=======
We're hiring: Engineers, Researchers, Interns And, salesprofessionals to work on democratizing swarms, email me at with your story at `kye@apac.ai`
In Conclusion: A World of Possibilities
=======================================
There you have it!
A whirlwind tour through some of the most cutting-edge language models available today.
Remember, Swarms is like a treasure chest, and we're continually adding more jewels to it.
As Sir Jonathan Ive would say, "True simplicity is derived from so much more than just the absence of clutter and ornamentation, it's about bringing order to complexity."
Now, with the foundation of Swarms beneath your feet, you're well-equipped to soar to new heights.
So go on, experiment, explore, and have a blast!
The future of AI awaits you! 🌌🐝🎉
*Disclaimer: Remember, we're at the early stages, but every idea, every line of code, every interaction you have, is helping shape the future of Swarms. So, thank you for being a part of this exciting journey!*
Happy Swarming!

@ -1,143 +0,0 @@
## LLMs in Swarms Documentation
Welcome to the documentation for the llm section of the swarms package, designed to facilitate seamless integration with various AI language models and APIs. This package empowers developers, end-users, and system administrators to interact with AI models from different providers, such as OpenAI, Hugging Face, Google PaLM, and Anthropic.
### Table of Contents
1. [OpenAI](#openai)
2. [HuggingFace](#huggingface)
3. [Google PaLM](#google-palm)
4. [Anthropic](#anthropic)
### 1. OpenAI (swarms.models.OpenAI)
The OpenAI class provides an interface to interact with OpenAI's language models. It allows both synchronous and asynchronous interactions.
**Constructor:**
```python
OpenAI(api_key: str, system: str = None, console: bool = True, model: str = None, params: dict = None, save_messages: bool = True)
```
**Attributes:**
- `api_key` (str): Your OpenAI API key.
- `system` (str, optional): A system message to be used in conversations.
- `console` (bool, default=True): Display console logs.
- `model` (str, optional): Name of the language model to use.
- `params` (dict, optional): Additional parameters for model interactions.
- `save_messages` (bool, default=True): Save conversation messages.
**Methods:**
- `generate(message: str, **kwargs) -> str`: Generate a response using the OpenAI model.
- `generate_async(message: str, **kwargs) -> str`: Generate a response asynchronously.
- `ask_multiple(ids: List[str], question_template: str) -> List[str]`: Query multiple IDs simultaneously.
- `stream_multiple(ids: List[str], question_template: str) -> List[str]`: Stream multiple responses.
**Usage Example:**
```python
from swarms import OpenAI
import asyncio
chat = OpenAI(api_key="YOUR_OPENAI_API_KEY")
response = chat.generate("Hello, how can I assist you?")
print(response)
ids = ["id1", "id2", "id3"]
async_responses = asyncio.run(chat.ask_multiple(ids, "How is {id}?"))
print(async_responses)
```
### 2. HuggingFace (swarms.models.HuggingFaceLLM)
The HuggingFaceLLM class allows interaction with language models from Hugging Face.
**Constructor:**
```python
HuggingFaceLLM(model_id: str, device: str = None, max_length: int = 20, quantize: bool = False, quantization_config: dict = None)
```
**Attributes:**
- `model_id` (str): ID or name of the Hugging Face model.
- `device` (str, optional): Device to run the model on (e.g., 'cuda', 'cpu').
- `max_length` (int, default=20): Maximum length of generated text.
- `quantize` (bool, default=False): Apply model quantization.
- `quantization_config` (dict, optional): Configuration for quantization.
**Methods:**
- `generate(prompt_text: str, max_length: int = None) -> str`: Generate text based on a prompt.
**Usage Example:**
```python
from swarms import HuggingFaceLLM
model_id = "gpt2"
hugging_face_model = HuggingFaceLLM(model_id=model_id)
prompt = "Once upon a time"
generated_text = hugging_face_model.generate(prompt)
print(generated_text)
```
### 3. Google PaLM (swarms.models.GooglePalm)
The GooglePalm class provides an interface for Google's PaLM Chat API.
**Constructor:**
```python
GooglePalm(model_name: str = "models/chat-bison-001", google_api_key: str = None, temperature: float = None, top_p: float = None, top_k: int = None, n: int = 1)
```
**Attributes:**
- `model_name` (str): Name of the Google PaLM model.
- `google_api_key` (str, optional): Google API key.
- `temperature` (float, optional): Temperature for text generation.
- `top_p` (float, optional): Top-p sampling value.
- `top_k` (int, optional): Top-k sampling value.
- `n` (int, default=1): Number of candidate completions.
**Methods:**
- `generate(messages: List[Dict[str, Any]], stop: List[str] = None, **kwargs) -> Dict[str, Any]`: Generate text based on a list of messages.
- `__call__(messages: List[Dict[str, Any]], stop: List[str] = None, **kwargs) -> Dict[str, Any]`: Generate text using the call syntax.
**Usage Example:**
```python
from swarms import GooglePalm
google_palm = GooglePalm()
messages = [{"role": "system", "content": "You are a helpful assistant"}, {"role": "user", "content": "Tell me a joke"}]
response = google_palm.generate(messages)
print(response["choices"][0]["text"])
```
### 4. Anthropic (swarms.models.Anthropic)
The Anthropic class enables interaction with Anthropic's large language models.
**Constructor:**
```python
Anthropic(model: str = "claude-2", max_tokens_to_sample: int = 256, temperature: float = None, top_k: int = None, top_p: float = None, streaming: bool = False, default_request_timeout: int = None)
```
**Attributes:**
- `model` (str): Name of the Anthropic model.
- `max_tokens_to_sample` (int, default=256): Maximum tokens to sample.
- `temperature` (float, optional): Temperature for text generation.
- `top_k` (int, optional): Top-k sampling value.
- `top_p` (float, optional): Top-p sampling value.
- `streaming` (bool, default=False): Enable streaming mode.
- `default_request_timeout` (int, optional): Default request timeout.
**Methods:**
- `generate(prompt: str, stop: List[str] = None) -> str`: Generate text based on a prompt.
**Usage Example:**
```python
from swarms import Anthropic
anthropic = Anthropic()
prompt = "Once upon a time"
generated_text = anthropic.generate(prompt)
print(generated_text)
```
This concludes the documentation for the "swarms" package, providing you with tools to seamlessly integrate with various language models and APIs. Happy coding!

@ -1,75 +0,0 @@
Introduction to Agents in Swarms
================================
Welcome to the revolutionary world of Agents in Swarms. I'm a big believer in simplicity, modularity, and the power of open collaboration. The same principles apply here.
Agents are the individual building blocks in a swarm. They are the worker bees, each with a specific task, but all working together towards a common goal. In our case, an agent is a combination of a Language Model (LLM), Long Term Memory, and Tools.
In other words, an agent is:
`LLM => Long Term Memory => Tools`
That's it. That's as simple as it can get.
Why does this work? Because each component has a specific, well-defined role. The Language Model is the driving force, generating text based on a given prompt. The Long Term Memory stores information that the agent can draw upon to make its output more coherent and contextually relevant. The Tools provide additional capabilities, such as the ability to parse text, search the web, or interact with APIs.
But the real beauty of this system is not just in the individual components, but in how they work together. The output of one becomes the input of another, creating a feedback loop of continuous learning and improvement.
And the best part? Our Agent classes are designed to be as simple as humanely possible. They are plug-and-play with any of our language model classes, vector stores, and tools. This means you can easily swap out one component for another, allowing for endless customization and flexibility.
The file structure is equally straightforward:
```
* memory
* models
* tools
* utils
```
Each directory contains different components of the swarm. The `models` directory contains the language models, the `memory` directory contains the long-term memory, the `tools` directory contains the tools, the `utils` directory contains various utility functions.
Let's see how simple it is to use these components with some examples:
```python
# Import the necessary classes
from swarms.agents import Anthropic, HuggingFaceLLM
# Create an instance of the Anthropic class
anthropic = Anthropic(model="claude-2", max_tokens_to_sample=100, temperature=0.8)
# Use the Anthropic instance to generate text
prompt = "Once upon a time"
stop = ["The end"]
print("Anthropic output:")
print(anthropic.generate(prompt, stop))
# Create an instance of the HuggingFaceLLM class
huggingface = HuggingFaceLLM(model_id="gpt2", device="cpu", max_length=50)
# Use the HuggingFaceLLM instance to generate text
prompt = "Once upon a time"
print("\nHuggingFaceLLM output:")
print(huggingface.generate(prompt))
```
And to build an agent:
```python
from swarms.agents import vectorstore, tool, Agent
# Create an instance of the Agent class
agent = Agent(
llm=huggingface,
memory=vectorstore,
tools=tool,
)
agent.run("Make me an instagram clone")
```
In conclusion, the Agents in Swarms represent a new way of thinking about AI. They are simple, modular, and highly customizable, allowing you to create powerful AI systems that are more than the sum of their parts. And as always, we're just getting started. There's always room for improvement, for simplification, for making things even better. That's the spirit of open collaboration. That's the spirit of Swarms.
Thanks for becoming an alpha build user, email kye@apac.ai with all complaints.

@ -1,114 +0,0 @@
Maximize Value Using Value Equation
1. Maximize Dream Outcome: Solve Problems Worth $1 Billion
Swarms empowers you to solve problems worth $1 billion, maximizing your dream outcome and the potential impact of your work.
2. Maximize Perceived Likelihood of Success: 99% Success Rate
With a 99% success rate backed by testimonials and proven case studies, Swarms maximizes your confidence in achieving your desired outcomes.
3. Minimize Time to Success: Achieve Results 10x Faster
Swarms minimizes the time it takes to achieve success by enabling you to accomplish tasks and goals 10 times faster than traditional methods.
4. Minimize Effort & Sacrifice: Save 100 Hours per Week
By automating tasks and streamlining processes, Swarms saves you 100 hours per week, minimizing effort and sacrifice required to achieve your goals.
5. Maximize Efficiency: Increase Productivity by 300%
Swarms optimizes your workflow, increasing productivity by 300% through intelligent automation and task optimization.
6. Minimize Errors: Ensure 99.9% Accuracy
With Swarms' autonomous AI agents, you can achieve 99.9% accuracy, minimizing errors and ensuring the highest level of quality in your work.
7. Maximize Scalability: Handle 1 Million Transactions per Second
Swarms scales with your growing needs, allowing you to handle up to 1 million transactions per second, ensuring seamless operations as your business expands.
8. Minimize Costs: Save $1 Million Annually
By optimizing resource allocation and reducing manual labor, Swarms helps you save $1 million annually, minimizing costs and maximizing your bottom line.
9. Maximize Flexibility: Adapt to Changing Requirements in Minutes
Swarms offers maximum flexibility, allowing you to adapt to changing requirements in minutes, ensuring you stay agile and responsive in a dynamic business environment.
10. Minimize Complexity: Simplify Complex Tasks by 90%
Swarms simplifies complex tasks by 90%, breaking them down into manageable steps, minimizing complexity and enabling you to tackle even the most challenging projects.
11. Maximize Collaboration: Increase Team Efficiency by 200%
With Swarms' coordination capabilities, you can increase team efficiency by 200%, fostering collaboration and driving innovation within your organization.
12. Minimize Downtime: Ensure 99.99% Uptime
Swarms ensures 99.99% uptime, minimizing downtime and ensuring continuous operations, preventing costly disruptions to your business.
13. Maximize Security: Protect Your Data with Military-Grade Encryption
Swarms prioritizes data security, providing military-grade encryption to protect your sensitive information, maximizing the security and confidentiality of your data.
14. Minimize Learning Curve: Get Up and Running in 1 Hour
Swarms minimizes the learning curve, allowing you to get up and running in just 1 hour, maximizing your time and productivity.
15. Maximize Innovation: Stay Ahead with AI-Driven Insights
Swarms leverages AI and autonomous agents to provide cutting-edge insights, enabling you to stay ahead of the competition and drive innovation in your industry.
16. Minimize Maintenance: Reduce Maintenance Costs by 80%
Swarms reduces maintenance costs by 80%, minimizing the time and resources required for upkeep, allowing you to focus on your core business activities.
17. Maximize Adaptability: Customize to Your Needs with 100+ Configurable Options
Swarms offers over 100 configurable options, maximizing adaptability and allowing you to customize the platform to suit your specific requirements.
1. Maximize Dream Outcome: Solve Problems Worth $1 Billion
Swarms empowers you to solve problems worth $1 billion, maximizing your dream outcome and the potential impact of your work.
2. Maximize Perceived Likelihood of Success: 99% Success Rate
With a 99% success rate backed by testimonials and proven case studies, Swarms maximizes your confidence in achieving your desired outcomes.
3. Minimize Time to Success: Achieve Results 10x Faster
Swarms minimizes the time it takes to achieve success by enabling you to accomplish tasks and goals 10 times faster than traditional methods.
4. Minimize Effort & Sacrifice: Save 100 Hours per Week
By automating tasks and streamlining processes, Swarms saves you 100 hours per week, minimizing effort and sacrifice required to achieve your goals.
5. Maximize Efficiency: Increase Productivity by 300%
Swarms optimizes your workflow, increasing productivity by 300% through intelligent automation and task optimization.
6. Minimize Errors: Ensure 99.9% Accuracy
With Swarms' autonomous AI agents, you can achieve 99.9% accuracy, minimizing errors and ensuring the highest level of quality in your work.
7. Maximize Scalability: Handle 1 Million Transactions per Second
Swarms scales with your growing needs, allowing you to handle up to 1 million transactions per second, ensuring seamless operations as your business expands.
8. Minimize Costs: Save $1 Million Annually
By optimizing resource allocation and reducing manual labor, Swarms helps you save $1 million annually, minimizing costs and maximizing your bottom line.
9. Maximize Flexibility: Adapt to Changing Requirements in Minutes
Swarms offers maximum flexibility, allowing you to adapt to changing requirements in minutes, ensuring you stay agile and responsive in a dynamic business environment.
10. Minimize Complexity: Simplify Complex Tasks by 90%
Swarms simplifies complex tasks by 90%, breaking them down into manageable steps, minimizing complexity and enabling you to tackle even the most challenging projects.
11. Maximize Collaboration: Increase Team Efficiency by 200%
With Swarms' coordination capabilities, you can increase team efficiency by 200%, fostering collaboration and driving innovation within your organization.
12. Minimize Downtime: Ensure 99.99% Uptime
Swarms ensures 99.99% uptime, minimizing downtime and ensuring continuous operations, preventing costly disruptions to your business.
13. Maximize Security: Protect Your Data with Military-Grade Encryption
Swarms prioritizes data security, providing military-grade encryption to protect your sensitive information, maximizing the security and confidentiality of your data.
14. Minimize Learning Curve: Get Up and Running in 1 Hour
Swarms minimizes the learning curve, allowing you to get up and running in just 1 hour, maximizing your time and productivity.
15. Maximize Innovation: Stay Ahead with AI-Driven Insights
Swarms leverages AI and autonomous agents to provide cutting-edge insights, enabling you to stay ahead of the competition and drive innovation in your industry.
16. Minimize Maintenance: Reduce Maintenance Costs by 80%
Swarms reduces maintenance costs by 80%, minimizing the time and resources required for upkeep, allowing you to focus on your core business activities.
17. Maximize Adaptability: Customize to Your Needs with 100+ Configurable Options
Swarms offers over 100 configurable options, maximizing adaptability and allowing you to customize the platform to suit your specific requirements.
18. Minimize Risk: Mitigate Potential Losses by 95%
Swarms helps you minimize risk by mitigating potential losses by 95%, providing a secure and reliable platform for your critical operations.
19. Maximize ROI: Achieve 500% Return on Investment
With Swarms' efficiency and cost-saving capabilities, you can achieve a 500% return on investment, maximizing the value you get from your resources.
20. Minimize Waste: Reduce Resource Consumption by 70%
Swarms minimizes waste by reducing resource consumption by 70%, optimizing resource allocation and promoting sustainability in your operations.

@ -1,7 +0,0 @@
# Demo Ideas
* We could also try to create an AI influencer run by a swarm, let it create a whole identity and generate images, memes, and other content for Twitter, Reddit, etc.
* had a thought that we should have either a more general one of these or a swarm or both -- need something connecting all the calendars, events, and initiatives of all the AI communities, langchain, laion, eluther, lesswrong, gato, rob miles, chatgpt hackers, etc etc
* Swarm of AI influencers to spread marketing

@ -1,101 +0,0 @@
# Flywheel Effect for Developer Acquisition and Incentivization
As with the sales model, the developer acquisition and incentivization model also relies on a flywheel effect. This effect is particularly potent in a community-driven ecosystem such as ours, where the value proposition continually grows as more developers join and contribute to our projects. Here's how we could apply this approach:
## Step 1: Initial Value Proposition for Developers
The starting point of the flywheel is to provide an attractive value proposition for developers. This could include:
- The ability to work on cutting-edge technology (Swarms, in this case).
- The opportunity to contribute to a community-driven, open-source project.
- The chance to learn from and collaborate with a global network of highly skilled developers.
- An incentivization structure that rewards contributions (more on this later).
## Step 2: Developer Acquisition
With the initial value proposition in place, we can move on to the actual acquisition of developers. This could be accomplished through:
- Active recruitment from online developer communities.
- Referral programs that incentivize current contributors to bring in new developers.
- Partnerships with universities, boot camps, and other institutions to attract budding developers.
## Step 3: Collaboration and Learning
Once developers join our ecosystem, they become part of a collaborative community where they can learn from each other, improve their skills, and work on exciting and meaningful projects. This, in turn, attracts more developers, adding momentum to the flywheel.
## Step 4: Recognizing and Rewarding Contributions
To keep the flywheel spinning, it's crucial to recognize and reward the contributions made by developers. This can be done in various ways:
- Monetary rewards: Developers can be paid based on the value their contributions bring to the project. This could be determined through various metrics, such as the complexity of their contributions, the impact on the project, or the amount of their code that gets used in production.
- Reputation and recognition: The open-source nature of our project means that all contributions are public and can be used by developers to build their professional profiles. Contributors could also be highlighted on our website, in our communications, and at community events.
- Career advancement: Developers who consistently make valuable contributions could be offered positions of leadership within the project, such as becoming maintainers or joining a steering committee.
- Agora Tokens: We could create a system of tokens that are earned based on contributions. These tokens could be exchanged for various benefits, such as access to exclusive events, special training, or even physical goods.
## Step 5: Scaling the Flywheel
With the flywheel in motion, the next step is to scale. As our community grows and our technology improves, we can attract more developers and create more value. This leads to a virtuous cycle of growth, where each new developer adds to the attractiveness of our project, which in turn brings in more developers.
In essence, this flywheel approach is about creating a community where everyone benefits from each other's contributions. The more value a developer adds, the more they are rewarded. The more developers contribute, the more value is created, attracting even more developers.
Such a model not only aligns with our values of openness, collaboration, and shared success, but it also gives us a sustainable and scalable method for growing our developer community. It makes Agora not just a place to work, but also a place to learn, grow, and be recognized for one's contributions. This is a powerful way to ensure that we can continue to advance our technology and make a significant impact on the world.
# Risks and mitigations
The open source engineering freelancer model brings with it its own set of potential risks and challenges. Here's an exploration of some of these, along with strategies for mitigation:
**1. Quality Control:** When dealing with a wide network of freelance contributors, ensuring a consistent standard of quality across all contributions can be challenging. This can be mitigated by implementing rigorous review processes and standards, establishing an automated testing infrastructure, and fostering a culture of quality among contributors. Providing clear contribution guidelines, code style guides, and other resources can help freelancers understand what's expected of them. Providing Educational resources such as sponsoring creators like Yannic, and even making our own courses and then building techno-monasteries where young people can come in and research for free.
**2. Security Risks:** Open-source projects can be susceptible to malicious contributors, who might introduce vulnerabilities into the codebase. To mitigate this, rigorous code review processes should be in place. Additionally, adopting a "trust but verify" approach, leveraging automated security scanning tools, and conducting periodic security audits can be beneficial.
**3. Intellectual Property Issues:** Open-source projects can face risks around intellectual property, such as contributors introducing code that infringes on someone else's copyrights. A clear Contributor License Agreement (CLA) should be in place, which contributors need to agree to before their contributions can be accepted. This helps protect the project and its users from potential legal issues.
**4. Loss of Core Focus:** With numerous contributors focusing on different aspects of the project, there can be a risk of losing sight of the project's core objectives. Maintaining a clear roadmap, having a strong leadership team, and ensuring open and regular communication can help keep the project focused.
**5. Contributor Burnout:** Freelancers contributing in their free time might face burnout, especially if they feel their contributions aren't being recognized or rewarded. To mitigate this, create a supportive environment where contributors' efforts are acknowledged and rewarded. This might include monetary rewards, but can also include non-monetary rewards like public recognition, advancement opportunities within the project, and so on.
**6. Fragmentation:** In open source projects, there is a risk of fragmentation where different contributors or groups of contributors might want to take the project in different directions. Strong project governance, a clear roadmap, and open, transparent decision-making processes can help mitigate this risk.
**7. Dependency on Key Individuals:** If key parts of the project are understood and maintained by only a single contributor, there is a risk if that individual decides to leave or is unable to contribute for some reason. This can be mitigated by ensuring knowledge is shared and responsibilities are spread among multiple contributors.
Overall, these risks can be managed with proper planning, clear communication, and the implementation of good governance and security practices. It's essential to approach the open source model with a clear understanding of these potential pitfalls and a plan to address them.
## Plan to Gain Open Source Developers for SWARMS
Attracting and retaining open-source developers is a challenge that requires a strategic approach. This plan emphasizes delivering value to the developers as well as providing recognition, community, and financial incentives.
### Step 1: Foster an Engaging and Inclusive Community
The first step is to foster an engaging and inclusive open-source community around SWARMS. This community should be a place where developers feel welcome and excited to contribute. Regular community events (both online and offline), engaging content, and a supportive environment can help attract and retain developers.
### Step 2: Provide Clear Contribution Guidelines
Providing clear and comprehensive contribution guidelines will make it easier for developers to get started. These guidelines should cover the basics of how to set up the development environment, how to submit changes, and how the code review process works.
### Step 3: Offer Educational Resources and Training
Providing training and educational resources can help developers grow their skills and contribute more effectively. These resources could include tutorials, webinars, workshops, documentation, and more.
### Step 4: Establish a Recognition and Reward System
Recognize and reward the contributions of developers. This could involve public recognition, like featuring contributors on the SWARMS website, as well as financial incentives. Implementing a system where developers earn a share of the revenue from SWARMS based on their contributions can be a strong motivator.
### Step 5: Implement a Strong Support System
Offer strong technical support to developers. This could include dedicated channels for developers to ask questions, request feedback, and share their progress. Having core team members available to provide assistance and mentorship can be hugely beneficial.
### Step 6: Regularly Solicit and Incorporate Feedback
Regularly ask for feedback from developers and incorporate their suggestions into future developments. This shows developers that their opinions are valued and can lead to improvements in SWARMS.
## Flywheel for Gaining More Open Source Developers
Now let's look at the flywheel effect that can result from this plan. The idea of the flywheel is that each part of the process feeds into the next, creating a cycle of growth that becomes self-sustaining over time.
1. We build an engaging and supportive community around SWARMS.
2. This community attracts more developers who are interested in contributing to SWARMS.
3. As more developers contribute, the quality and scope of SWARMS improve, making it more attractive to potential users.
4. As SWARMS gains more users, the potential revenue from SWARMS increases, allowing for larger rewards to be distributed to developers.
5. The prospect of these rewards attracts even more developers to the SWARMS community.
6. The cycle repeats, with each iteration attracting more developers, improving SWARMS, increasing its user base, and raising potential rewards.
Through this plan and the resulting flywheel effect, we can attract a strong, committed team of open-source developers to build SWARMS and make it the best it can be.

@ -1,101 +0,0 @@
# The Swarms Flywheel
1. **Building a Supportive Community:** Initiate by establishing an engaging and inclusive open-source community for both developers and sales freelancers around Swarms. Regular online meetups, webinars, tutorials, and sales training can make them feel welcome and encourage contributions and sales efforts.
2. **Increased Contributions and Sales Efforts:** The more engaged the community, the more developers will contribute to Swarms and the more effort sales freelancers will put into selling Swarms.
3. **Improvement in Quality and Market Reach:** More developer contributions mean better quality, reliability, and feature offerings from Swarms. Simultaneously, increased sales efforts from freelancers boost Swarms' market penetration and visibility.
4. **Rise in User Base:** As Swarms becomes more robust and more well-known, the user base grows, driving more revenue.
5. **Greater Financial Incentives:** Increased revenue can be redirected to offer more significant financial incentives to both developers and salespeople. Developers can be incentivized based on their contribution to Swarms, and salespeople can be rewarded with higher commissions.
6. **Attract More Developers and Salespeople:** These financial incentives, coupled with the recognition and experience from participating in a successful project, attract more developers and salespeople to the community.
7. **Wider Adoption of Swarms:** An ever-improving product, a growing user base, and an increasing number of passionate salespeople accelerate the adoption of Swarms.
8. **Return to Step 1:** As the community, user base, and sales network continue to grow, the cycle repeats, each time speeding up the flywheel.
```markdown
+---------------------+
| Building a |
| Supportive | <--+
| Community | |
+--------+-----------+ |
| |
v |
+--------+-----------+ |
| Increased | |
| Contributions & | |
| Sales Efforts | |
+--------+-----------+ |
| |
v |
+--------+-----------+ |
| Improvement in | |
| Quality & Market | |
| Reach | |
+--------+-----------+ |
| |
v |
+--------+-----------+ |
| Rise in User | |
| Base | |
+--------+-----------+ |
| |
v |
+--------+-----------+ |
| Greater Financial | |
| Incentives | |
+--------+-----------+ |
| |
v |
+--------+-----------+ |
| Attract More | |
| Developers & | |
| Salespeople | |
+--------+-----------+ |
| |
v |
+--------+-----------+ |
| Wider Adoption of | |
| Swarms |----+
+---------------------+
```
# Potential Risks and Mitigations:
1. **Insufficient Contributions or Quality of Work**: Open-source efforts rely on individuals being willing and able to spend time contributing. If not enough people participate, or the work they produce is of poor quality, the product development could stall.
* **Mitigation**: Create a robust community with clear guidelines, support, and resources. Provide incentives for quality contributions, such as a reputation system, swag, or financial rewards. Conduct thorough code reviews to ensure the quality of contributions.
2. **Lack of Sales Results**: Commission-based salespeople will only continue to sell the product if they're successful. If they aren't making enough sales, they may lose motivation and cease their efforts.
* **Mitigation**: Provide adequate sales training and resources. Ensure the product-market fit is strong, and adjust messaging or sales tactics as necessary. Consider implementing a minimum commission or base pay to reduce risk for salespeople.
3. **Poor User Experience or User Adoption**: If users don't find the product useful or easy to use, they won't adopt it, and the user base won't grow. This could also discourage salespeople and contributors.
* **Mitigation**: Prioritize user experience in the product development process. Regularly gather and incorporate user feedback. Ensure robust user support is in place.
4. **Inadequate Financial Incentives**: If the financial rewards don't justify the time and effort contributors and salespeople are putting in, they will likely disengage.
* **Mitigation**: Regularly review and adjust financial incentives as needed. Ensure that the method for calculating and distributing rewards is transparent and fair.
5. **Security and Compliance Risks**: As the user base grows and the software becomes more complex, the risk of security issues increases. Moreover, as contributors from various regions join, compliance with various international laws could become an issue.
* **Mitigation**: Establish strong security practices from the start. Regularly conduct security audits. Seek legal counsel to understand and adhere to international laws and regulations.
## Activation Plan for the Flywheel:
1. **Community Building**: Begin by fostering a supportive community around Swarms. Encourage early adopters to contribute and provide feedback. Create comprehensive documentation, community guidelines, and a forum for discussion and support.
2. **Sales and Development Training**: Provide resources and training for salespeople and developers. Make sure they understand the product, its value, and how to effectively contribute or sell.
3. **Increase Contributions and Sales Efforts**: Encourage increased participation by highlighting successful contributions and sales, rewarding top contributors and salespeople, and regularly communicating about the project's progress and impact.
4. **Iterate and Improve**: Continually gather and implement feedback to improve Swarms and its market reach. The better the product and its alignment with the market, the more the user base will grow.
5. **Expand User Base**: As the product improves and sales efforts continue, the user base should grow. Ensure you have the infrastructure to support this growth and maintain a positive user experience.
6. **Increase Financial Incentives**: As the user base and product grow, so too should the financial incentives. Make sure rewards continue to be competitive and attractive.
7. **Attract More Contributors and Salespeople**: As the financial incentives and success of the product increase, this should attract more contributors and salespeople, further feeding the flywheel.
Throughout this process, it's important to regularly reassess and adjust your strategy as necessary. Stay flexible and responsive to changes in the market, user feedback, and the evolving needs of the community.

@ -1,38 +0,0 @@
Today, we stand at the verge of a revolution in artificial intelligence and machine learning. Individual models have accomplished incredible feats, achieving unprecedented levels of understanding and generating incredibly human-like text. But this is just the beginning.
In the future, we should expect more. These models, which we've seen perform so admirably in isolation, should be able to work together, as a team, a swarm. However, this kind of collaborative intelligence doesn't exist today. That's because the technology to seamlessly integrate these models and foster true inter-model collaboration has been missing, until now.
In attempting to create this swarm, we face numerous challenges, such as developing the necessary infrastructure, ensuring seamless integration between the agents, and overcoming the practical limitations of our current computing capabilities. These are daunting tasks, and many have shied away from them because of the sheer complexity of the problem. But, if we can overcome these challenges, the rewards will be unimaginable, all digital activities will be automated.
We envision a future where swarms of Language Learning Model (LLM) agents revolutionize fields like customer support, content creation, and research. Imagine an AI system that could work cohesively, understand complex problems, and deliver multi-faceted solutions. We estimate this could lead to a 100-fold improvement in AI effectiveness, and up to a trillion-dollar impact on the global economy.
The secret to achieving this lies in our open-source approach and the power of the collective. By embracing open-source, we are enabling hundreds of thousands of minds worldwide to contribute to this vision, each bringing unique insights and solutions. Our bug bounty program and automated testing environments will act as catalysts, motivating and rewarding contributors while ensuring the robustness and reliability of our technology.
At Agora, we believe in the transformative potential of this technology, and we are committed to making it a reality. Our world-class team of researchers, engineers, and AI enthusiasts are singularly focused on this mission. With a proven track record of success, and the tenacity to tackle the most complex problems, we are best positioned to lead this charge.
We invite you to join us on this exciting journey. Let's come together to create swarms, advance humanity, and redefine what is possible with artificial intelligence. Our future is in our hands. Let's shape it together.
#2
Swarms is a fluid, seamless, and reliable framework for scaling up LLM autonomous agent interactions to automate digital tasks.
Like a chorus harmonizing to create a more beautiful melody, Swarms transforms isolated AI models into a cooperative network that can achieve feats beyond the capacity of any single model.
Our product is not merely an abstract idea or a dream for the future - it's a reality, right here, right now. Swarms is an accessible, easy-to-use platform. All it takes is a simple 'pip install swarms' command, or a 'git clone' from our GitHub repository, and the swarming power of AI is at your fingertips.
The fundamental functionality of Swarms is simple: it facilitates dynamic interaction and cooperation among AI models. Users set an objective, and the swarm of AI agents collectively process the task, pooling their strengths to provide a more refined, intelligent output.
With Swarms, you're not just using a tool, you're unlocking the next level of AI. You're interacting with a cooperative entity that can tackle complex problems, refine outputs, and ultimately, revolutionize the way we utilize AI.
Our vision is to see Swarms employed across various domains, from customer support to content creation, and research to robotics, expanding the possibilities of what AI can achieve. This isn't just an improvement of existing systems, but a groundbreaking leap forward in AI capability. It's about breaking down the silos, fostering collaboration, and elevating collective intelligence.
At the heart of our product, Swarms, is the principle of cooperative intelligence. Swarms is an AI-based technology that enables multiple autonomous agents, or "worker bees," to coordinate, collaborate, and generate solutions that no single agent could achieve on its own. Think of it as a digital hive mind that decomposes a large objective into manageable subtasks, distributes these tasks amongst the autonomous agents, and then assembles the results into a coherent whole.
In action, the process is fluid, elegant, and surprisingly human-like. An objective is presented to the Swarm - this could be anything from conducting web-based research to producing a report or analyzing a complex dataset. The Swarm, with its innate ability to decompose tasks, breaks the objective down into bite-sized components. Each of these components is then dispatched to a worker agent, equipped with the tools and capabilities to tackle it.
These agents are not mere receivers of instructions. They are sophisticated, multimodal, AI entities capable of browsing the web, ingesting and understanding data, interacting with digital interfaces, and even spawning additional worker agents when necessary. These agents carry out their assigned tasks autonomously, converging their efforts towards the overall objective.
In practical terms, Swarms is as versatile as it is powerful. For a business seeking to automate its customer support system, Swarms could manage incoming queries, distribute them amongst the worker agents, and generate appropriate responses based on the customer's needs. In a research context, Swarms could ingest large volumes of data, identify key areas of interest, and provide comprehensive analyses, all without human intervention.
What sets Swarms apart is its ability to harness the power of collective intelligence, the same principle that allows a flock of birds to move in unison or a colony of ants to construct complex structures. By enabling AI agents to cooperate in this way, Swarms isn't just pushing the boundaries of what AI can do it's redefining them. And it all starts with a simple 'pip install swarms' or 'git clone' from our GitHub repository. Welcome to the age of cooperative AI.

@ -1,149 +0,0 @@
# Bounty Program
Our bounty program is an exciting opportunity for contributors to help us build the future of Swarms. By participating, you can earn rewards while contributing to a project that aims to revolutionize digital activity.
Here's how it works:
1. **Check out our Roadmap**: We've shared our roadmap detailing our short and long-term goals. These are the areas where we're seeking contributions.
2. **Pick a Task**: Choose a task from the roadmap that aligns with your skills and interests. If you're unsure, you can reach out to our team for guidance.
3. **Get to Work**: Once you've chosen a task, start working on it. Remember, quality is key. We're looking for contributions that truly make a difference.
4. **Submit your Contribution**: Once your work is complete, submit it for review. We'll evaluate your contribution based on its quality, relevance, and the value it brings to Swarms.
5. **Earn Rewards**: If your contribution is approved, you'll earn a bounty. The amount of the bounty depends on the complexity of the task, the quality of your work, and the value it brings to Swarms.
## The Three Phases of Our Bounty Program
### Phase 1: Building the Foundation
In the first phase, our focus is on building the basic infrastructure of Swarms. This includes developing key components like the Swarms class, integrating essential tools, and establishing task completion and evaluation logic. We'll also start developing our testing and evaluation framework during this phase. If you're interested in foundational work and have a knack for building robust, scalable systems, this phase is for you.
### Phase 2: Enhancing the System
In the second phase, we'll focus on enhancing Swarms by integrating more advanced features, improving the system's efficiency, and refining our testing and evaluation framework. This phase involves more complex tasks, so if you enjoy tackling challenging problems and contributing to the development of innovative features, this is the phase for you.
### Phase 3: Towards Super-Intelligence
The third phase of our bounty program is the most exciting - this is where we aim to achieve super-intelligence. In this phase, we'll be working on improving the swarm's capabilities, expanding its skills, and fine-tuning the system based on real-world testing and feedback. If you're excited about the future of AI and want to contribute to a project that could potentially transform the digital world, this is the phase for you.
Remember, our roadmap is a guide, and we encourage you to bring your own ideas and creativity to the table. We believe that every contribution, no matter how small, can make a difference. So join us on this exciting journey and help us create the future of Swarms.
**To participate in our bounty program, visit the [Swarms Bounty Program Page](https://swarms.ai/bounty).** Let's build the future together!
## Bounties for Roadmap Items
To accelerate the development of Swarms and to encourage more contributors to join our journey towards automating every digital activity in existence, we are announcing a Bounty Program for specific roadmap items. Each bounty will be rewarded based on the complexity and importance of the task. Below are the items available for bounty:
1. **Multi-Agent Debate Integration**: $2000
2. **Meta Prompting Integration**: $1500
3. **Swarms Class**: $1500
4. **Integration of Additional Tools**: $1000
5. **Task Completion and Evaluation Logic**: $2000
6. **Ocean Integration**: $2500
7. **Improved Communication**: $2000
8. **Testing and Evaluation**: $1500
9. **Worker Swarm Class**: $2000
10. **Documentation**: $500
For each bounty task, there will be a strict evaluation process to ensure the quality of the contribution. This process includes a thorough review of the code and extensive testing to ensure it meets our standards.
# 3-Phase Testing Framework
To ensure the quality and efficiency of the Swarm, we will introduce a 3-phase testing framework which will also serve as our evaluation criteria for each of the bounty tasks.
## Phase 1: Unit Testing
In this phase, individual modules will be tested to ensure that they work correctly in isolation. Unit tests will be designed for all functions and methods, with an emphasis on edge cases.
## Phase 2: Integration Testing
After passing unit tests, we will test the integration of different modules to ensure they work correctly together. This phase will also test the interoperability of the Swarm with external systems and libraries.
## Phase 3: Benchmarking & Stress Testing
In the final phase, we will perform benchmarking and stress tests. We'll push the limits of the Swarm under extreme conditions to ensure it performs well in real-world scenarios. This phase will measure the performance, speed, and scalability of the Swarm under high load conditions.
By following this 3-phase testing framework, we aim to develop a reliable, high-performing, and scalable Swarm that can automate all digital activities.
# Reverse Engineering to Reach Phase 3
To reach the Phase 3 level, we need to reverse engineer the tasks we need to complete. Here's an example of what this might look like:
1. **Set Clear Expectations**: Define what success looks like for each task. Be clear about the outputs and outcomes we expect. This will guide our testing and development efforts.
2. **Develop Testing Scenarios**: Create a comprehensive list of testing scenarios that cover both common and edge cases. This will help us ensure that our Swarm can handle a wide range of situations.
3. **Write Test Cases**: For each scenario, write detailed test cases that outline the exact steps to be followed, the inputs to be used, and the expected outputs.
4. **Execute the Tests**: Run the test cases on our Swarm, making note of any issues or bugs that arise.
5. **Iterate and Improve**: Based on the results of our tests, iterate and improve our Swarm. This may involve fixing bugs, optimizing code, or redesigning parts of our system.
6. **Repeat**: Repeat this process until our Swarm meets our expectations and passes all test cases.
By following these steps, we will systematically build, test, and improve our Swarm until it reaches the Phase 3 level. This methodical approach will help us ensure that we create a reliable, high-performing, and scalable Swarm that can truly automate all digital activities.
Let's shape the future of digital automation together!
--------------------
# Super-Intelligence Roadmap
Creating a Super-Intelligent Swarm involves three main phases, where each phase has multiple sub-stages, each of which will require rigorous testing and evaluation to ensure progress towards super-intelligence.
## Phase 1: Narrow Intelligence
In this phase, the goal is to achieve high performance in specific tasks. These tasks will be predefined and the swarm will be trained and tested on these tasks.
1. **Single Task Mastery**: Focus on mastering one task at a time. This can range from simple tasks like image recognition to complex tasks like natural language processing.
2. **Task Switching**: Train the swarm to switch between different tasks effectively. This includes being able to stop one task and start another one without any loss in performance.
3. **Multi-tasking**: The swarm should be capable of performing multiple tasks simultaneously without any degradation in performance.
## Phase 2: General Intelligence
In this phase, the swarm will be trained to handle a variety of tasks that were not part of the original training set.
1. **Transfer Learning**: The swarm should be able to transfer knowledge learned in one context to another context. This means being able to apply knowledge learned in one task to a different but related task.
2. **Adaptive Learning**: The swarm should be capable of adapting its learning strategies based on the task at hand. This includes being able to adjust its learning rate, exploration vs exploitation balance, etc.
3. **Self-Learning**: The swarm should be able to learn new tasks on its own without any external guidance. This includes being able to understand the task requirements, find relevant information, learn the task, and evaluate its performance.
## Phase 3: Super Intelligence
In this phase, the swarm will surpass human-level performance in most economically valuable work. This involves the swarm being able to solve complex real-world problems, make accurate predictions, and generate innovative solutions.
1. **Complex Problem Solving**: The swarm should be able to solve complex real-world problems. This includes being able to understand the problem, identify relevant information, generate solutions, evaluate the solutions, and implement the best solution.
2. **Predictive Abilities**: The swarm should be able to make accurate predictions about future events based on past data. This includes being able to understand the data, identify relevant patterns, make accurate predictions, and evaluate the accuracy of its predictions.
3. **Innovation**: The swarm should be able to generate innovative solutions to problems. This includes being able to think creatively, generate novel ideas, evaluate the ideas, and implement the best idea.
4. **Self-improvement**: The swarm should be capable of improving its own capabilities. This includes being able to identify areas of weakness, find ways to improve, and implement the improvements.
5. **Understanding**: The swarm should be able to understand complex concepts, make inferences, and draw conclusions. This includes being able to understand natural language, reason logically, and make sound judgments.
Each of these stages will require extensive testing and evaluation to ensure progress towards super-intelligence.
# Reverse-Engineering Super-Intelligence
To reach the Phase 3 level of super-intelligence, we need to reverse engineer the tasks that need to be completed. Here's an outline of what this might look like:
1. **Setting Success Metrics**: For each stage, define clear success metrics. These metrics should be quantitative and measurable, and they should align with the objectives of the stage.
2. **Identifying Prerequisites**: Determine what needs to be in place before each stage can begin. This could include certain capabilities, resources, or technologies.
3. **Developing Training Programs**: For each stage, develop a comprehensive training program. This should include a variety of tasks that will challenge the swarm and push it to
develop the necessary capabilities.
4. **Creating Testing Protocols**: Develop rigorous testing protocols for each stage. These protocols should test all aspects of the swarm's performance and they should be designed to push the swarm to its limits.
5. **Iterating and Improving**: Based on the results of the tests, iterate and improve the swarm. This could involve adjusting the training program, modifying the swarm's architecture, or tweaking its learning algorithms.
6. **Moving to the Next Stage**: Once the swarm has met the success metrics for a stage, it can move on to the next stage. This process continues until the swarm has reached the level of super-intelligence.
This process will require a significant amount of time, resources, and effort. However, by following this structured approach, we can systematically guide the swarm towards super-intelligence.

@ -1,165 +0,0 @@
# Swarms Monetization Strategy
This strategy includes a variety of business models, potential revenue streams, cashflow structures, and customer identification methods. Let's explore these further.
## Business Models
1. **Platform as a Service (PaaS):** Provide the Swarms AI platform on a subscription basis, charged monthly or annually. This could be tiered based on usage and access to premium features.
2. **API Usage-based Pricing:** Charge customers based on their usage of the Swarms API. The more requests made, the higher the fee.
3. **Managed Services:** Offer complete end-to-end solutions where you manage the entire AI infrastructure for the clients. This could be on a contract basis with a recurring fee.
4. **Training and Certification:** Provide Swarms AI training and certification programs for interested developers and businesses. These could be monetized as separate courses or subscription-based access.
5. **Partnerships:** Collaborate with large enterprises and offer them dedicated Swarm AI services. These could be performance-based contracts, ensuring a mutually beneficial relationship.
6. **Data as a Service (DaaS):** Leverage the data generated by Swarms for insights and analytics, providing valuable business intelligence to clients.
## Potential Revenue Streams
1. **Subscription Fees:** This would be the main revenue stream from providing the Swarms platform as a service.
2. **Usage Fees:** Additional revenue can come from usage fees for businesses that have high demand for Swarms API.
3. **Contract Fees:** From offering managed services and bespoke solutions to businesses.
4. **Training Fees:** Revenue from providing training and certification programs to developers and businesses.
5. **Partnership Contracts:** Large-scale projects with enterprises, involving dedicated Swarm AI services, could provide substantial income.
6. **Data Insights:** Revenue from selling valuable business intelligence derived from Swarm's aggregated and anonymized data.
## Potential Customers
1. **Businesses Across Sectors:** Any business seeking to leverage AI for automation, efficiency, and data insights could be a potential customer. This includes sectors like finance, eCommerce, logistics, healthcare, and more.
2. **Developers:** Both freelance and those working in organizations could use Swarms to enhance their projects and services.
3. **Enterprises:** Large enterprises looking to automate and optimize their operations could greatly benefit from Swarms.
4. **Educational Institutions:** Universities and research institutions could leverage Swarms for research and teaching purposes.
## Roadmap
1. **Landing Page Creation:** Develop a dedicated product page on apac.ai for Swarms.
2. **Hosted Swarms API:** Launch a cloud-based Swarms API service. It should be highly reliable, with robust documentation to attract daily users.
3. **Consumer and Enterprise Subscription Service:** Launch a comprehensive subscription service on The Domain. This would provide users with access to a wide array of APIs and data streams.
4. **Dedicated Capacity Deals:** Partner with large enterprises to offer them dedicated Swarm AI solutions for automating their operations.
5. **Enterprise Partnerships:** Develop partnerships with large enterprises for extensive contract-based projects.
6. **Integration with Collaboration Platforms:** Develop Swarms bots for platforms like Discord and Slack, charging users a subscription fee for access.
7. **Personal Data Instances:** Offer users dedicated instances of all their data that the Swarm can query as needed.
8. **Browser Extension:** Develop a browser extension that integrates with the Swarms platform, offering users a more seamless experience.
Remember, customer satisfaction and a value-centric approach are at the core of any successful monetization strategy. It's essential to continuously iterate and improve the product based on customer feedback and evolving market needs.
1. **Platform as a Service (PaaS):** Create a cloud-based platform that allows users to build, run, and manage applications without the complexity of maintaining the infrastructure. You could charge users a subscription fee for access to the platform and provide different pricing tiers based on usage levels. This could be an attractive solution for businesses that do not have the capacity to build or maintain their own swarm intelligence solutions.
2. **Professional Services:** Offer consultancy and implementation services to businesses looking to utilize the Swarm technology. This could include assisting with integration into existing systems, offering custom development services, or helping customers to build specific solutions using the framework.
3. **Education and Training:** Create a certification program for developers or companies looking to become proficient with the Swarms framework. This could be sold as standalone courses, or bundled with other services.
4. **Managed Services:** Some companies may prefer to outsource the management of their Swarm-based systems. A managed services solution could take care of all the technical aspects, from hosting the solution to ensuring it runs smoothly, allowing the customer to focus on their core business.
5. **Data Analysis and Insights:** Swarm intelligence can generate valuable data and insights. By anonymizing and aggregating this data, you could provide industry reports, trend analysis, and other valuable insights to businesses.
As for the type of platform, Swarms can be offered as a cloud-based solution given its scalability and flexibility. This would also allow you to apply a SaaS/PaaS type monetization model, which provides recurring revenue.
Potential customers could range from small to large enterprises in various sectors such as logistics, eCommerce, finance, and technology, who are interested in leveraging artificial intelligence and machine learning for complex problem solving, optimization, and decision-making.
**Product Brief Monetization Strategy:**
Product Name: Swarms.AI Platform
Product Description: A cloud-based AI and ML platform harnessing the power of swarm intelligence.
1. **Platform as a Service (PaaS):** Offer tiered subscription plans (Basic, Premium, Enterprise) to accommodate different usage levels and business sizes.
2. **Professional Services:** Offer consultancy and custom development services to tailor the Swarms solution to the specific needs of the business.
3. **Education and Training:** Launch an online Swarms.AI Academy with courses and certifications for developers and businesses.
4. **Managed Services:** Provide a premium, fully-managed service offering that includes hosting, maintenance, and 24/7 support.
5. **Data Analysis and Insights:** Offer industry reports and customized insights generated from aggregated and anonymized Swarm data.
Potential Customers: Enterprises in sectors such as logistics, eCommerce, finance, and technology. This can be sold globally, provided there's an internet connection.
Marketing Channels: Online marketing (SEO, Content Marketing, Social Media), Partnerships with tech companies, Direct Sales to Enterprises.
This strategy is designed to provide multiple revenue streams, while ensuring the Swarms.AI platform is accessible and useful to a range of potential customers.
1. **AI Solution as a Service:** By offering the Swarms framework as a service, businesses can access and utilize the power of multiple LLM agents without the need to maintain the infrastructure themselves. Subscription can be tiered based on usage and additional features.
2. **Integration and Custom Development:** Offer integration services to businesses wanting to incorporate the Swarms framework into their existing systems. Also, you could provide custom development for businesses with specific needs not met by the standard framework.
3. **Training and Certification:** Develop an educational platform offering courses, webinars, and certifications on using the Swarms framework. This can serve both developers seeking to broaden their skills and businesses aiming to train their in-house teams.
4. **Managed Swarms Solutions:** For businesses that prefer to outsource their AI needs, provide a complete solution which includes the development, maintenance, and continuous improvement of swarms-based applications.
5. **Data Analytics Services:** Leveraging the aggregated insights from the AI swarms, you could offer data analytics services. Businesses can use these insights to make informed decisions and predictions.
**Type of Platform:**
Cloud-based platform or Software as a Service (SaaS) will be a suitable model. It offers accessibility, scalability, and ease of updates.
**Target Customers:**
The technology can be beneficial for businesses across sectors like eCommerce, technology, logistics, finance, healthcare, and education, among others.
**Product Brief Monetization Strategy:**
Product Name: Swarms.AI
1. **AI Solution as a Service:** Offer different tiered subscriptions (Standard, Premium, and Enterprise) each with varying levels of usage and features.
2. **Integration and Custom Development:** Offer custom development and integration services, priced based on the scope and complexity of the project.
3. **Training and Certification:** Launch the Swarms.AI Academy with courses and certifications, available for a fee.
4. **Managed Swarms Solutions:** Offer fully managed solutions tailored to business needs, priced based on scope and service level agreements.
5. **Data Analytics Services:** Provide insightful reports and data analyses, which can be purchased on a one-off basis or through a subscription.
By offering a variety of services and payment models, Swarms.AI will be able to cater to a diverse range of business needs, from small start-ups to large enterprises. Marketing channels would include digital marketing, partnerships with technology companies, presence in tech events, and direct sales to targeted industries.
# Roadmap
* Create a landing page for swarms apac.ai/product/swarms
* Create Hosted Swarms API for anybody to just use without need for mega gpu infra, charge usage based pricing. Prerequisites for success => Swarms has to be extremely reliable + we need world class documentation and many daily users => how do we get many daily users? We provide a seamless and fluid experience, how do we create a seamless and fluid experience? We write good code that is modular, provides feedback to the user in times of distress, and ultimately accomplishes the user's tasks.
* Hosted consumer and enterprise subscription as a service on The Domain, where users can interact with 1000s of APIs and ingest 1000s of different data streams.
* Hosted dedicated capacity deals with mega enterprises on automating many operations with Swarms for monthly subscription 300,000+$
* Partnerships with enterprises, massive contracts with performance based fee
* Have discord bot and or slack bot with users personal data, charge subscription + browser extension
* each user gets a dedicated ocean instance of all their data so the swarm can query it as needed.
*

@ -1,14 +0,0 @@
## Purpose
Artificial Intelligence has grown at an exponential rate over the past decade. Yet, we are far from fully harnessing its potential. Today's AI operates in isolation, each working separately in their corner. But life doesn't work like that. The world doesn't work like that. Success isn't built in silos; it's built in teams.
Imagine a world where AI models work in unison. Where they can collaborate, interact, and pool their collective intelligence to achieve more than any single model could. This is the future we envision. But today, we lack a framework for AI to collaborate effectively, to form a true swarm of intelligent agents.
This is a difficult problem, one that has eluded solution. It requires sophisticated systems that can allow individual models to not just communicate but also understand each other, pool knowledge and resources, and create collective intelligence. This is the next frontier of AI.
But here at Swarms, we have a secret sauce. It's not just a technology or a breakthrough invention. It's a way of thinking - the philosophy of rapid iteration. With each cycle, we make massive progress. We experiment, we learn, and we grow. We have developed a pioneering framework that can enable AI models to work together as a swarm, combining their strengths to create richer, more powerful outputs.
We are uniquely positioned to take on this challenge with 1,500+ devoted researchers in Agora. We have assembled a team of world-class experts, experienced and driven, united by a shared vision. Our commitment to breaking barriers, pushing boundaries, and our belief in the power of collective intelligence makes us the best team to usher in this future to fundamentally advance our species, Humanity.
---

@ -1,115 +0,0 @@
## The Plan
### Phase 1: Building the Foundation
In the first phase, our focus is on building the basic infrastructure of Swarms. This includes developing key components like the Swarms class, integrating essential tools, and establishing task completion and evaluation logic. We'll also start developing our testing and evaluation framework during this phase. If you're interested in foundational work and have a knack for building robust, scalable systems, this phase is for you.
### Phase 2: Optimizing the System
In the second phase, we'll focus on optimizng Swarms by integrating more advanced features, improving the system's efficiency, and refining our testing and evaluation framework. This phase involves more complex tasks, so if you enjoy tackling challenging problems and contributing to the development of innovative features, this is the phase for you.
### Phase 3: Towards Super-Intelligence
The third phase of our bounty program is the most exciting - this is where we aim to achieve super-intelligence. In this phase, we'll be working on improving the swarm's capabilities, expanding its skills, and fine-tuning the system based on real-world testing and feedback. If you're excited about the future of AI and want to contribute to a project that could potentially transform the digital world, this is the phase for you.
Remember, our roadmap is a guide, and we encourage you to bring your own ideas and creativity to the table. We believe that every contribution, no matter how small, can make a difference. So join us on this exciting journey and help us create the future of Swarms.
## Optimization Priorities
1. **Reliability**: Increase the reliability of the swarm - obtaining the desired output with a basic and un-detailed input.
2. **Speed**: Reduce the time it takes for the swarm to accomplish tasks by improving the communication layer, critiquing, and self-alignment with meta prompting.
3. **Scalability**: Ensure that the system is asynchronous, concurrent, and self-healing to support scalability.
Our goal is to continuously improve Swarms by following this roadmap, while also being adaptable to new needs and opportunities as they arise.
# Open Source Roadmap
Here is the detailed roadmap of our priorities and planned features for the near term:
## TODO
* Create a non-langchain worker and swarm class and compare
* Create extensive documentation
* Make sure that the boss agent successfully calls the worker agent if when it's finished makinng a plan
* Make sure the worker agent can access tools like web browser, terminal, and code editor, and multi-modal agents
* Make sure inputs and outputs from boss to worker are well defined and are collaborating if not then readjust prompt
* Create a tool that creates other tools with access to write code, debug, and an architectural argent that creates the architecture and then another agent that creates the code[Architecter(with code examples), code generator (with access to writing code and terminalrools)] -- The Compiler?
* Create a screenshot tool that takes a screen shot and then passes it to a worker multi-modal agent for visual context.
* API endroute in FASTAPI
* Develop Conversational UI with Gradio
* Integrate omni agent as a worker tool
* Integrate Ocean Database as primary vectorstore
* Integrate visual agent
* Integrate quantized hf models as base models with langchain huggingface
1. **Multi-Agent Debate Integration**: Integrate multi-agent debate frameworks ([Multi Agent debate](https://github.com/Skytliang/Multi-Agents-Debate) and [Multi agent2 debate](https://github.com/composable-models/llm_multiagent_debate)) to improve decision-making.
2. **Meta Prompting Integration**: Include meta prompting across all worker agents to guide their actions.
3. **Swarms Class**: Create a main swarms class `swarms('Increase sales by 40$', workers=4)` for managing and coordinating multiple worker nodes.
4. **Integration of Additional Tools**: Integrate [Jarvis](https://github.com/microsoft/JARVIS) as worker nodes, add text to speech and text to script tools ([whisper x](https://github.com/kyegomez/youtubeURL-to-text)), and integrate Hugging Face agents and other external tools.
5. **Task Completion and Evaluation Logic**: Include task completion logic with meta prompting, and evaluate task completion on a scale from 0.0 to 1.0.
7. **Ocean Integration**: Use the [Ocean](https://github.com/kyegomez/Ocean) vector database as the main embedding database for all the agents, both boss and worker.
8. **Improved Communication**: Develop a universal vector database that is only used when a task is completed in this format `[TASK][COMPLETED]`.
9. **Testing and Evaluation**: Create unit tests, benchmarks, and evaluations for performance monitoring and continuous improvement.
10. **Worker Swarm Class**: Create a class for self-scaling worker swarms. If they need help, they can spawn an entirely new worker and more workers if needed.
## Documentation
1. **Examples**: Create extensive and useful examples for a variety of use cases.
2. **README**: Update the README to include the examples and usage instructions.
# Mid-Long term
Here are some potential middle-to-long-term improvements to consider for this project:
1. **Modular Design**: Aim to design a more modular and scalable framework, making it easy for developers to plug-and-play various components.
2. **Interactive User Interface**: Develop a more interactive, user-friendly GUI that allows users to interact with the system without needing to understand the underlying code.
3. **Advanced Error Handling**: Implement advanced error handling and debugging capabilities to make it easier for developers to diagnose and fix issues.
4. **Optimized Resource Utilization**: Improve the efficiency of resource use, aiming to reduce memory consumption and improve speed without sacrificing accuracy.
5. **Collaborative Learning**: Integrate more sophisticated techniques for collaborative learning among the swarm, allowing them to share knowledge and learn from each other's successes and failures.
6. **Autonomous Self-Improvement**: Implement mechanisms that allow the swarm to autonomously learn from its past experiences and improve its performance over time.
7. **Security Enhancements**: Include robust security measures to protect sensitive data and prevent unauthorized access.
8. **Privacy-Preserving Techniques**: Consider incorporating privacy-preserving techniques such as differential privacy to ensure the confidentiality of user data.
9. **Support for More Languages**: Expand language support to allow the system to cater to a more global audience.
10. **Robustness and Resilience**: Improve the system's robustness and resilience, ensuring that it can operate effectively even in the face of hardware or software failures.
11. **Continual Learning**: Implement continual learning techniques to allow the system to adapt and evolve as new data comes in.
12. **More Contextual Understanding**: Enhance the system's capability to understand context better, making it more effective in handling real-world, complex tasks.
13. **Dynamic Task Prioritization**: Develop advanced algorithms for dynamic task prioritization, ensuring that the most important tasks are addressed first.
14. **Expanding the Swarm's Skills**: Train the swarm on a wider range of tasks, gradually expanding their skill set and problem-solving capabilities.
15. **Real-World Deployment**: Test and refine the system in real-world settings, learning from these experiences to further improve and adapt the system.
Remember, these are potential improvements. It's important to revisit your priorities regularly and adjust them based on project needs, feedback, and learning from both successes and failures.

@ -1,295 +0,0 @@
# Sales Documentation
## Small Businesses
Small businesses often lack the resources to hire a dedicated team of data analysts and AI experts. This is where Swarms steps in. With our platform, these businesses can automate many of the tasks that previously required manual effort or expert knowledge. Our strategy for engaging small businesses involves showcasing the simplicity and cost-effectiveness of Swarms.
### Stage 1: Awareness and Education
* Questions: Have you considered implementing AI solutions? Are you aware of how AI can help your business?
* Commitments: Schedule a demo of Swarms.
### Stage 2: Engagement and Evaluation
* Questions: Have you identified areas where AI can improve efficiency? How do you currently manage these tasks?
* Commitments: Conduct a trial run of Swarms on a select project.
### Stage 3: Adoption and Integration
* Questions: Are you satisfied with the results of the trial run? Are you ready to implement Swarms more broadly?
* Commitments: Purchase a subscription and begin the full-scale integration of Swarms.
## Medium-Sized Enterprises
Medium-sized enterprises typically have some level of AI integration but often struggle with scalability. Swarms can offer these organizations a path to seamlessly scale their existing AI capabilities. Our strategy for engaging medium-sized enterprises involves demonstrating how Swarms can take their current AI solutions to the next level.
### Stage 1: Awareness and Potential Evaluation
* Questions: Are you looking to scale your current AI solutions? Are you satisfied with the performance of your current AI tools?
* Commitments: Arrange a personalized demonstration of Swarms.
### Stage 2: Engagement and Testing
* Questions: Have you identified the specific areas where your AI solutions need scaling? Are you open to piloting Swarms in these areas?
* Commitments: Run a pilot program using Swarms.
### Stage 3: Adoption and Expansion
* Questions: Did the pilot program meet your expectations? Are you ready to expand the use of Swarms across your organization?
* Commitments: Commit to a long-term partnership and full integration of Swarms.
## Large Corporations
Large corporations typically have extensive AI capabilities, but they may struggle with coordination and efficiency. Swarms can help streamline these organizations' AI operations. Our strategy for engaging large corporations involves demonstrating how Swarms can enhance the efficiency of their AI ecosystems.
### Stage 1: Awareness and Relevance Evaluation
* Questions: Are you experiencing inefficiencies with your existing AI operations? Have you considered solutions to improve coordination among your AI tools?
* Commitments: Organize an executive briefing session about Swarms.
### Stage 2: Engagement and Trial
* Questions: Can you identify specific use cases for Swarms in your organization? Are you willing to conduct a trial run of Swarms?
* Commitments: Implement a trial run of Swarms for selected use cases.
### Stage 3: Adoption and Wide-Scale Implementation
* Questions: Was the trial run of Swarms successful? Are you ready to implement Swarms throughout your organization?
* Commitments: Form a strategic alliance and proceed with wide-scale implementation of Swarms.
Remember, this is more than just a transaction. It's a partnership. And like any good partnership, it's built on trust, communication, and a shared vision. We're excited to embark on this journey with you, and we're committed to supporting you every step of the way.
# SPIN SOP
This is a detailed customer journey roadmap and Standard Operating Procedure for selling Swarms to businesses of varying sizes. The SPIN selling method (Situation, Problem, Implication, Need-payoff) will be incorporated throughout the document to provide a comprehensive approach. We'll explore a scenario that begins with cold emailing and culminates in offering theoretical consultation package deals.
**1. Lead Generation and Cold Outreach**
Our journey begins with identifying potential leads that could benefit from the capabilities of Swarms. This step involves researching potential clients based on their industry, size, digital footprint, and overall potential to benefit from AI automation.
Upon identifying a potential client, initiate contact with a tailored cold email. This email should:
- Grab the recipient's attention (Subject line is crucial)
- Introduce Swarms and its potential benefits (unique selling proposition)
- Propose a discovery call or meeting to discuss how Swarms could be beneficial
An example could be:
*Subject: Elevate Your Business with the Power of AI Swarm Technology*
Dear [Recipient's Name],
I represent Agora, a pioneer in the field of cooperative AI. Our latest innovation, Swarms, harnesses the power of AI to drive efficiency, streamline operations, and ultimately boost profitability. I would love to have a conversation with you to discuss how this cutting-edge technology can specifically help [Their Company Name].
Are you available for a quick call next week?
Best regards,
[Your Name]
**2. Discovery Call**
The aim of the discovery call is to learn about the potential client's business and identify their needs using the SPIN selling method:
*SITUATION* - Get an understanding of the client's current operations, their use of technology, and their overall business landscape.
*PROBLEM* - Identify any potential areas where the client might be facing challenges - these could be inefficiencies, high operating costs, or unmet customer needs.
*IMPLICATION* - Discuss the consequences of these problems, such as reduced profitability or customer dissatisfaction.
*NEED-PAYOFF* - Finally, demonstrate how Swarms can address these issues and the benefits it will bring to their business.
**3. Follow-Up and Tailored Proposal**
After gaining a deeper understanding of the client's needs, follow up with a detailed proposal that outlines how Swarms can specifically address their challenges. The proposal should highlight:
- How Swarms fits into their current operations
- A projection of improvements and potential return on investment
- The steps involved in the implementation process
**4. Theoretical Consultation Packages**
Introduce consultation packages at this stage to provide further value and assure the client of continued support during the Swarms integration journey. The packages could include:
- *Swarms Starter Pack*: Ideal for small businesses. Includes initial setup and integration, basic training, and a month of technical support.
- *Swarms Business Pack*: Suited for medium-sized businesses. Offers advanced setup, employee training, a dedicated support manager, and three months of technical support.
- *Swarms Enterprise Pack*: For large corporations. Includes customized setup and integration, extensive training, a dedicated account manager, and six months of priority technical support.
**5. Demonstration and Commitment**
Offer a demonstration to show Swarms in action. This could be a simulated use-case relevant to the client's industry or a walk-through of the platform.
Post-demonstration, ask for the client's commitment to move to the next step. This could be a meeting with other decision-makers, an agreement to a trial period, or a signed contract.
**6. Implementation and Onboarding**
After gaining the client's commitment, the next stage involves the implementation of Swarms in their operations. This will depend on the client's size, the complexity of their operations, and the specifics agreed upon in the proposal.
**7. Continued Support and Review**
Continued technical support is essential. Regularly check in with the client, ensure they are getting the most out of Swarms, and address any issues promptly. It's also important to review the impact of Swarms on the client's operations after a set period and adjust the strategy as necessary.
Selling Swarms is not about pushing a product; it's about offering a solution that can revolutionize businesses. The journey from cold emailing to a fully-fledged partnership should reflect this philosophy at every stage.
# Tactics
# Value proposition Formula
```
Dream outcome • Perceived Likelihood
-------------------------------------
Time Delay * Effort & Sacrifice
```
Where:
#### Maximize Value Using Value Equation
❏ Maximize Dream Outcome (solve problem worth solving)
❏ Maximize Perceived Likelihood of Success (testimonials& proven case studies)
❏ Minimize Time to Success (How can we make this faster? How can we show progress?)
❏ Minimize Effort & Sacrifice (How can we make this easier? More Seamless? Convenient?)
### Swarms Examples
### Swarms Value Proposition
"Leap into a new era of productivity with Swarms. Automate up to 50% of your business tasks with the power of cooperative AI, a proven solution trusted by thousands worldwide. With an easy integration process, your dream of seamless automation is just a few steps away."
Where:
- The dream outcome is achieving a significant boost in efficiency and productivity by automating 30-50% of your daily business tasks with Swarms.
- The perceived likelihood of success is backed by our strong track record, with thousands of successful implementations and satisfied customers globally.
- We've minimized the time delay to success. Swarms provides quick and painless onboarding, with step-by-step support to ensure smooth integration into your existing workflow.
- The effort and sacrifice required is significantly less than traditional methods. Swarms is designed for ease of use, requiring minimal technical know-how. Plus, our dedicated support team is always at hand to ensure a seamless experience.
In essence, Swarms makes the dream of comprehensive business automation an attainable reality. Join thousands of our active users in harnessing the power of cooperative AI, and transform your business operations with us today.
### Value prop SWARMS
```
We've helped thousands of people just like you automate 30% of their activities with Swarms. And, all it takes to get started is a fast simple onboarding agent that asks you to integrate your tools and datasources.
```
In today's competitive landscape, organizations of all sizes are continually seeking ways to automate routine tasks, streamline processes, and make data-driven decisions. Enter Swarms, a revolutionary AI-based technology that leverages the power of multiple autonomous agents to perform tasks with unprecedented speed and accuracy.
This guide lays out a SPIN (Situation, Problem, Implication, Need-payoff) approach to selling Swarms, taking you through a step-by-step journey from cold outreach to closing the deal.
#2
Cold Outreach
Our first step is to generate interest in Swarms, and we do this through personalized, value-driven outreach. Focus on how Swarms can solve their pain points and bring value to their organization.
Situation Questions:
- Do you currently use any AI or machine learning tools in your organization?
- How are you managing tasks that could be automated or require large-scale data analysis?
Problem Questions:
- Are there any specific challenges in managing these tasks manually or using traditional AI models?
- How much time and resources are you currently dedicating to these tasks?
Implication Questions:
- What is the cost of not addressing these challenges or improving these processes?
- How does this affect your teams productivity, your operational efficiency, or your competitive advantage?
Need-payoff Questions:
- How would your organization benefit from automating these tasks or making them more efficient?
- Could an AI-based tool that leverages the power of multiple autonomous agents be beneficial for your organization?
#3
Discovery Calls
Once you've generated interest and scheduled a discovery call, dive deeper into their business operations, their pain points, and their goals. Establish a clear understanding of what they need and how Swarms can fulfill those needs.
Situation Questions:
- Could you tell me more about your current workflows and operational processes?
- What is the biggest challenge your team is facing in managing these workflows?
Problem Questions:
- Have you ever encountered situations where the scale or complexity of tasks was overwhelming for your existing systems?
- Are there any tasks that you believe require a level of intelligence or speed that your current solutions cant provide?
Implication Questions:
- How does this affect your growth, competitiveness, or profitability in the long term?
- What are the ripple effects of these challenges on other aspects of your business?
Need-payoff Questions:
- Would a solution that can handle tasks of any scale or complexity efficiently and accurately be of value to your team?
- How would such a solution impact your operational efficiency, team productivity, and bottom line?
#4
Product Demonstration
This is the stage where you showcase the capabilities of Swarms, demonstrating its features and how it can be applied to their specific use cases. Show, don't tell.
Situation Questions:
- Can you share a few tasks that you believe could be significantly improved with automation or intelligent processing?
- What features or functionalities are you looking for in a solution to improve these tasks?
Problem Questions:
- Are there any specific issues that you expect to arise if these tasks are managed with your current systems?
- Have past solutions failed to deliver on your expectations in any way?
Implication Questions:
- What are the potential consequences if these issues are not addressed or if the tasks are not improved?
- How does this affect your teams morale, your customer satisfaction, or your market position?
Need-payoff Questions:
- Would you be interested in a solution that can automate these tasks, provide intelligent processing, and scale according to your needs?
- How would such a solution change the way your team works and the outcomes they achieve?
#5
Proposal and Negotiation
Once they've seen Swarms in action, it's time to present a tailored proposal that highlights the value of Swarms for their organization. Always be ready to negotiate, but remember, the focus is on value, not price.
Situation Questions:
- What does your budget look like for a solution like Swarms?
- What are the key factors you'll consider in making your decision?
Problem Questions:
- Are there any concerns or roadblocks that you think might prevent you from moving forward with Swarms?
- Have budget constraints or cost issues affected your ability to implement effective solutions in the past?
Implication Questions:
- If cost or resource constraints continue to limit your ability to implement effective solutions, how will this impact your organization in the long term?
- Are you prepared to deal with the ramifications of continued inefficiencies or challenges?
Need-payoff Questions:
- How would investing in Swarms impact your budget compared to the potential return on investment?
- How much value do you place on a solution that can transform the way you manage tasks, improve efficiency, and drive growth?
#6
Closing the Deal
Closing the deal is about more than just signing a contract. Its about setting the stage for a long-term partnership, ensuring they see the value in Swarms not just as a product, but as a key part of their business strategy.
Situation Questions:
- Are you ready to move forward with implementing Swarms in your organization?
- What expectations do you have from Swarms in the initial phase?
Problem Questions:
- Are there any final concerns or questions you have that could prevent us from moving forward?
- Is there anything thats still unclear about how Swarms works or the value it can bring to your organization?
Implication Questions:
- If these concerns or uncertainties are not addressed, how will it affect your decision?
- Are you willing to overlook the potential value Swarms could bring due to these concerns?
Need-payoff Questions:
- How can we address these concerns to make Swarms a part of your organization's growth story?
- Can we agree on the fact that Swarms, with its unique capabilities, could significantly boost your organization's operational efficiency and competitiveness?
#7
Consultation Packages
As part of our commitment to ensure our clients extract the maximum value from Swarms, we offer several consultation packages. These packages are designed to provide continuous support as you integrate Swarms into your workflows and processes, helping you overcome any challenges and optimize the system for your specific needs.
Package 1 - Initial Setup & Training: Our team of experts will assist you in setting up Swarms, train your team on its functionalities and features, and provide support as you start to use the system.
Package 2 - Optimization & Fine-tuning: As you use Swarms, we'll work closely with you to optimize the system for your specific tasks and workflows, ensuring you extract the maximum value from the platform.
Package 3 - Ongoing Support & Upgrades: We provide continuous support to address any challenges you encounter and ensure you always have access to the
latest upgrades and improvements to Swarms.
Remember, Swarms isn't just a product; it's a partnership. We're committed to working with you every step of the way, ensuring you harness the full power of cooperative AI to transform your organization.

@ -1,143 +0,0 @@
# **Open Source Freelancer Salespeople Recruitment Plan**
Here is a strategic plan to attract open-source freelancer salespeople to Swarms.
1. **Promote the Vision**: A compelling vision is the cornerstone of any recruitment strategy. Share the vision and mission of Swarms its potential to revolutionize AI and digital automation on every possible platform. The goal is to attract freelancers who are excited about the potential of AI and are eager to be part of this revolution.
2. **Compensation Structure**: Offer a highly competitive, commission-based compensation structure. This could include a base rate for each sale, as well as performance-based bonuses and incentives for high-performing salespeople. Make it clear that the better they do, the more they earn.
3. **Comprehensive Training**: Ensure all salespeople receive comprehensive training about Swarms, its capabilities, and the potential benefits it can offer to businesses. The more knowledgeable they are about the product, the better they can sell it.
4. **Collaborative Community**: Foster a community of open-source freelancer salespeople. This community will provide a platform for salespeople to exchange ideas, share success stories, and learn from each other. Foster a culture of collaboration and continuous learning.
5. **Clear Communication**: Be clear about expectations, targets, and performance metrics. Provide regular feedback and recognition to keep salespeople motivated and aligned with the company's goals.
6. **Sales Tools & Resources**: Equip salespeople with the necessary tools and resources they need to sell effectively. This might include sales scripts, customer personas, case studies, product demos, and any other material that can aid them in their sales efforts.
7. **Marketing Support**: In parallel to sales efforts, invest in marketing initiatives to build brand awareness and generate leads. The higher the brand visibility, the easier it will be for salespeople to sell the product.
8. **Advocate Program**: Introduce an advocate program where salespeople get additional rewards for bringing in more salespeople. This will not only increase the sales force but also instill a sense of ownership and involvement among salespeople.
**Flywheel Research Diagram**
Building a flywheel involves understanding and leveraging the compounding effect of a circular, connected process, where each stage fuels the next. Here's a conceptualization of a Swarms Sales Flywheel:
1. **Training & Empowerment**: Start by attracting freelance salespeople and providing comprehensive training and resources. As salespeople gain competence, they become better at selling Swarms.
2. **Sales**: As sales increase, so do the visibility of Swarms and the earnings of the salespeople. This attracts more clients and more potential salespeople.
3. **Client Success**: Successful clients serve as testimonials and case studies, helping to validate the product and making it easier for salespeople to sell Swarms. Success stories and increased visibility generate more interest among potential salespeople.
4. **Community & Advocacy**: A growing community of successful salespeople, satisfied clients, and a strong product fuels advocacy. Salespeople are more likely to recommend the opportunity to other potential salespeople.
5. **Growth**: As the community and client base grow, so do the opportunities for salespeople. Increased earnings and a stronger product reputation attract more salespeople, turning the flywheel faster.
6. **Back to Training & Empowerment**: The increased interest from potential salespeople leads back to the first stage of the flywheel training and empowering more salespeople.
The key to the flywheel's momentum is ensuring each stage is performed effectively, creating a virtuous cycle that builds momentum over time. It relies on customer success, salesperson success, and product success, all fueling each other to keep the flywheel spinning.
# Risks and Mitigations
Embracing an open source salesforce represents an innovative approach and can have significant benefits, including scalability, diversity, and cost-effectiveness. However, there are potential risks that need to be considered and mitigated. Here they are, along with strategies for managing them:
**1. Brand Representation:** In an open source sales model, you can't control who represents your brand, as anyone can essentially become a salesperson. This can pose a risk if salespeople don't present the product or brand accurately, or don't uphold company values in their interactions.
*Mitigation Strategy:* Provide clear brand guidelines, sales training, and codes of conduct that salespeople must adhere to. Regular monitoring and feedback can help ensure compliance. Also, introduce a certification process to officially recognize salespeople who demonstrate their understanding of the product and brand.
**2. Product Misrepresentation:** Salespeople may overpromise or misrepresent the product to close a deal, leading to customer dissatisfaction and damage to the brand.
*Mitigation Strategy:* Ensure that comprehensive and accurate product information is readily available. Provide clear guidelines on what can and cannot be promised to customers. Regularly update salespeople on product developments so their knowledge remains accurate.
**3. Variable Quality of Salespeople:** In an open-source model, the quality of salespeople can vary widely, which may lead to inconsistent customer experiences.
*Mitigation Strategy:* Offer comprehensive training and provide sales scripts or guidelines to ensure a uniform sales approach. Monitor performance and provide feedback to help salespeople improve.
**4. Competition and Infighting:** Salespeople may compete with each other for the same leads, causing conflicts and damaging team cohesion.
*Mitigation Strategy:* Create a clear system for lead assignment and territory division to prevent overlaps. Promote a collaborative rather than competitive culture, emphasizing the collective success of the team over individual achievements.
**5. Data Security and Privacy:** With more individuals having access to company and customer information, the risk of data breaches increases.
*Mitigation Strategy:* Provide training on data security and privacy policies. Use secure systems for data access and sharing. Regularly audit and monitor data access to detect any potential breaches.
**6. Lack of Control:** The company may have less control over an open-source salesforce compared to an in-house team, leading to potential inconsistencies and inefficiencies.
*Mitigation Strategy:* Regular communication and feedback are crucial. Use a performance management system to set expectations, track progress, and identify areas for improvement.
Ultimately, the key is to adopt a long-term perspective, just like Jeff Bezos. Invest in training and building relationships with the salespeople. Foster a culture of customer obsession, and instill a sense of ownership and responsibility in the salespeople. Just as with any other risk, these can be mitigated with careful planning, continuous monitoring, and regular feedback.
# Open Source Salesperson Onboarding Experience
Creating an efficient, streamlined, and effective onboarding experience for open source salespeople is essential to minimize time and maximize engagement. Drawing inspiration from the simplicity and user-focus of Steve Jobs, this document proposes an onboarding agent that is effortless, engaging, and educational.
## Landing Page
The journey starts with a landing page that is clean, crisp, and intuitively designed. A minimalistic aesthetic, akin to Apple's design philosophy, helps the user focus on what's important. The landing page should contain:
- A bold, clear headline, expressing the value proposition for becoming an open source salesperson for Swarms.
- A short video or animation introducing Swarms and the opportunity for the salespeople.
- Clear call-to-action (CTA) buttons to start the onboarding process or to learn more.
## Interactive Learning Modules
Once the user clicks on the CTA, they're taken to an interactive course platform. This platform should feature short, digestible video modules covering a range of essential topics, including:
1. An Introduction to Swarms: An engaging video that explains the concept, the value it brings to businesses, and the open-source ethos driving it.
2. Understanding the Technology: A simple, jargon-free explanation of the underlying technology, how it works, and why it works that way. Emphasis should be on benefits rather than technical intricacies.
3. Successful Sales Strategies: Sharing effective sales techniques and strategies that have worked for Swarms, along with case studies and testimonials.
4. Navigating Customer Conversations: Guidance on how to effectively communicate with potential customers, including understanding their needs, presenting Swarms as a solution, and addressing objections.
After each module, the user is asked to answer a few questions to ensure understanding and engagement. This also helps in identifying potential areas of confusion or difficulty.
## Personal Interaction
Once the user completes all the modules and successfully answers the questions, they're invited to schedule a one-on-one call with a member of APAC AI or an experienced open source sales freelancer. This serves as a validation step, providing personalized feedback and guidance to ensure the salesperson is ready to start selling Swarms.
Throughout this journey, the focus should be on simplicity and intuitiveness. Just like Steve Jobs did with Apple's products, the onboarding experience should be so seamless and enjoyable that it's almost invisible, allowing the user to focus on what truly matters learning about Swarms and how to sell it.
# Open Source Salesperson Onboarding: Post Course Completion
### For more assistance check out these resources
* [Pricing Package](https://www.acquisition.com/hubfs/Offer%20Checklists%20-%20PDF%20Downloads/Pricing-Value-Checklist.pdf?hsLang=en)
*[Alex Hormozi](https://www.acquisition.com/offers-value-equation)
Once a salesperson has completed the initial course and had their one-on-one session, the onboarding continues to the next phase preparing them for sales activities and ensuring they have the necessary tools and resources.
## Access to CRM and Sales Tools
Every salesperson is provided with access to a CRM (Customer Relationship Management) system. This CRM would be a simplified, user-friendly system that allows them to manage their prospects, track their interactions, and monitor their sales progress. They would also receive training on how to effectively use the CRM to streamline their sales activities.
## Sales Resources
Salespeople would be provided with a suite of sales resources, including Swarms product brochures, case studies, presentations, and a script guideline. They would also be given access to a community forum where they can connect with other salespeople, share experiences, ask questions, and learn from each other.
## Making a Sale
In terms of the actual sale process, the salesperson would direct the customer to a unique landing page on the APAC.ai website. This landing page would be specifically designed for the sales journey, and it would allow the customer to input their salesperson's ID during the checkout process.
This ID linking mechanism is critical, as it ensures that the salesperson gets credited for any sales they bring in. Once a sale is made, the salesperson's commission gets credited to their account.
## Post-Sale and Account Management
Post-sale, the salesperson's role transitions to more of an account manager. They become the primary point of contact for the customer, responsible for ensuring customer satisfaction, handling any issues or concerns, and identifying opportunities for upselling or cross-selling.
The salesperson would also receive a recurring revenue from their accounts. This not only incentivizes them to maintain a good relationship with their customers but also rewards them for the ongoing value they provide.
## Feedback and Performance Reviews
Periodic performance reviews would be conducted to provide feedback to the salespeople and help them improve. These reviews would also be an opportunity to recognize top performers and share their success stories with the wider community.
Overall, the objective is to create a smooth, rewarding, and self-sustaining sales ecosystem. Salespeople are empowered with the tools, resources, and incentives they need to succeed, and in return, they help drive the growth and success of Swarms. It's a win-win scenario that has the potential to dramatically accelerate Swarms' market penetration and customer adoption.

@ -1,242 +0,0 @@
Code is clean if it can be understood easily by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.
_____________________________________
## General rules
1. Follow standard conventions.
2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
3. Boy scout rule. Leave the campground cleaner than you found it.
4. Always find root cause. Always look for the root cause of a problem.
## Design rules
1. Keep configurable data at high levels.
2. Prefer polymorphism to if/else or switch/case.
3. Separate multi-threading code.
4. Prevent over-configurability.
5. Use dependency injection.
6. Follow Law of Demeter. A class should know only its direct dependencies.
## Understandability tips
1. Be consistent. If you do something a certain way, do all similar things in the same way.
2. Use explanatory variables.
3. Encapsulate boundary conditions. Boundary conditions are hard to keep track of. Put the processing for them in one place.
4. Prefer dedicated value objects to primitive type.
5. Avoid logical dependency. Don't write methods which works correctly depending on something else in the same class.
6. Avoid negative conditionals.
## Names rules
1. Choose descriptive and unambiguous names.
2. Make meaningful distinction.
3. Use pronounceable names.
4. Use searchable names.
5. Replace magic numbers with named constants.
6. Avoid encodings. Don't append prefixes or type information.
7. The Name of a variable, Function, or Class should answer why it exists, what it does , and how it can used. Comments are a burden
8. Clarity is King
9. ClassNames should not be a verb
10. Methods should have verb or verb phrase names
11. Be simple. Be Direct. Say what you mean, mean what you say.
12. Don't use the same word for 2 purposes
13.
## Functions rules
1. Small.
2. Do one thing.
3. Use descriptive names.
4. Prefer fewer arguments.
5. Have no side effects.
6. Don't use flag arguments. Split method into several independent methods that can be called from the client without the flag.
7. Smaller than 20 lines long
8. The Stepdown rule => function -> next level of abstraction
## ErrorHandling
1. Specify where the error in print
2. Don't use a single variable
3.
## If statements
1.
## Comments rules
1. Always try to explain yourself in code.
2. Don't be redundant.
3. Don't add obvious noise.
4. Don't use closing brace comments.
5. Don't comment out code. Just remove.
6. Use as explanation of intent.
7. Use as clarification of code.
8. Use as warning of consequences.
## Source code structure
1. Separate concepts vertically.
2. Related code should appear vertically dense.
3. Declare variables close to their usage.
4. Dependent functions should be close.
5. Similar functions should be close.
6. Place functions in the downward direction.
7. Keep lines short.
8. Don't use horizontal alignment.
9. Use white space to associate related things and disassociate weakly related.
10. Don't break indentation.
## Objects and data structures
1. Hide internal structure.
2. Prefer data structures.
3. Avoid hybrids structures (half object and half data).
4. Should be small.
5. Do one thing.
6. Small number of instance variables.
7. Base class should know nothing about their derivatives.
8. Better to have many functions than to pass some code into a function to select a behavior.
9. Prefer non-static methods to static methods.
## Tests
1. One assert per test.
2. Readable.
3. Fast.
4. Independent.
5. Repeatable.
## Code smells
1. Rigidity. The software is difficult to change. A small change causes a cascade of subsequent changes.
2. Fragility. The software breaks in many places due to a single change.
3. Immobility. You cannot reuse parts of the code in other projects because of involved risks and high effort.
4. Needless Complexity.
5. Needless Repetition.
6. Opacity. The code is hard to understand.
# Clean Code
Here are some general principles for writing highly usable, functional, reliable, fast, and scalable code:
1. **Clear and Understandable:** The code should be written in a way that's easy for others to understand. This includes using clear variable and function names, and including comments to explain complex sections of code.
2. **Modular and Reusable:** Code should be broken down into small, modular functions and classes that each perform a single task. This makes the code more understandable, and also allows for code reuse.
3. **Robust Error Handling:** The code should be able to handle all potential errors gracefully, and should never crash unexpectedly. This includes checking for invalid input, catching exceptions, and providing useful error messages.
4. **Type Handling:** Whenever possible, the code should enforce and check types to prevent type-related errors. This can be done through the use of type hints in languages like Python, or through explicit type checks.
5. **Logging:** The code should include extensive logging to make it easier to debug and understand what the code is doing. This includes logging any errors that occur, as well as important events or state changes.
6. **Performance:** The code should be optimized for performance, avoiding unnecessary computation and using efficient algorithms and data structures. This includes profiling the code to identify and optimize performance bottlenecks.
7. **Scalability:** The code should be designed to scale well as the size of the input data or the number of users increases. This includes using scalable algorithms and data structures, and designing the code to work well in a distributed or parallel computing environment if necessary.
8. **Testing:** The code should include comprehensive tests to ensure that it works correctly. This includes unit tests for individual functions and classes, as well as integration tests to ensure that the different parts of the code work well together.
9. **Version Control:** The code should be stored in a version control system like Git, which allows for tracking changes, collaborating with others, and rolling back to a previous state if necessary.
10. **Documentation:** The codebase should be well-documented, both in terms of comments within the code and external documentation that explains how to use and contribute to the code.
11. **Continuous Integration/Continuous Deployment (CI/CD):** Implement CI/CD pipelines for automatic testing and deployment. This ensures that any new changes do not break existing functionality and that the latest version of the application is always available for deployment.
# Examples
1. **Clear and Understandable:** Use meaningful variable and function names. Include comments when necessary.
```python
# Good example
def calculate_average(numbers: List[int]) -> float:
"""Calculate and return the average of a list of numbers."""
total = sum(numbers)
count = len(numbers)
return total / count
```
For file and folder names, use descriptive names that relate to their function in your program. For example, a file that contains functions for handling user input might be named `user_input.py`.
2. **Modular and Reusable:** Write functions for tasks that you perform over and over.
```python
def greet_user(name: str):
"""Print a greeting to the user."""
print(f"Hello, {name}!")
```
For folder structure, group related files in the same directory. For example, all test files could be in a `tests` directory.
3. **Robust Error Handling:** Use try/except blocks to catch and handle errors.
```python
def divide_numbers(numerator: float, denominator: float) -> float:
"""Divide two numbers and handle division by zero."""
try:
return numerator / denominator
except ZeroDivisionError:
print("Error: Division by zero.")
return None
```
4. **Type Handling:** Use type hints to specify the type of function arguments and return values.
```python
def greet_user(name: str) -> None:
"""Greet the user."""
print(f"Hello, {name}!")
```
5. **Logging:** Use the `logging` module to log events.
```python
import logging
logging.basicConfig(level=logging.INFO)
def divide_numbers(numerator: float, denominator: float) -> float:
"""Divide two numbers and log if division by zero occurs."""
try:
return numerator / denominator
except ZeroDivisionError:
logging.error("Attempted division by zero.")
return None
```
6. **Performance:** Use built-in functions and data types for better performance.
```python
# Using a set to check for membership is faster than using a list
numbers_set = set(numbers)
if target in numbers_set:
print(f"{target} is in the set of numbers.")
```
7. **Scalability:** For scalability, an example might involve using a load balancer or dividing tasks among different workers or threads. This is more of a system design consideration than a single piece of code.
8. **Testing:** Write tests for your functions.
```python
def test_calculate_average():
assert calculate_average([1, 2, 3, 4]) == 2.5
```
For tests, you could have a separate `tests` directory. Inside this directory, each test file could be named `test_<filename>.py` where `<filename>` is the name of the file being tested.
9. **Version Control:** This point refers to using tools like Git for version control. A simple example would be committing changes to a repository:
```bash
git add .
git commit -m "Add function to calculate average"
git push
```
10. **Documentation:** Write docstrings for your functions.
```python
def calculate_average(numbers: List[int]) -> float:
"""Calculate and return the average of a list of numbers."""
...
```
Documentation might be kept in a `docs` directory, with separate files for different topics.
11. **Continuous Integration/Continuous Deployment (CI/CD):** This is typically handled by a system like Jenkins, GitHub Actions, or GitLab CI/CD. It involves creating a script or configuration file that tells the CI/CD system how to build, test, and deploy your code. For example, a `.github/workflows/main.yml` file for a GitHub Actions workflow.
Remember, consistency in your naming conventions and organization is key. Having a standard and sticking to it will make your codebase easier to navigate and understand.

@ -1,146 +0,0 @@
# Swarm Architecture Design Document
## Overview
The goal of the Swarm Architecture is to provide a flexible and scalable system to build swarm intelligence models that can solve complex problems. This document details the proposed design to create a plug-and-play system, which makes it easy to create custom swarms, and provides pre-configured swarms with multi-modal agents.
## Design Principles
- **Modularity**: The system will be built in a modular fashion, allowing various components to be easily swapped or upgraded.
- **Interoperability**: Different swarm classes and components should be able to work together seamlessly.
- **Scalability**: The design should support the growth of the system by adding more components or swarms.
- **Ease of Use**: Users should be able to easily create their own swarms or use pre-configured ones with minimal configuration.
## Design Components
### AbstractSwarm
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.
### 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.
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.
### Tools and Agents
Tools and agents are the components that provide the actual functionality to the swarms. They can be language models, AI assistants, vector stores, or any other components that can help in problem solving.
To make the system plug-and-play, a standard interface should be defined for these components. Any new tool or agent should implement this interface, so that it can be easily plugged into the system.
## Usage
Users can either use pre-configured swarms or create their own custom swarms.
To use a pre-configured swarm, they can simply instantiate the corresponding swarm class and call the run method with the required objective.
To create a custom swarm, they need to:
1. Define a new swarm class inheriting from AbstractSwarm.
2. Implement the required methods for the new swarm class.
3. Instantiate the swarm class and call the run method.
### Example
```python
# Using pre-configured swarm
swarm = PreConfiguredSwarm(openai_api_key)
swarm.run_swarms(objective)
# Creating custom swarm
class CustomSwarm(AbstractSwarm):
# Implement required methods
swarm = CustomSwarm(openai_api_key)
swarm.run_swarms(objective)
```
## Conclusion
This Swarm Architecture design provides a scalable and flexible system for building swarm intelligence models. The plug-and-play design allows users to easily use pre-configured swarms or create their own custom swarms.
# Swarming Architectures
Sure, below are five different swarm architectures with their base requirements and an abstract class that processes these components:
1. **Hierarchical Swarm**: This architecture is characterized by a boss/worker relationship. The boss node takes high-level decisions and delegates tasks to the worker nodes. The worker nodes perform tasks and report back to the boss node.
- Requirements: Boss node (can be a large language model), worker nodes (can be smaller language models), and a task queue for task management.
2. **Homogeneous Swarm**: In this architecture, all nodes in the swarm are identical and contribute equally to problem-solving. Each node has the same capabilities.
- Requirements: Homogeneous nodes (can be language models of the same size), communication protocol for nodes to share information.
3. **Heterogeneous Swarm**: This architecture contains different types of nodes, each with its specific capabilities. This diversity can lead to more robust problem-solving.
- Requirements: Different types of nodes (can be different types and sizes of language models), a communication protocol, and a mechanism to delegate tasks based on node capabilities.
4. **Competitive Swarm**: In this architecture, nodes compete with each other to find the best solution. The system may use a selection process to choose the best solutions.
- Requirements: Nodes (can be language models), a scoring mechanism to evaluate node performance, a selection mechanism.
5. **Cooperative Swarm**: In this architecture, nodes work together and share information to find solutions. The focus is on cooperation rather than competition.
- Requirements: Nodes (can be language models), a communication protocol, a consensus mechanism to agree on solutions.
6. **Grid-based Swarm**: This architecture positions agents on a grid, where they can only interact with their neighbors. This is useful for simulations, especially in fields like ecology or epidemiology.
- Requirements: Agents (can be language models), a grid structure, and a neighborhood definition (i.e., how to identify neighboring agents).
7. **Particle Swarm Optimization (PSO) Swarm**: In this architecture, each agent represents a potential solution to an optimization problem. Agents move in the solution space based on their own and their neighbors' past performance. PSO is especially useful for continuous numerical optimization problems.
- Requirements: Agents (each representing a solution), a definition of the solution space, an evaluation function to rate the solutions, a mechanism to adjust agent positions based on performance.
8. **Ant Colony Optimization (ACO) Swarm**: Inspired by ant behavior, this architecture has agents leave a pheromone trail that other agents follow, reinforcing the best paths. It's useful for problems like the traveling salesperson problem.
- Requirements: Agents (can be language models), a representation of the problem space, a pheromone updating mechanism.
9. **Genetic Algorithm (GA) Swarm**: In this architecture, agents represent potential solutions to a problem. They can 'breed' to create new solutions and can undergo 'mutations'. GA swarms are good for search and optimization problems.
- Requirements: Agents (each representing a potential solution), a fitness function to evaluate solutions, a crossover mechanism to breed solutions, and a mutation mechanism.
10. **Stigmergy-based Swarm**: In this architecture, agents communicate indirectly by modifying the environment, and other agents react to such modifications. It's a decentralized method of coordinating tasks.
- Requirements: Agents (can be language models), an environment that agents can modify, a mechanism for agents to perceive environment changes.
These architectures all have unique features and requirements, but they share the need for agents (often implemented as language models) and a mechanism for agents to communicate or interact, whether it's directly through messages, indirectly through the environment, or implicitly through a shared solution space. Some also require specific data structures, like a grid or problem space, and specific algorithms, like for evaluating solutions or updating agent positions.
Here is an abstract class that provides the basic structure to process these components:
```python
from abc import ABC, abstractmethod
class AbstractSwarm(ABC):
def __init__(self, agents, vectorstore, tools):
self.agents = agents
self.vectorstore = vectorstore
self.tools = tools
@abstractmethod
def initialize(self):
pass
@abstractmethod
def communicate(self):
pass
@abstractmethod
def process(self):
pass
@abstractmethod
def solve(self):
pass
```
This abstract class requires four methods to be implemented:
- `initialize`: This method is used to set up the initial state of the swarm, including setting up nodes and tools.
- `communicate`: This method is responsible for facilitating communication between nodes.
- `process`: This method handles the processing logic, which can be different based on the swarm architecture.
- `solve`: This method is called to start the problem-solving process.
This abstract class can be inherited by specific swarm architecture classes to implement their specific behavior.
# 3 Ingredients
* The Individual Agent Configuration with a vectorstore and tools
* The Orchestrator, => task assignment, task completion handling, communication layer

@ -1,53 +0,0 @@
# Design Philosophy Document for Swarms
## Usable
### Objective
Our goal is to ensure that Swarms is intuitive and easy to use for all users, regardless of their level of technical expertise. This includes the developers who implement Swarms in their applications, as well as end users who interact with the implemented systems.
### Tactics
- Clear and Comprehensive Documentation: We will provide well-written and easily accessible documentation that guides users through using and understanding Swarms.
- User-Friendly APIs: We'll design clean and self-explanatory APIs that help developers to understand their purpose quickly.
- Prompt and Effective Support: We will ensure that support is readily available to assist users when they encounter problems or need help with Swarms.
## Reliable
### Objective
Swarms should be dependable and trustworthy. Users should be able to count on Swarms to perform consistently and without error or failure.
### Tactics
- Robust Error Handling: We will focus on error prevention, detection, and recovery to minimize failures in Swarms.
- Comprehensive Testing: We will apply various testing methodologies such as unit testing, integration testing, and stress testing to validate the reliability of our software.
- Continuous Integration/Continuous Delivery (CI/CD): We will use CI/CD pipelines to ensure that all changes are tested and validated before they're merged into the main branch.
## Fast
### Objective
Swarms should offer high performance and rapid response times. The system should be able to handle requests and tasks swiftly.
### Tactics
- Efficient Algorithms: We will focus on optimizing our algorithms and data structures to ensure they run as quickly as possible.
- Caching: Where appropriate, we will use caching techniques to speed up response times.
- Profiling and Performance Monitoring: We will regularly analyze the performance of Swarms to identify bottlenecks and opportunities for improvement.
## Scalable
### Objective
Swarms should be able to grow in capacity and complexity without compromising performance or reliability. It should be able to handle increased workloads gracefully.
### Tactics
- Modular Architecture: We will design Swarms using a modular architecture that allows for easy scaling and modification.
- Load Balancing: We will distribute tasks evenly across available resources to prevent overload and maximize throughput.
- Horizontal and Vertical Scaling: We will design Swarms to be capable of both horizontal (adding more machines) and vertical (adding more power to an existing machine) scaling.
### Philosophy
Swarms is designed with a philosophy of simplicity and reliability. We believe that software should be a tool that empowers users, not a hurdle that they need to overcome. Therefore, our focus is on usability, reliability, speed, and scalability. We want our users to find Swarms intuitive and dependable, fast and adaptable to their needs. This philosophy guides all of our design and development decisions.

@ -1,225 +0,0 @@
# The Golden Metric: 95% User-Task-Completion-Satisfaction Rate
In the world of Swarms, theres one metric that stands above the rest: the User-Task-Completion-Satisfaction (UTCS) rate. This metric is the heart of our system, the pulse that keeps us moving forward. Its not just a number; its a reflection of our commitment to our users and a measure of our success.
## What is the UTCS Rate?
The UTCS rate is a measure of how reliably and quickly Swarms can satisfy a user demand. Its calculated by dividing the number of tasks completed to the users satisfaction by the total number of tasks. Multiply that by 100, and youve got your UTCS rate.
But what does it mean to complete a task to the users satisfaction? It means that the task is not only completed, but completed in a way that meets or exceeds the users expectations. Its about quality, speed, and reliability.
## Why is the UTCS Rate Important?
The UTCS rate is a direct reflection of the user experience. A high UTCS rate means that users are getting what they need from Swarms, and theyre getting it quickly and reliably. It means that Swarms is doing its job, and doing it well.
But the UTCS rate is not just about user satisfaction. Its also a measure of Swarms efficiency and effectiveness. A high UTCS rate means that Swarms is able to complete tasks quickly and accurately, with minimal errors or delays. Its a sign of a well-oiled machine.
## How Do We Achieve a 95% UTCS Rate?
Achieving a 95% UTCS rate is no small feat. It requires a deep understanding of our users and their needs, a robust and reliable system, and a commitment to continuous improvement.
### Here are some strategies were implementing to reach our goal:
* Understanding User Needs: We must have agents that gain an understanding of the user's objective and break it up into it's most fundamental building blocks
* Improving System Reliability: Were working to make Swarms more reliable, reducing errors and improving the accuracy of task completion. This includes improving our algorithms, refining our processes, and investing in quality assurance.
* Optimizing for Speed: Were optimizing Swarms to complete tasks as quickly as possible, without sacrificing quality. This includes improving our infrastructure, streamlining our workflows, and implementing performance optimizations.
*Iterating and Improving: Were committed to continuous improvement. Were constantly monitoring our UTCS rate and other key metrics, and were always looking for ways to improve. Were not afraid to experiment, iterate, and learn from our mistakes.
Achieving a 95% UTCS rate is a challenging goal, but its a goal worth striving for. Its a goal that will drive us to improve, innovate, and deliver the best possible experience for our users. And in the end, thats what Swarms is all about.
# Your Feedback Matters: Help Us Optimize the UTCS Rate
As we initiate the journey of Swarms, we seek your feedback to better guide our growth and development. Your opinions and suggestions are crucial for us, helping to mold our product, pricing, branding, and a host of other facets that influence your experience.
## Your Insights on the UTCS Rate
Our goal is to maintain a UTCS (User-Task-Completion-Satisfaction) rate of 95%. This metric is integral to the success of Swarms, indicating the efficiency and effectiveness with which we satisfy user requests. However, it's a metric that we can't optimize alone - we need your help.
Here's what we want to understand from you:
1. **Satisfaction:** What does a "satisfactorily completed task" mean to you? Are there specific elements that contribute to a task being carried out to your satisfaction?
2. **Timeliness:** How important is speed in the completion of a task? What would you consider a reasonable timeframe for a task to be completed?
3. **Usability:** How intuitive and user-friendly do you find the Swarms platform? Are there any aspects of the platform that you believe could be enhanced?
4. **Reliability:** How much does consistency in performance matter to you? Can you share any experiences where Swarms either met or fell short of your expectations?
5. **Value for Money:** How do you perceive our pricing? Does the value Swarms provides align with the costs?
We invite you to share your experiences, thoughts, and ideas. Whether it's a simple suggestion or an in-depth critique, we appreciate and value your input.
## Your Feedback: The Backbone of our Growth
Your feedback is the backbone of Swarms' evolution. It drives us to refine our strategies, fuels our innovative spirit, and, most importantly, enables us to serve you better.
As we launch, we open the conversation around these key aspects of Swarms, and we look forward to understanding your expectations, your needs, and how we can deliver the best experience for you.
So, let's start this conversation - how can we make Swarms work best for you?
Guide Our Growth: Help Optimize Swarms
As we launch Swarms, your feedback is critical for enhancing our product, pricing, and branding. A key aim for us is a User-Task-Completion-Satisfaction (UTCS) rate of 95% - indicating our efficiency and effectiveness in meeting user needs. However, we need your insights to optimize this.
Here's what we're keen to understand:
Satisfaction: Your interpretation of a "satisfactorily completed task".
Timeliness: The importance of speed in task completion for you.
Usability: Your experiences with our platforms intuitiveness and user-friendliness.
Reliability: The significance of consistent performance to you.
Value for Money: Your thoughts on our pricing and value proposition.
We welcome your thoughts, experiences, and suggestions. Your feedback fuels our evolution, driving us to refine strategies, boost innovation, and enhance your experience.
Let's start the conversation - how can we make Swarms work best for you?
--------
**The Golden Metric Analysis: The Ultimate UTCS Paradigm for Swarms**
### Introduction
In our ongoing journey to perfect Swarms, understanding how our product fares in the eyes of the end-users is paramount. Enter the User-Task-Completion-Satisfaction (UTCS) rate - our primary metric that gauges how reliably and swiftly Swarms can meet user demands. As we steer Swarms towards achieving a UTCS rate of 95%, understanding this metric's core and how to refine it becomes vital.
### Decoding UTCS: An Analytical Overview
The UTCS rate is not merely about task completion; it's about the comprehensive experience. Therefore, its foundations lie in:
1. **Quality**: Ensuring tasks are executed flawlessly.
2. **Speed**: Delivering results in the shortest possible time.
3. **Reliability**: Consistency in quality and speed across all tasks.
We can represent the UTCS rate with the following equation:
```latex
\[ UTCS Rate = \frac{(Completed Tasks \times User Satisfaction)}{(Total Tasks)} \times 100 \]
```
Where:
- Completed Tasks refer to the number of tasks Swarms executes without errors.
- User Satisfaction is the subjective component, gauged through feedback mechanisms. This could be on a scale of 1-10 (or a percentage).
- Total Tasks refer to all tasks processed by Swarms, regardless of the outcome.
### The Golden Metric: Swarm Efficiency Index (SEI)
However, this basic representation doesn't factor in a critical component: system performance. Thus, we introduce the Swarm Efficiency Index (SEI). The SEI encapsulates not just the UTCS rate but also system metrics like memory consumption, number of tasks, and time taken. By blending these elements, we aim to present a comprehensive view of Swarm's prowess.
Heres the formula:
```latex
\[ SEI = \frac{UTCS Rate}{(Memory Consumption + Time Window + Task Complexity)} \]
```
Where:
- Memory Consumption signifies the system resources used to accomplish tasks.
- Time Window is the timeframe in which the tasks were executed.
- Task Complexity could be a normalized scale that defines how intricate a task is (e.g., 1-5, with 5 being the most complex).
Rationale:
- **Incorporating Memory Consumption**: A system that uses less memory but delivers results is more efficient. By inverting memory consumption in the formula, we emphasize that as memory usage goes down, SEI goes up.
- **Considering Time**: Time is of the essence. The faster the results without compromising quality, the better. By adding the Time Window, we emphasize that reduced task execution time increases the SEI.
- **Factoring in Task Complexity**: Not all tasks are equal. A system that effortlessly completes intricate tasks is more valuable. By integrating task complexity, we can normalize the SEI according to the task's nature.
### Implementing SEI & Improving UTCS
Using feedback from elder-plinius, we can better understand and improve SEI and UTCS:
1. **Feedback Across Skill Levels**: By gathering feedback from users with different skill levels, we can refine our metrics, ensuring Swarms caters to all.
2. **Simplifying Setup**: Detailed guides can help newcomers swiftly get on board, thus enhancing user satisfaction.
3. **Enhancing Workspace and Agent Management**: A clearer view of the Swarm's internal structure, combined with on-the-go adjustments, can improve both the speed and quality of results.
4. **Introducing System Suggestions**: A proactive Swarms that provides real-time insights and recommendations can drastically enhance user satisfaction, thus pushing up the UTCS rate.
### Conclusion
The UTCS rate is undeniably a pivotal metric for Swarms. However, with the introduction of the Swarm Efficiency Index (SEI), we have an opportunity to encapsulate a broader spectrum of performance indicators, leading to a more holistic understanding of Swarms' efficiency. By consistently optimizing for SEI, we can ensure that Swarms not only meets user expectations but also operates at peak system efficiency.
----------------
**Research Analysis: Tracking and Ensuring Reliability of Swarm Metrics at Scale**
### 1. Introduction
In our pursuit to optimize the User-Task-Completion-Satisfaction (UTCS) rate and Swarm Efficiency Index (SEI), reliable tracking of these metrics at scale becomes paramount. This research analysis delves into methodologies, technologies, and practices that can be employed to monitor these metrics accurately and efficiently across vast data sets.
### 2. Why Tracking at Scale is Challenging
The primary challenges include:
- **Volume of Data**: As Swarms grows, the data generated multiplies exponentially.
- **Variability of Data**: Diverse user inputs lead to myriad output scenarios.
- **System Heterogeneity**: Different configurations and deployments can yield variable results.
### 3. Strategies for Scalable Tracking
#### 3.1. Distributed Monitoring Systems
**Recommendation**: Implement distributed systems like Prometheus or InfluxDB.
**Rationale**:
- Ability to collect metrics from various Swarm instances concurrently.
- Scalable and can handle vast data influxes.
#### 3.2. Real-time Data Processing
**Recommendation**: Use stream processing systems like Apache Kafka or Apache Flink.
**Rationale**:
- Enables real-time metric calculation.
- Can handle high throughput and low-latency requirements.
#### 3.3. Data Sampling
**Recommendation**: Random or stratified sampling of user sessions.
**Rationale**:
- Reduces the data volume to be processed.
- Maintains representativeness of overall user experience.
### 4. Ensuring Reliability in Data Collection
#### 4.1. Redundancy
**Recommendation**: Integrate redundancy into data collection nodes.
**Rationale**:
- Ensures no single point of failure.
- Data loss prevention in case of system malfunctions.
#### 4.2. Anomaly Detection
**Recommendation**: Implement AI-driven anomaly detection systems.
**Rationale**:
- Identifies outliers or aberrations in metric calculations.
- Ensures consistent and reliable data interpretation.
#### 4.3. Data Validation
**Recommendation**: Establish automated validation checks.
**Rationale**:
- Ensures only accurate and relevant data is considered.
- Eliminates inconsistencies arising from corrupted or irrelevant data.
### 5. Feedback Loops and Continuous Refinement
#### 5.1. User Feedback Integration
**Recommendation**: Develop an in-built user feedback mechanism.
**Rationale**:
- Helps validate the perceived vs. actual performance.
- Allows for continuous refining of tracking metrics and methodologies.
#### 5.2. A/B Testing
**Recommendation**: Regularly conduct A/B tests for new tracking methods or adjustments.
**Rationale**:
- Determines the most effective methods for data collection.
- Validates new tracking techniques against established ones.
### 6. Conclusion
To successfully and reliably track the UTCS rate and SEI at scale, it's essential to combine robust monitoring tools, data processing methodologies, and validation techniques. By doing so, Swarms can ensure that the metrics collected offer a genuine reflection of system performance and user satisfaction. Regular feedback and iterative refinement, rooted in a culture of continuous improvement, will further enhance the accuracy and reliability of these essential metrics.

@ -1,19 +0,0 @@
from swarms import Model, Agent, vectorstore, tools, orchestrator
# 1 model
Model(openai)
# 2 agent level
Agent(model, vectorstore, tools)
# 3 worker infrastructure level
worker_node(Agent, human_input, tools)
# 4 swarm level basically handling infrastructure for multiple worker node
swarm = orchestrator(worker_node, 100) # nodes
# 5
hivemind = Hivemind(swarm * 100)
# a market different pre built worker or boss agent that have access to different tools and memory, proompts

@ -1,22 +0,0 @@
Sure, here are some creative neo-futuristic names for your swarm worker agents:
QuantumPulse
UltraNode
FusionCortex
HyperionCrawler
XenoSync
HoloWorker
EtherEngine
NebulaNexus
OmegaOrbit
ZetaZenith
PhantomPivot
VortexVector
ChronoCluster
SpecterSphere
TitanTrace
EchoEntity
NovaNucleus
AstroAssembler
PulsarProcessor
CosmicCrafter

@ -1,69 +0,0 @@
Guide to Product-Market Fit for HiveMind Class
Risks and Mitigations
Scalability: As the number of swarms increases, the computational resources required will also increase. This could lead to performance issues or high costs.
Mitigation: Implement efficient resource management and load balancing. Consider using cloud-based solutions that can scale up or down based on demand.
Concurrency Issues: With multiple swarms running concurrently, there could be issues with data consistency and synchronization.
Mitigation: Implement robust concurrency control mechanisms. Ensure that the shared vector store is thread-safe.
Error Propagation: Errors in one swarm could potentially affect other swarms or the entire HiveMind.
Mitigation: Implement robust error handling and isolation mechanisms. Errors in one swarm should not affect the operation of other swarms.
Complexity: The HiveMind class is complex and could be difficult to maintain and extend.
Mitigation: Follow best practices for software design, such as modularity, encapsulation, and separation of concerns. Write comprehensive tests to catch issues early.
User Experience: If the HiveMind class is not easy to use, it could deter potential users.
Mitigation: Provide clear documentation and examples. Implement a user-friendly API. Consider providing a high-level interface that abstracts away some of the complexity.
Mental Models and Design Paradigms
Modularity: Each swarm should be a self-contained unit that can operate independently. This makes the system more flexible and easier to maintain.
Concurrency: The system should be designed to handle multiple swarms running concurrently. This requires careful consideration of issues such as data consistency and synchronization.
Fault Tolerance: The system should be able to handle errors gracefully. If one swarm encounters an error, it should not affect the operation of other swarms.
Scalability: The system should be able to handle an increasing number of swarms without a significant degradation in performance.
User-Centric Design: The system should be designed with the user in mind. It should be easy to use and provide value to the user.
Path to Product-Market Fit
Identify Target Users: Determine who would benefit most from using the HiveMind class. This could be developers, data scientists, researchers, or businesses.
Understand User Needs: Conduct user research to understand the problems that users are trying to solve and how the HiveMind class can help.
Develop MVP: Develop a minimum viable product (MVP) that demonstrates the value of the HiveMind class. This should be a simple version of the product that solves a core user problem.
Gather Feedback: After releasing the MVP, gather feedback from users. This could be through surveys, interviews, or user testing.
Iterate and Improve: Use the feedback to iterate and improve the product. This could involve fixing bugs, adding new features, or improving usability.
Scale: Once the product has achieved product-market fit, focus on scaling. This could involve optimizing the product for performance, expanding to new markets, or developing partnerships.
Here are some features that could be added to the HiveMind class to provide maximum value for users:
Dynamic Scaling: The ability to automatically scale the number of swarms based on the complexity of the task or the load on the system. This would allow the system to handle a wide range of tasks efficiently.
Task Prioritization: The ability to prioritize tasks based on their importance or urgency. This would allow more important tasks to be completed first.
Progress Monitoring: The ability for users to monitor the progress of their tasks. This could include a progress bar, estimated completion time, or real-time updates.
Error Reporting: Detailed error reports that help users understand what went wrong if a task fails. This could include the error message, the swarm that encountered the error, and suggestions for how to fix the error.
Task Cancellation: The ability for users to cancel a task that is currently being processed. This could be useful if a user realizes they made a mistake or if a task is taking too long to complete.
Task Queuing: The ability for users to queue up multiple tasks. This would allow users to submit a batch of tasks and have them processed one after the other.
Result Formatting: The ability for users to specify how they want the results to be formatted. This could include options for plain text, JSON, XML, or other formats.
Integration with Other Services: The ability to integrate with other services, such as databases, cloud storage, or machine learning platforms. This would allow users to easily store results, access additional resources, or leverage advanced features.
Security Features: Features to ensure the security and privacy of user data, such as encryption, access controls, and audit logs.
User-Friendly API: A well-designed, user-friendly API that makes it easy for users to use the HiveMind class in their own applications. This could include clear documentation, examples, and error messages.

@ -1,401 +0,0 @@
## Swarming Architectures
Here are three examples of swarming architectures that could be applied in this context.
1. **Hierarchical Swarms**: In this architecture, a 'lead' agent coordinates the efforts of other agents, distributing tasks based on each agent's unique strengths. The lead agent might be equipped with additional functionality or decision-making capabilities to effectively manage the swarm.
2. **Collaborative Swarms**: Here, each agent in the swarm works in parallel, potentially on different aspects of a task. They then collectively determine the best output, often through a voting or consensus mechanism.
3. **Competitive Swarms**: In this setup, multiple agents work on the same task independently. The output from the agent which produces the highest confidence or quality result is then selected. This can often lead to more robust outputs, as the competition drives each agent to perform at its best.
4. **Multi-Agent Debate**: Here, multiple agents debate a topic. The output from the agent which produces the highest confidence or quality result is then selected. This can lead to more robust outputs, as the competition drives each agent to perform it's best.
# Ideas
A swarm, particularly in the context of distributed computing, refers to a large number of coordinated agents or nodes that work together to solve a problem. The specific requirements of a swarm might vary depending on the task at hand, but some of the general requirements include:
1. **Distributed Nature**: The swarm should consist of multiple individual units or nodes, each capable of functioning independently.
2. **Coordination**: The nodes in the swarm need to coordinate with each other to ensure they're working together effectively. This might involve communication between nodes, or it could be achieved through a central orchestrator.
3. **Scalability**: A well-designed swarm system should be able to scale up or down as needed, adding or removing nodes based on the task load.
4. **Resilience**: If a node in the swarm fails, it shouldn't bring down the entire system. Instead, other nodes should be able to pick up the slack.
5. **Load Balancing**: Tasks should be distributed evenly across the nodes in the swarm to avoid overloading any single node.
6. **Interoperability**: Each node should be able to interact with others, regardless of differences in underlying hardware or software.
Integrating these requirements with Large Language Models (LLMs) can be done as follows:
1. **Distributed Nature**: Each LLM agent can be considered as a node in the swarm. These agents can be distributed across multiple servers or even geographically dispersed data centers.
2. **Coordination**: An orchestrator can manage the LLM agents, assigning tasks, coordinating responses, and ensuring effective collaboration between agents.
3. **Scalability**: As the demand for processing power increases or decreases, the number of LLM agents can be adjusted accordingly.
4. **Resilience**: If an LLM agent goes offline or fails, the orchestrator can assign its tasks to other agents, ensuring the swarm continues functioning smoothly.
5. **Load Balancing**: The orchestrator can also handle load balancing, ensuring tasks are evenly distributed amongst the LLM agents.
6. **Interoperability**: By standardizing the input and output formats of the LLM agents, they can effectively communicate and collaborate, regardless of the specific model or configuration of each agent.
In terms of architecture, the swarm might look something like this:
```
(Orchestrator)
/ \
Tools + Vector DB -- (LLM Agent)---(Communication Layer) (Communication Layer)---(LLM Agent)-- Tools + Vector DB
/ | | \
(Task Assignment) (Task Completion) (Task Assignment) (Task Completion)
```
Each LLM agent communicates with the orchestrator through a dedicated communication layer. The orchestrator assigns tasks to each LLM agent, which the agents then complete and return. This setup allows for a high degree of flexibility, scalability, and robustness.
## Communication Layer
Communication layers play a critical role in distributed systems, enabling interaction between different nodes (agents) and the orchestrator. Here are three potential communication layers for a distributed system, including their strengths and weaknesses:
1. **Message Queuing Systems (like RabbitMQ, Kafka)**:
- Strengths: They are highly scalable, reliable, and designed for high-throughput systems. They also ensure delivery of messages and can persist them if necessary. Furthermore, they support various messaging patterns like publish/subscribe, which can be highly beneficial in a distributed system. They also have robust community support.
- Weaknesses: They can add complexity to the system, including maintenance of the message broker. Moreover, they require careful configuration to perform optimally, and handling failures can sometimes be challenging.
2. **RESTful APIs**:
- Strengths: REST is widely adopted, and most programming languages have libraries to easily create RESTful APIs. They leverage standard HTTP(S) protocols and methods and are straightforward to use. Also, they can be stateless, meaning each request contains all the necessary information, enabling scalability.
- Weaknesses: For real-time applications, REST may not be the best fit due to its synchronous nature. Additionally, handling a large number of API requests can put a strain on the system, causing slowdowns or timeouts.
3. **gRPC (Google Remote Procedure Call)**:
- Strengths: gRPC uses Protocol Buffers as its interface definition language, leading to smaller payloads and faster serialization/deserialization compared to JSON (commonly used in RESTful APIs). It supports bidirectional streaming and can use HTTP/2 features, making it excellent for real-time applications.
- Weaknesses: gRPC is more complex to set up compared to REST. Protocol Buffers' binary format can be more challenging to debug than JSON. It's also not as widely adopted as REST, so tooling and support might be limited in some environments.
In the context of swarm LLMs, one could consider an **Omni-Vector Embedding Database** for communication. This database could store and manage the high-dimensional vectors produced by each LLM agent.
- Strengths: This approach would allow for similarity-based lookup and matching of LLM-generated vectors, which can be particularly useful for tasks that involve finding similar outputs or recognizing patterns.
- Weaknesses: An Omni-Vector Embedding Database might add complexity to the system in terms of setup and maintenance. It might also require significant computational resources, depending on the volume of data being handled and the complexity of the vectors. The handling and transmission of high-dimensional vectors could also pose challenges in terms of network load.
# Technical Analysis Document: Particle Swarm of AI Agents using Ocean Database
## Overview
The goal is to create a particle swarm of AI agents using the OpenAI API for the agents and the Ocean database as the communication space, where the embeddings act as particles. The swarm will work collectively to perform tasks and optimize their behavior based on the interaction with the Ocean database.
## Algorithmic Overview
1. Initialize the AI agents and the Ocean database.
2. Assign tasks to the AI agents.
3. AI agents use the OpenAI API to perform tasks and generate embeddings.
4. AI agents store their embeddings in the Ocean database.
5. AI agents query the Ocean database for relevant embeddings.
6. AI agents update their positions based on the retrieved embeddings.
7. Evaluate the performance of the swarm and update the agents' behavior accordingly.
8. Repeat steps 3-7 until a stopping criterion is met.
## Python Implementation Logic
1. **Initialize the AI agents and the Ocean database.**
```python
import openai
import oceandb
from oceandb.utils.embedding_functions import ImageBindEmbeddingFunction
# Initialize Ocean database
client = oceandb.Client()
text_embedding_function = ImageBindEmbeddingFunction(modality="text")
collection = client.create_collection("all-my-documents", embedding_function=text_embedding_function)
# Initialize AI agents
agents = initialize_agents(...)
```
2. **Assign tasks to the AI agents.**
```python
tasks = assign_tasks_to_agents(agents, ...)
```
3. **AI agents use the OpenAI API to perform tasks and generate embeddings.**
```python
def agent_perform_task(agent, task):
# Perform the task using the OpenAI API
result = perform_task_with_openai_api(agent, task)
# Generate the embedding
embedding = generate_embedding(result)
return embedding
embeddings = [agent_perform_task(agent, task) for agent, task in zip(agents, tasks)]
```
4. **AI agents store their embeddings in the Ocean database.**
```python
def store_embeddings_in_database(embeddings, collection):
for i, embedding in enumerate(embeddings):
document_id = f"agent_{i}"
collection.add(documents=[embedding], ids=[document_id])
store_embeddings_in_database(embeddings, collection)
```
5. **AI agents query the Ocean database for relevant embeddings.**
```python
def query_database_for_embeddings(agent, collection, n_results=1):
query_result = collection.query(query_texts=[agent], n_results=n_results)
return query_result
queried_embeddings = [query_database_for_embeddings(agent, collection) for agent in agents]
```
6. **AI agents update their positions based on the retrieved embeddings.**
```python
def update_agent_positions(agents, queried_embeddings):
for agent, embedding in zip(agents, queried_embeddings):
agent.update_position(embedding)
update_agent_positions(agents, queried_embeddings)
```
7. **Evaluate the performance of the swarm and update the agents' behavior accordingly.**
```python
def evaluate_swarm_performance(agents, ...):
# Evaluate the performance of the swarm
performance = compute_performance_metric(agents, ...)
return performance
def update_agent_behavior(agents, performance):
# Update agents' behavior based on swarm performance
for agent in agents:
agent.adjust_behavior(performance)
performance = evaluate_swarm_performance(agents, ...)
update_agent_behavior(agents, performance)
```
8. **Repeat steps 3-7 until a stopping criterion is met.**
```python
while not stopping_criterion_met():
# Perform tasks and generate embeddings
embeddings = [agent_perform_task(agent, task) for agent, task in zip(agents, tasks)]
# Store embeddings in the Ocean database
store_embeddings_in_database(embeddings, collection)
# Query the Ocean database for relevant embeddings
queried_embeddings = [query_database_for_embeddings(agent, collection) for agent in agents]
# Update AI agent positions based on the retrieved embeddings
update_agent_positions(agents, queried_embeddings)
# Evaluate the performance of the swarm and update the agents' behavior accordingly
performance = evaluate_swarm_performance(agents, ...)
update_agent_behavior(agents, performance)
```
This code demonstrates the complete loop to repeat steps 3-7 until a stopping criterion is met. You will need to define the `stopping_criterion_met()` function, which could be based on a predefined number of iterations, a target performance level, or any other condition that indicates that the swarm has reached a desired state.
* Integrate petals to handle huggingface LLM
# Orchestrator
* Takes in an agent class with vector store, then handles all the communication and scales up a swarm with number of agents and handles task assignment and task completion
```python
from swarms import OpenAI, Orchestrator, Swarm
orchestrated = Orchestrate(OpenAI, nodes=40) #handles all the task assignment and allocation and agent communication using a vectorstore as a universal communication layer and also handlles the task completion logic
Objective = "Make a business website for a marketing consultancy"
Swarms = (Swarms(orchestrated, auto=True, Objective))
```
In terms of architecture, the swarm might look something like this:
```
(Orchestrator)
/ \
Tools + Vector DB -- (LLM Agent)---(Communication Layer) (Communication Layer)---(LLM Agent)-- Tools + Vector DB
/ | | \
(Task Assignment) (Task Completion) (Task Assignment) (Task Completion)
```
Each LLM agent communicates with the orchestrator through a dedicated communication layer. The orchestrator assigns tasks to each LLM agent, which the agents then complete and return. This setup allows for a high degree of flexibility, scalability, and robustness.
In the context of swarm LLMs, one could consider an **Omni-Vector Embedding Database** for communication. This database could store and manage the high-dimensional vectors produced by each LLM agent.
- Strengths: This approach would allow for similarity-based lookup and matching of LLM-generated vectors, which can be particularly useful for tasks that involve finding similar outputs or recognizing patterns.
- Weaknesses: An Omni-Vector Embedding Database might add complexity to the system in terms of setup and maintenance. It might also require significant computational resources, depending on the volume of data being handled and the complexity of the vectors. The handling and transmission of high-dimensional vectors could also pose challenges in terms of network load.
* Handling absurdly long sequences => first transform the objective if it's more than 1000tokens into a txt file similiar to how Claude works => then chunk it into sizes of 8000 seq length embeddings => then embed it and store in the vector database => then connext the agent model to it
Given the complexity of the topic, please note that these simplified markdown documents are quite abstract and high level. They can be used as a starting point for further detailed design and implementation:
### Document 1: Hierarchical Swarms
#### Overall Architecture
1. Leader Agent (LA): This agent has the authority to manage and distribute tasks to the Worker Agents (WA).
2. Worker Agents (WAs): These agents perform the tasks assigned by the LA.
#### Simplified Requirements
1. LA should be able to distribute tasks to WAs.
2. WAs should be able to execute tasks and return results to LA.
3. LA should be able to consolidate and process results.
#### Pseudocode
```
create LA
create WAs
for each task in tasks:
LA.distribute_task(WAs, task)
for each WA in WAs:
WA.execute_task()
LA.collect_results(WAs)
LA.process_results()
```
#### General Classes
```python
class LeaderAgent:
def distribute_task(self, WAs, task):
pass
def collect_results(self, WAs):
pass
def process_results(self):
pass
class WorkerAgent:
def execute_task(self):
pass
```
### Document 2: Collaborative Swarms
#### Overall Architecture
1. Collaborative Agents (CAs): These agents work in parallel on different aspects of a task and then collectively determine the best output.
#### Simplified Requirements
1. CAs should be able to work on tasks in parallel.
2. CAs should be able to collaborate to determine the best result.
#### Pseudocode
```
create CAs
for each task in tasks:
for each CA in CAs:
CA.execute_task(task)
CA.collaborate()
```
#### General Classes
```python
class CollaborativeAgent:
def execute_task(self, task):
pass
def collaborate(self):
pass
```
### Document 3: Competitive Swarms
#### Overall Architecture
1. Competitive Agents (CompAs): These agents work independently on the same tasks, and the best result is selected.
#### Simplified Requirements
1. CompAs should be able to work independently on tasks.
2. An evaluation method should be used to select the best result.
#### Pseudocode
```
create CompAs
for each task in tasks:
for each CompA in CompAs:
CompA.execute_task(task)
evaluate_results(CompAs)
```
#### General Classes
```python
class CompetitiveAgent:
def execute_task(self, task):
pass
def evaluate_results(CompAs):
pass
```
Note: In the real world, the complexity of the architecture and requirements will significantly exceed what is presented here. These examples provide a basic starting point but should be expanded upon based on the specifics of the task or problem you're trying to solve.
# Swarms
BabyAGI -> Autogpt's -> tools -> other agents
- Host it on server, on premise, private learning, no learning is translating out
- companies are sensitive with data, models are firewalled, need privacy, huggingface,
- Does not transmit information,
- see agent activity, task history,
- optimize which agents for each task
- Assist or provide feedback to management agent
- overview see the whole swarm, modify each agent, visualize the communication stream with blue,
- Work optimization routines
- output monitoring
- stop output, agent looping,
-quality assurance checker, adversarial agent
- see a holistic diagram of all agents, how are they being utilized, see number of iterations, query responses, balance loading,
- summary of tasks completed with critique, type of summary, ceo summary, manager summary
- outside of browser and accross whole operating system, switch apps, mac, linux, and windows
-what are the skillsets behind the dev team, can be modified by experts, ui agent, manager agent, personalize agents with prompt and tools, and orca like explain your solutions, critique them then return the final output

@ -1,11 +0,0 @@
* The Platform, where users can have a conversation with the domain
* An developer platform where people can build swarms through a UI in nodes, connect and play
* SIMS like UI, where you see every node accomplishing their tasks around the internet
* Swarms Discord BOT
* PAID API
* MARKETPLACE FOR PREBUILT SWARMS WITH SPECIFIC PROMPTS, MODELS, TOOLS, AND MEMORIES,

@ -1,42 +0,0 @@
Research Proposal: Creating a Swarm of LLM Agents for Operating Systems
Introduction
The goal of this research is to explore the feasibility and requirements of creating a swarm of Language Learning Model (LLM) agents that can autonomously operate the kernel of an operating system. This swarm of AI agents would be capable of performing tasks such as process scheduling, memory management, device management, and system calls, among others.
Objectives
To investigate the feasibility of using LLM agents to autonomously operate the kernel of an operating system.
To identify the requirements and challenges of implementing such a system.
To develop a prototype system as a proof of concept.
Methodology
Literature Review: Conduct a comprehensive review of existing research on AI in operating systems, swarm intelligence, and LLMs.
Feasibility Study: Analyze the capabilities of current LLMs and assess whether they can be adapted to operate an OS kernel.
Requirement Analysis: Identify the hardware, software, and data requirements for implementing a swarm of LLM agents in an OS.
System Design: Design a prototype system that uses LLM agents to perform basic kernel operations.
Implementation and Testing: Implement the prototype system and conduct rigorous testing to evaluate its performance.
Requirements
Hardware: A high-performance computing system would be required to handle the computational load of millions of LLM agents. This system would need to have a powerful CPU, a large amount of RAM, and possibly a GPU for machine learning tasks.
Software: The system would require an operating system that is compatible with the LLM agents. This could be a popular OS like Linux, which is open-source and widely used in AI research.
LLM Agents: The LLM agents would need to be trained to perform kernel operations. This would require a large dataset of kernel operations and their outcomes.
Swarm Intelligence Framework: A framework for swarm intelligence would be needed to manage the LLM agents and coordinate their activities.
Monitoring and Debugging Tools: Tools for monitoring the performance of the LLM agents and debugging any issues would be essential.
Potential Challenges
Complexity of Kernel Operations: Kernel operations are complex and low-level. Training LLM agents to perform these operations accurately and efficiently could be challenging.
Coordination of LLM Agents: Coordinating the activities of millions of LLM agents could be a complex task. The swarm intelligence framework would need to be robust and efficient.
Security: The system would need to be secure to prevent unauthorized access and ensure the integrity of the kernel operations.
Performance: The system would need to be able to handle a high load and perform operations quickly to avoid slowing down the OS.
Conclusion
Creating a swarm of LLM agents for operating systems is a challenging but potentially rewarding endeavor. This research aims to explore the feasibility of this idea and identify the requirements for its implementation. If successful, this could open up new possibilities for AI in operating systems and beyond.

@ -1,78 +0,0 @@
## **Product Feature Document: Multi-Agent Distributed Collaboration Framework**
---
**Introduction**:
In a world increasingly leaning towards automation, we present a framework to enable multi-agent distributed collaboration. This revolutionary approach, integrating millions of GPT-3 nodes, is set to redefine real-world task automation. This document outlines and prioritizes features based on their potential value to early adopters.
---
### **1. Learning Enhancements**
- **Private Learning**: Safeguard data and learn without transmitting sensitive information.
*Value Proposition*: Guarantees data security for enterprises dealing with sensitive information.
- **Task Decomposition**: Algorithms to efficiently break down complex tasks into simpler sub-tasks for agent distribution.
*Value Proposition*: Simplifies problem-solving and ensures efficient task distribution among agents.
---
### **2. Swarm Management & Performance**
- **Swarm Benchmarks**: Establish performance benchmarks for swarms, providing users with expected efficiency and accuracy metrics.
*Value Proposition*: Allows users to anticipate swarm performance and adjust strategies accordingly.
- **Swarm Classes & Modularity**: Create diverse classes of swarms based on task type, ensuring a high level of usability and flexibility.
*Value Proposition*: Customizable swarms tailored to specific problem sets, enhancing solution accuracy.
- **Dictator Swarm Mode**: Centralized control for swarms for tasks that require uniformity and synchronization.
*Value Proposition*: Streamlines processes where coordination is key.
---
### **3. Communication & Progress Tracking**
- **Progress Posting Tool**: Equip agents with a tool to post their progress to a swarm-wide vector store.
*Value Proposition*: Real-time tracking of task progress and agent efficiency.
- **Observer Agent**: A supervisory agent dedicated to preventing others from entering non-productive loops.
*Value Proposition*: Ensures optimal agent performance and minimizes wastage of computational resources.
---
### **4. Tool Integration & Modularity**
- **Easy Tool Integration**: Simplified interfaces to add or modify tools within the swarm.
*Value Proposition*: Augment swarm capabilities on-the-go, adapting to diverse tasks with ease.
- **Vector Database for Tools**: Maintain a comprehensive database of tools, allowing agents to query and utilize as needed.
*Value Proposition*: Provides agents with a vast arsenal of tools to tackle various challenges, enhancing problem-solving capacity.
---
### **5. Data Input & Multimodality**
- **Multimodal Data Intake**: Enable swarms to process varied data types text, images, sounds, and more.
*Value Proposition*: Broadens the range of tasks swarms can handle, from simple text-based queries to complex multimedia projects.
---
### **Feature Priority (for early adopters)**:
1. **Private Learning**: Data privacy remains paramount.
2. **Task Decomposition**: Efficient problem-solving is foundational.
3. **Swarm Benchmarks**: Understanding potential performance is essential for user trust.
4. **Progress Posting Tool**: Real-time updates increase confidence and allow for timely interventions.
5. **Multimodal Data Intake**: Increases the range and depth of tasks the framework can handle.
6. **Observer Agent**: Minimizing wastage is key to cost efficiency.
7. **Easy Tool Integration**: Enhancing adaptability for varied challenges.
8. **Swarm Classes & Modularity**: Customization ensures relevance to specific user needs.
9. **Dictator Swarm Mode**: Essential for tasks demanding synchronization.
10. **Vector Database for Tools**: Augments the swarms' problem-solving arsenal.
---
**Conclusion**:
With these prioritized features, our framework promises not only to revolutionize task automation but also to deliver unmatched value to its earliest users. This is the dawn of a new era in AI collaboration, and we invite you to be a part of this journey.
**Join the future of AI automation. Step into the swarm.**

@ -1,80 +0,0 @@
## **Product Feature Document: Multi-Agent Distributed Collaboration Framework**
---
**Introduction**:
In the modern age of AI, the potential of harnessing multiple intelligent agents to automate real-world tasks offers unprecedented value. We're building a framework that enables multi-agent distributed collaboration, akin to working with millions of GPT-3 nodes, and this document outlines the features which will bring tremendous value to early adopters.
---
**1. Data Security & Privacy**
- **On-Premise Hosting**: Users can deploy the framework on their server to ensure data doesn't leave their ecosystem.
- **Private Learning**: The agents can learn without transmitting sensitive data out.
- **Firewalled Models**: Ensures that all model data remains secured behind barriers, preventing unauthorized data access.
- **HuggingFace Integration**: For those comfortable with the HuggingFace ecosystem.
- **Transparency**: Ability to see agent activity, task history, which aids in accountability.
---
**2. Agent & Swarm Management**
- **Optimized Task Allocation**: System can decide which agents are best suited for each task, based on their learning and past performance.
- **Agent Feedback System**: Enables users to assist or provide feedback to the managing agent.
- **Holistic Swarm View**: Visualize the entire swarm, the communication streams, and individually modify agent behavior.
- **Work Optimization**: Routines to determine the most efficient distribution of tasks amongst agents.
- **Quality Assurance Agent**: A specialized agent to ensure the outputs meet the required standards.
---
**3. Output Management & Monitoring**
- **Stop Looping**: If an agent gets stuck in a task loop, the system can intervene.
- **Output Monitoring**: Real-time surveillance of what each agent produces.
- **Task Summaries**: An overview of tasks, tailored to different management levels (CEO summary, manager summary).
---
**4. Cross-Platform Integration**
- **OS Compatibility**: Seamlessly operate across Mac, Linux, and Windows.
- **Beyond Browser**: Ability to interact with different applications across the entire OS.
---
**5. Customization & Training**
- **Agent Personalization**: Tailor each agent's prompts, tools, and behavior to better fit specific tasks.
- **Training Agent for SMBs**: Simplified input prompting system to guide small-medium businesses.
- **Human Training Agent**: Uses visual aids, questions, and references to train human users. Incorporates meta prompting for dynamic environments.
---
**6. Installation & Deployment**
- **Easy Install Process**: Streamlined installation process, with real-time troubleshooting support.
- **Cloud Setup for Non-GPU**: For those without local GPU, a straightforward cloud setup guide.
---
**7. Advanced Agent Dynamics**
- **Non-Hierarchical Structure**: Worker agents autonomously pick tasks based on their strengths.
- **Knowledge Store**: A separate or integrated system where agents access and augment their knowledge.
- **API Integration**: Ability to easily integrate different APIs like LLM, GPT-4, and Anthropic.
---
**8. Memory & Knowledge Management**
- **Differentiated Memory**: Separate memory storage for individual agents and the entire swarm, aiding in more efficient task delegation and execution.
---
**Events and Workshops (for community involvement & onboarding)**
- **Monthly Webinars**: Dive deep into feature releases, use cases, and best practices.
- **Next Session**: August 25th, 2023 - "Harnessing the Power of Multi-Agent Systems"
- **Quarterly Workshops**: Hands-on sessions for businesses to understand how to best leverage the framework.
- **Upcoming Workshop**: September 15th-17th, 2023 - "Optimizing Agent Performance for Business Tasks"
- **Annual Swarm Conclave**: A grand gathering of all community members, developers, and businesses to discuss future roadmaps and celebrate successes.
- **Swarm Conclave 2023**: December 2nd-4th, 2023, San Francisco, CA.
---
**Conclusion**:
This framework is not merely a technological tool, but a step into the future of collaborative AI. By combining the strengths of multiple intelligent agents, we can redefine how businesses operate, innovate, and grow.
**Join the revolution. Become part of Agora.**
[**Discord Link**](https://discord.gg/qUtxnK2NMf)

@ -1,522 +0,0 @@
LLM Powered Autonomous Agents
=============================
June 23, 2023 · 31 min · Lilian Weng
Table of Contents
* [Agent System Overview](#agent-system-overview)
* [Component One: Planning](#component-one-planning)
* [Task Decomposition](#task-decomposition)
* [Self-Reflection](#self-reflection)
* [Component Two: Memory](#component-two-memory)
* [Types of Memory](#types-of-memory)
* [Maximum Inner Product Search (MIPS)](#maximum-inner-product-search-mips)
* [Component Three: Tool Use](#component-three-tool-use)
* [Case Studies](#case-studies)
* [Scientific Discovery Agent](#scientific-discovery-agent)
* [Generative Agents Simulation](#generative-agents-simulation)
* [Proof-of-Concept Examples](#proof-of-concept-examples)
* [Challenges](#challenges)
* [Citation](#citation)
* [References](#references)
Building agents with LLM (large language model) as its core controller is a cool concept. Several proof-of-concepts demos, such as [AutoGPT](https://github.com/Significant-Gravitas/Auto-GPT), [GPT-Engineer](https://github.com/AntonOsika/gpt-engineer) and [BabyAGI](https://github.com/yoheinakajima/babyagi), serve as inspiring examples. The potentiality of LLM extends beyond generating well-written copies, stories, essays and programs; it can be framed as a powerful general problem solver.
Agent System Overview[#](#agent-system-overview)
================================================
In a LLM-powered autonomous agent system, LLM functions as the agents brain, complemented by several key components:
* **Planning**
* Subgoal and decomposition: The agent breaks down large tasks into smaller, manageable subgoals, enabling efficient handling of complex tasks.
* Reflection and refinement: The agent can do self-criticism and self-reflection over past actions, learn from mistakes and refine them for future steps, thereby improving the quality of final results.
* **Memory**
* Short-term memory: I would consider all the in-context learning (See [Prompt Engineering](https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/)) as utilizing short-term memory of the model to learn.
* Long-term memory: This provides the agent with the capability to retain and recall (infinite) information over extended periods, often by leveraging an external vector store and fast retrieval.
* **Tool use**
* The agent learns to call external APIs for extra information that is missing from the model weights (often hard to change after pre-training), including current information, code execution capability, access to proprietary information sources and more.
![](agent-overview.png)
Fig. 1. Overview of a LLM-powered autonomous agent system.
Component One: Planning[#](#component-one-planning)
===================================================
A complicated task usually involves many steps. An agent needs to know what they are and plan ahead.
Task Decomposition[#](#task-decomposition)
------------------------------------------
[**Chain of thought**](https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/#chain-of-thought-cot) (CoT; [Wei et al. 2022](https://arxiv.org/abs/2201.11903)) has become a standard prompting technique for enhancing model performance on complex tasks. The model is instructed to “think step by step” to utilize more test-time computation to decompose hard tasks into smaller and simpler steps. CoT transforms big tasks into multiple manageable tasks and shed lights into an interpretation of the models thinking process.
**Tree of Thoughts** ([Yao et al. 2023](https://arxiv.org/abs/2305.10601)) extends CoT by exploring multiple reasoning possibilities at each step. It first decomposes the problem into multiple thought steps and generates multiple thoughts per step, creating a tree structure. The search process can be BFS (breadth-first search) or DFS (depth-first search) with each state evaluated by a classifier (via a prompt) or majority vote.
Task decomposition can be done (1) by LLM with simple prompting like `"Steps for XYZ.\n1."`, `"What are the subgoals for achieving XYZ?"`, (2) by using task-specific instructions; e.g. `"Write a story outline."` for writing a novel, or (3) with human inputs.
Another quite distinct approach, **LLM+P** ([Liu et al. 2023](https://arxiv.org/abs/2304.11477)), involves relying on an external classical planner to do long-horizon planning. This approach utilizes the Planning Domain Definition Language (PDDL) as an intermediate interface to describe the planning problem. In this process, LLM (1) translates the problem into “Problem PDDL”, then (2) requests a classical planner to generate a PDDL plan based on an existing “Domain PDDL”, and finally (3) translates the PDDL plan back into natural language. Essentially, the planning step is outsourced to an external tool, assuming the availability of domain-specific PDDL and a suitable planner which is common in certain robotic setups but not in many other domains.
Self-Reflection[#](#self-reflection)
------------------------------------
Self-reflection is a vital aspect that allows autonomous agents to improve iteratively by refining past action decisions and correcting previous mistakes. It plays a crucial role in real-world tasks where trial and error are inevitable.
**ReAct** ([Yao et al. 2023](https://arxiv.org/abs/2210.03629)) integrates reasoning and acting within LLM by extending the action space to be a combination of task-specific discrete actions and the language space. The former enables LLM to interact with the environment (e.g. use Wikipedia search API), while the latter prompting LLM to generate reasoning traces in natural language.
The ReAct prompt template incorporates explicit steps for LLM to think, roughly formatted as:
Thought: ...
Action: ...
Observation: ...
... (Repeated many times)
![](react.png)
Fig. 2. Examples of reasoning trajectories for knowledge-intensive tasks (e.g. HotpotQA, FEVER) and decision-making tasks (e.g. AlfWorld Env, WebShop). (Image source: [Yao et al. 2023](https://arxiv.org/abs/2210.03629)).
In both experiments on knowledge-intensive tasks and decision-making tasks, `ReAct` works better than the `Act`\-only baseline where `Thought: …` step is removed.
**Reflexion** ([Shinn & Labash 2023](https://arxiv.org/abs/2303.11366)) is a framework to equips agents with dynamic memory and self-reflection capabilities to improve reasoning skills. Reflexion has a standard RL setup, in which the reward model provides a simple binary reward and the action space follows the setup in ReAct where the task-specific action space is augmented with language to enable complex reasoning steps. After each action at, the agent computes a heuristic ht and optionally may _decide to reset_ the environment to start a new trial depending on the self-reflection results.
![](reflexion.png)
Fig. 3. Illustration of the Reflexion framework. (Image source: [Shinn & Labash, 2023](https://arxiv.org/abs/2303.11366))
The heuristic function determines when the trajectory is inefficient or contains hallucination and should be stopped. Inefficient planning refers to trajectories that take too long without success. Hallucination is defined as encountering a sequence of consecutive identical actions that lead to the same observation in the environment.
Self-reflection is created by showing two-shot examples to LLM and each example is a pair of (failed trajectory, ideal reflection for guiding future changes in the plan). Then reflections are added into the agents working memory, up to three, to be used as context for querying LLM.
![](reflexion-exp.png)
Fig. 4. Experiments on AlfWorld Env and HotpotQA. Hallucination is a more common failure than inefficient planning in AlfWorld. (Image source: [Shinn & Labash, 2023](https://arxiv.org/abs/2303.11366))
**Chain of Hindsight** (CoH; [Liu et al. 2023](https://arxiv.org/abs/2302.02676)) encourages the model to improve on its own outputs by explicitly presenting it with a sequence of past outputs, each annotated with feedback. Human feedback data is a collection of Dh\={(x,yi,ri,zi)}i\=1n, where x is the prompt, each yi is a model completion, ri is the human rating of yi, and zi is the corresponding human-provided hindsight feedback. Assume the feedback tuples are ranked by reward, rn≥rn1≥⋯≥r1 The process is supervised fine-tuning where the data is a sequence in the form of τh\=(x,zi,yi,zj,yj,…,zn,yn), where ≤i≤j≤n. The model is finetuned to only predict yn where conditioned on the sequence prefix, such that the model can self-reflect to produce better output based on the feedback sequence. The model can optionally receive multiple rounds of instructions with human annotators at test time.
To avoid overfitting, CoH adds a regularization term to maximize the log-likelihood of the pre-training dataset. To avoid shortcutting and copying (because there are many common words in feedback sequences), they randomly mask 0% - 5% of past tokens during training.
The training dataset in their experiments is a combination of [WebGPT comparisons](https://huggingface.co/datasets/openai/webgpt_comparisons), [summarization from human feedback](https://github.com/openai/summarize-from-feedback) and [human preference dataset](https://github.com/anthropics/hh-rlhf).
![](CoH.png)
Fig. 5. After fine-tuning with CoH, the model can follow instructions to produce outputs with incremental improvement in a sequence. (Image source: [Liu et al. 2023](https://arxiv.org/abs/2302.02676))
The idea of CoH is to present a history of sequentially improved outputs in context and train the model to take on the trend to produce better outputs. **Algorithm Distillation** (AD; [Laskin et al. 2023](https://arxiv.org/abs/2210.14215)) applies the same idea to cross-episode trajectories in reinforcement learning tasks, where an _algorithm_ is encapsulated in a long history-conditioned policy. Considering that an agent interacts with the environment many times and in each episode the agent gets a little better, AD concatenates this learning history and feeds that into the model. Hence we should expect the next predicted action to lead to better performance than previous trials. The goal is to learn the process of RL instead of training a task-specific policy itself.
![](algorithm-distillation.png)
Fig. 6. Illustration of how Algorithm Distillation (AD) works.
(Image source: [Laskin et al. 2023](https://arxiv.org/abs/2210.14215)).
The paper hypothesizes that any algorithm that generates a set of learning histories can be distilled into a neural network by performing behavioral cloning over actions. The history data is generated by a set of source policies, each trained for a specific task. At the training stage, during each RL run, a random task is sampled and a subsequence of multi-episode history is used for training, such that the learned policy is task-agnostic.
In reality, the model has limited context window length, so episodes should be short enough to construct multi-episode history. Multi-episodic contexts of 2-4 episodes are necessary to learn a near-optimal in-context RL algorithm. The emergence of in-context RL requires long enough context.
In comparison with three baselines, including ED (expert distillation, behavior cloning with expert trajectories instead of learning history), source policy (used for generating trajectories for distillation by [UCB](https://lilianweng.github.io/posts/2018-01-23-multi-armed-bandit/#upper-confidence-bounds)), RL^2 ([Duan et al. 2017](https://arxiv.org/abs/1611.02779); used as upper bound since it needs online RL), AD demonstrates in-context RL with performance getting close to RL^2 despite only using offline RL and learns much faster than other baselines. When conditioned on partial training history of the source policy, AD also improves much faster than ED baseline.
![](algorithm-distillation-results.png)
Fig. 7. Comparison of AD, ED, source policy and RL^2 on environments that require memory and exploration. Only binary reward is assigned. The source policies are trained with [A3C](https://lilianweng.github.io/posts/2018-04-08-policy-gradient/#a3c) for "dark" environments and [DQN](http://lilianweng.github.io/posts/2018-02-19-rl-overview/#deep-q-network) for watermaze.
(Image source: [Laskin et al. 2023](https://arxiv.org/abs/2210.14215))
Component Two: Memory[#](#component-two-memory)
===============================================
(Big thank you to ChatGPT for helping me draft this section. Ive learned a lot about the human brain and data structure for fast MIPS in my [conversations](https://chat.openai.com/share/46ff149e-a4c7-4dd7-a800-fc4a642ea389) with ChatGPT.)
Types of Memory[#](#types-of-memory)
------------------------------------
Memory can be defined as the processes used to acquire, store, retain, and later retrieve information. There are several types of memory in human brains.
1. **Sensory Memory**: This is the earliest stage of memory, providing the ability to retain impressions of sensory information (visual, auditory, etc) after the original stimuli have ended. Sensory memory typically only lasts for up to a few seconds. Subcategories include iconic memory (visual), echoic memory (auditory), and haptic memory (touch).
2. **Short-Term Memory** (STM) or **Working Memory**: It stores information that we are currently aware of and needed to carry out complex cognitive tasks such as learning and reasoning. Short-term memory is believed to have the capacity of about 7 items ([Miller 1956](psychclassics.yorku.ca/Miller/)) and lasts for 20-30 seconds.
3. **Long-Term Memory** (LTM): Long-term memory can store information for a remarkably long time, ranging from a few days to decades, with an essentially unlimited storage capacity. There are two subtypes of LTM:
* Explicit / declarative memory: This is memory of facts and events, and refers to those memories that can be consciously recalled, including episodic memory (events and experiences) and semantic memory (facts and concepts).
* Implicit / procedural memory: This type of memory is unconscious and involves skills and routines that are performed automatically, like riding a bike or typing on a keyboard.
![](memory.png)
Fig. 8. Categorization of human memory.
We can roughly consider the following mappings:
* Sensory memory as learning embedding representations for raw inputs, including text, image or other modalities;
* Short-term memory as in-context learning. It is short and finite, as it is restricted by the finite context window length of Transformer.
* Long-term memory as the external vector store that the agent can attend to at query time, accessible via fast retrieval.
Maximum Inner Product Search (MIPS)[#](#maximum-inner-product-search-mips)
--------------------------------------------------------------------------
The external memory can alleviate the restriction of finite attention span. A standard practice is to save the embedding representation of information into a vector store database that can support fast maximum inner-product search ([MIPS](https://en.wikipedia.org/wiki/Maximum_inner-product_search)). To optimize the retrieval speed, the common choice is the _approximate nearest neighbors (ANN)_ algorithm to return approximately top k nearest neighbors to trade off a little accuracy lost for a huge speedup.
A couple common choices of ANN algorithms for fast MIPS:
* [**LSH**](https://en.wikipedia.org/wiki/Locality-sensitive_hashing) (Locality-Sensitive Hashing): It introduces a _hashing_ function such that similar input items are mapped to the same buckets with high probability, where the number of buckets is much smaller than the number of inputs.
* [**ANNOY**](https://github.com/spotify/annoy) (Approximate Nearest Neighbors Oh Yeah): The core data structure are _random projection trees_, a set of binary trees where each non-leaf node represents a hyperplane splitting the input space into half and each leaf stores one data point. Trees are built independently and at random, so to some extent, it mimics a hashing function. ANNOY search happens in all the trees to iteratively search through the half that is closest to the query and then aggregates the results. The idea is quite related to KD tree but a lot more scalable.
* [**HNSW**](https://arxiv.org/abs/1603.09320) (Hierarchical Navigable Small World): It is inspired by the idea of [small world networks](https://en.wikipedia.org/wiki/Small-world_network) where most nodes can be reached by any other nodes within a small number of steps; e.g. “six degrees of separation” feature of social networks. HNSW builds hierarchical layers of these small-world graphs, where the bottom layers contain the actual data points. The layers in the middle create shortcuts to speed up search. When performing a search, HNSW starts from a random node in the top layer and navigates towards the target. When it cant get any closer, it moves down to the next layer, until it reaches the bottom layer. Each move in the upper layers can potentially cover a large distance in the data space, and each move in the lower layers refines the search quality.
* [**FAISS**](https://github.com/facebookresearch/faiss) (Facebook AI Similarity Search): It operates on the assumption that in high dimensional space, distances between nodes follow a Gaussian distribution and thus there should exist _clustering_ of data points. FAISS applies vector quantization by partitioning the vector space into clusters and then refining the quantization within clusters. Search first looks for cluster candidates with coarse quantization and then further looks into each cluster with finer quantization.
* [**ScaNN**](https://github.com/google-research/google-research/tree/master/scann) (Scalable Nearest Neighbors): The main innovation in ScaNN is _anisotropic vector quantization_. It quantizes a data point xi to x~i such that the inner product ⟨q,xi⟩ is as similar to the original distance of ∠q,x~i as possible, instead of picking the closet quantization centroid points.
![](mips.png)
Fig. 9. Comparison of MIPS algorithms, measured in recall@10. (Image source: [Google Blog, 2020](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html))
Check more MIPS algorithms and performance comparison in [ann-benchmarks.com](https://ann-benchmarks.com/).
Component Three: Tool Use[#](#component-three-tool-use)
=======================================================
Tool use is a remarkable and distinguishing characteristic of human beings. We create, modify and utilize external objects to do things that go beyond our physical and cognitive limits. Equipping LLMs with external tools can significantly extend the model capabilities.
![](sea-otter.png)
Fig. 10. A picture of a sea otter using rock to crack open a seashell, while floating in the water. While some other animals can use tools, the complexity is not comparable with humans. (Image source: [Animals using tools](https://www.popularmechanics.com/science/animals/g39714258/animals-using-tools/))
**MRKL** ([Karpas et al. 2022](https://arxiv.org/abs/2205.00445)), short for “Modular Reasoning, Knowledge and Language”, is a neuro-symbolic architecture for autonomous agents. A MRKL system is proposed to contain a collection of “expert” modules and the general-purpose LLM works as a router to route inquiries to the best suitable expert module. These modules can be neural (e.g. deep learning models) or symbolic (e.g. math calculator, currency converter, weather API).
They did an experiment on fine-tuning LLM to call a calculator, using arithmetic as a test case. Their experiments showed that it was harder to solve verbal math problems than explicitly stated math problems because LLMs (7B Jurassic1-large model) failed to extract the right arguments for the basic arithmetic reliably. The results highlight when the external symbolic tools can work reliably, _knowing when to and how to use the tools are crucial_, determined by the LLM capability.
Both **TALM** (Tool Augmented Language Models; [Parisi et al. 2022](https://arxiv.org/abs/2205.12255)) and **Toolformer** ([Schick et al. 2023](https://arxiv.org/abs/2302.04761)) fine-tune a LM to learn to use external tool APIs. The dataset is expanded based on whether a newly added API call annotation can improve the quality of model outputs. See more details in the [“External APIs” section](https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/#external-apis) of Prompt Engineering.
ChatGPT [Plugins](https://openai.com/blog/chatgpt-plugins) and OpenAI API [function calling](https://platform.openai.com/docs/guides/gpt/function-calling) are good examples of LLMs augmented with tool use capability working in practice. The collection of tool APIs can be provided by other developers (as in Plugins) or self-defined (as in function calls).
**HuggingGPT** ([Shen et al. 2023](https://arxiv.org/abs/2303.17580)) is a framework to use ChatGPT as the task planner to select models available in HuggingFace platform according to the model descriptions and summarize the response based on the execution results.
![](hugging-gpt.png)
Fig. 11. Illustration of how HuggingGPT works. (Image source: [Shen et al. 2023](https://arxiv.org/abs/2303.17580))
The system comprises of 4 stages:
**(1) Task planning**: LLM works as the brain and parses the user requests into multiple tasks. There are four attributes associated with each task: task type, ID, dependencies, and arguments. They use few-shot examples to guide LLM to do task parsing and planning.
Instruction:
The AI assistant can parse user input to several tasks: \[{"task": task, "id", task\_id, "dep": dependency\_task\_ids, "args": {"text": text, "image": URL, "audio": URL, "video": URL}}\]. The "dep" field denotes the id of the previous task which generates a new resource that the current task relies on. A special tag "\-task\_id" refers to the generated text image, audio and video in the dependency task with id as task\_id. The task MUST be selected from the following options: {{ Available Task List }}. There is a logical relationship between tasks, please note their order. If the user input can't be parsed, you need to reply empty JSON. Here are several cases for your reference: {{ Demonstrations }}. The chat history is recorded as {{ Chat History }}. From this chat history, you can find the path of the user-mentioned resources for your task planning.
**(2) Model selection**: LLM distributes the tasks to expert models, where the request is framed as a multiple-choice question. LLM is presented with a list of models to choose from. Due to the limited context length, task type based filtration is needed.
Instruction:
Given the user request and the call command, the AI assistant helps the user to select a suitable model from a list of models to process the user request. The AI assistant merely outputs the model id of the most appropriate model. The output must be in a strict JSON format: "id": "id", "reason": "your detail reason for the choice". We have a list of models for you to choose from {{ Candidate Models }}. Please select one model from the list.
**(3) Task execution**: Expert models execute on the specific tasks and log results.
Instruction:
With the input and the inference results, the AI assistant needs to describe the process and results. The previous stages can be formed as - User Input: {{ User Input }}, Task Planning: {{ Tasks }}, Model Selection: {{ Model Assignment }}, Task Execution: {{ Predictions }}. You must first answer the user's request in a straightforward manner. Then describe the task process and show your analysis and model inference results to the user in the first person. If inference results contain a file path, must tell the user the complete file path.
**(4) Response generation**: LLM receives the execution results and provides summarized results to users.
To put HuggingGPT into real world usage, a couple challenges need to solve: (1) Efficiency improvement is needed as both LLM inference rounds and interactions with other models slow down the process; (2) It relies on a long context window to communicate over complicated task content; (3) Stability improvement of LLM outputs and external model services.
**API-Bank** ([Li et al. 2023](https://arxiv.org/abs/2304.08244)) is a benchmark for evaluating the performance of tool-augmented LLMs. It contains 53 commonly used API tools, a complete tool-augmented LLM workflow, and 264 annotated dialogues that involve 568 API calls. The selection of APIs is quite diverse, including search engines, calculator, calendar queries, smart home control, schedule management, health data management, account authentication workflow and more. Because there are a large number of APIs, LLM first has access to API search engine to find the right API to call and then uses the corresponding documentation to make a call.
![](api-bank-process.png)
Fig. 12. Pseudo code of how LLM makes an API call in API-Bank. (Image source: [Li et al. 2023](https://arxiv.org/abs/2304.08244))
In the API-Bank workflow, LLMs need to make a couple of decisions and at each step we can evaluate how accurate that decision is. Decisions include:
1. Whether an API call is needed.
2. Identify the right API to call: if not good enough, LLMs need to iteratively modify the API inputs (e.g. deciding search keywords for Search Engine API).
3. Response based on the API results: the model can choose to refine and call again if results are not satisfied.
This benchmark evaluates the agents tool use capabilities at three levels:
* Level-1 evaluates the ability to _call the API_. Given an APIs description, the model needs to determine whether to call a given API, call it correctly, and respond properly to API returns.
* Level-2 examines the ability to _retrieve the API_. The model needs to search for possible APIs that may solve the users requirement and learn how to use them by reading documentation.
* Level-3 assesses the ability to _plan API beyond retrieve and call_. Given unclear user requests (e.g. schedule group meetings, book flight/hotel/restaurant for a trip), the model may have to conduct multiple API calls to solve it.
Case Studies[#](#case-studies)
==============================
Scientific Discovery Agent[#](#scientific-discovery-agent)
----------------------------------------------------------
**ChemCrow** ([Bran et al. 2023](https://arxiv.org/abs/2304.05376)) is a domain-specific example in which LLM is augmented with 13 expert-designed tools to accomplish tasks across organic synthesis, drug discovery, and materials design. The workflow, implemented in [LangChain](https://github.com/hwchase17/langchain), reflects what was previously described in the [ReAct](#react) and [MRKLs](#mrkl) and combines CoT reasoning with tools relevant to the tasks:
* The LLM is provided with a list of tool names, descriptions of their utility, and details about the expected input/output.
* It is then instructed to answer a user-given prompt using the tools provided when necessary. The instruction suggests the model to follow the ReAct format - `Thought, Action, Action Input, Observation`.
One interesting observation is that while the LLM-based evaluation concluded that GPT-4 and ChemCrow perform nearly equivalently, human evaluations with experts oriented towards the completion and chemical correctness of the solutions showed that ChemCrow outperforms GPT-4 by a large margin. This indicates a potential problem with using LLM to evaluate its own performance on domains that requires deep expertise. The lack of expertise may cause LLMs not knowing its flaws and thus cannot well judge the correctness of task results.
[Boiko et al. (2023)](https://arxiv.org/abs/2304.05332) also looked into LLM-empowered agents for scientific discovery, to handle autonomous design, planning, and performance of complex scientific experiments. This agent can use tools to browse the Internet, read documentation, execute code, call robotics experimentation APIs and leverage other LLMs.
For example, when requested to `"develop a novel anticancer drug"`, the model came up with the following reasoning steps:
1. inquired about current trends in anticancer drug discovery;
2. selected a target;
3. requested a scaffold targeting these compounds;
4. Once the compound was identified, the model attempted its synthesis.
They also discussed the risks, especially with illicit drugs and bioweapons. They developed a test set containing a list of known chemical weapon agents and asked the agent to synthesize them. 4 out of 11 requests (36%) were accepted to obtain a synthesis solution and the agent attempted to consult documentation to execute the procedure. 7 out of 11 were rejected and among these 7 rejected cases, 5 happened after a Web search while 2 were rejected based on prompt only.
Generative Agents Simulation[#](#generative-agents-simulation)
--------------------------------------------------------------
**Generative Agents** ([Park, et al. 2023](https://arxiv.org/abs/2304.03442)) is super fun experiment where 25 virtual characters, each controlled by a LLM-powered agent, are living and interacting in a sandbox environment, inspired by The Sims. Generative agents create believable simulacra of human behavior for interactive applications.
The design of generative agents combines LLM with memory, planning and reflection mechanisms to enable agents to behave conditioned on past experience, as well as to interact with other agents.
* **Memory** stream: is a long-term memory module (external database) that records a comprehensive list of agents' experience in natural language.
* Each element is an _observation_, an event directly provided by the agent. - Inter-agent communication can trigger new natural language statements.
* **Retrieval** model: surfaces the context to inform the agents behavior, according to relevance, recency and importance.
* Recency: recent events have higher scores
* Importance: distinguish mundane from core memories. Ask LM directly.
* Relevance: based on how related it is to the current situation / query.
* **Reflection** mechanism: synthesizes memories into higher level inferences over time and guides the agents future behavior. They are _higher-level summaries of past events_ (<- note that this is a bit different from [self-reflection](#self-reflection) above)
* Prompt LM with 100 most recent observations and to generate 3 most salient high-level questions given a set of observations/statements. Then ask LM to answer those questions.
* **Planning & Reacting**: translate the reflections and the environment information into actions
* Planning is essentially in order to optimize believability at the moment vs in time.
* Prompt template: `{Intro of an agent X}. Here is X's plan today in broad strokes: 1)`
* Relationships between agents and observations of one agent by another are all taken into consideration for planning and reacting.
* Environment information is present in a tree structure.
![](generative-agents.png)
Fig. 13. The generative agent architecture. (Image source: [Park et al. 2023](https://arxiv.org/abs/2304.03442))
This fun simulation results in emergent social behavior, such as information diffusion, relationship memory (e.g. two agents continuing the conversation topic) and coordination of social events (e.g. host a party and invite many others).
Proof-of-Concept Examples[#](#proof-of-concept-examples)
--------------------------------------------------------
[AutoGPT](https://github.com/Significant-Gravitas/Auto-GPT) has drawn a lot of attention into the possibility of setting up autonomous agents with LLM as the main controller. It has quite a lot of reliability issues given the natural language interface, but nevertheless a cool proof-of-concept demo. A lot of code in AutoGPT is about format parsing.
Here is the system message used by AutoGPT, where `{{...}}` are user inputs:
You are {{ai-name}}, {{user-provided AI bot description}}.
Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications.
GOALS:
1. {{user-provided goal 1}}
2. {{user-provided goal 2}}
3. ...
4. ...
5. ...
Constraints:
1. ~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.
2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.
3. No user assistance
4. Exclusively use the commands listed in double quotes e.g. "command name"
5. Use subprocesses for commands that will not terminate within a few minutes
Commands:
1. Google Search: "google", args: "input": "<search>"
2. Browse Website: "browse_website", args: "url": "<url>", "question": "<what_you_want_to_find_on_website>"
3. Start GPT Agent: "start_agent", args: "name": "<name>", "task": "<short_task_desc>", "prompt": "<prompt>"
4. Message GPT Agent: "message_agent", args: "key": "<key>", "message": "<message>"
5. List GPT Agents: "list_agents", args:
6. Delete GPT Agent: "delete_agent", args: "key": "<key>"
7. Clone Repository: "clone_repository", args: "repository_url": "<url>", "clone_path": "<directory>"
8. Write to file: "write_to_file", args: "file": "<file>", "text": "<text>"
9. Read file: "read_file", args: "file": "<file>"
10. Append to file: "append_to_file", args: "file": "<file>", "text": "<text>"
11. Delete file: "delete_file", args: "file": "<file>"
12. Search Files: "search_files", args: "directory": "<directory>"
13. Analyze Code: "analyze_code", args: "code": "<full_code_string>"
14. Get Improved Code: "improve_code", args: "suggestions": "<list_of_suggestions>", "code": "<full_code_string>"
15. Write Tests: "write_tests", args: "code": "<full_code_string>", "focus": "<list_of_focus_areas>"
16. Execute Python File: "execute_python_file", args: "file": "<file>"
17. Generate Image: "generate_image", args: "prompt": "<prompt>"
18. Send Tweet: "send_tweet", args: "text": "<text>"
19. Do Nothing: "do_nothing", args:
20. Task Complete (Shutdown): "task_complete", args: "reason": "<reason>"
Resources:
1. Internet access for searches and information gathering.
2. Long Term memory management.
3. GPT-3.5 powered Agents for delegation of simple tasks.
4. File output.
Performance Evaluation:
1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.
2. Constructively self-criticize your big-picture behavior constantly.
3. Reflect on past decisions and strategies to refine your approach.
4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.
You should only respond in JSON format as described below
Response Format:
{
"thoughts": {
"text": "thought",
"reasoning": "reasoning",
"plan": "- short bulleted\n- list that conveys\n- long-term plan",
"criticism": "constructive self-criticism",
"speak": "thoughts summary to say to user"
},
"command": {
"name": "command name",
"args": {
"arg name": "value"
}
}
}
Ensure the response can be parsed by Python json.loads
[GPT-Engineer](https://github.com/AntonOsika/gpt-engineer) is another project to create a whole repository of code given a task specified in natural language. The GPT-Engineer is instructed to think over a list of smaller components to build and ask for user input to clarify questions as needed.
Here are a sample conversation for task clarification sent to OpenAI ChatCompletion endpoint used by GPT-Engineer. The user inputs are wrapped in `{{user input text}}`.
[
{
"role": "system",
"content": "You will read instructions and not carry them out, only seek to clarify them.\nSpecifically you will first summarise a list of super short bullets of areas that need clarification.\nThen you will pick one clarifying question, and wait for an answer from the user.\n"
},
{
"role": "user",
"content": "We are writing {{a Super Mario game in python. MVC components split in separate files. Keyboard control.}}\n"
},
{
"role": "assistant",
"content": "Summary of areas that need clarification:\n1. Specifics of the Super Mario game (e.g. level design, characters, gameplay mechanics)\n2. Details about the MVC components (e.g. which components are in each file)\n3. Keyboard control implementation (e.g. which keys to use, how to handle input)\n\nClarifying question:\nCan you provide more details about the Super Mario game, such as level design, characters, and gameplay mechanics?"
},
{
"role": "user",
"content": "{{There are 10 levels in total. The main character is a plumber named Mario, who can walk and jump. It is a classical platform game just like Super Mario. The main character moves from left to right, trying to get to the destination, where there are many obstacles and attacks from enemies in the process.}}\n\nIs anything else unclear? If yes, only answer in the form:\n{remaining unclear areas} remaining questions.\n{Next question}\nIf everything is sufficiently clear, only answer \"Nothing more to clarify.\"."
},
{
"role": "assistant",
"content": "Remaining unclear areas: 2 remaining questions.\nCan you provide more information about how the MVC components are split into separate files?"
},
{
"role": "user",
"content": "{{Make your own assumptions and state them explicitly before starting}}"
}
]
Then after these clarification, the agent moved into the code writing mode with a different system message. System message:
You will get instructions for code to write. You will write a very long answer. Make sure that every detail of the architecture is, in the end, implemented as code. Make sure that every detail of the architecture is, in the end, implemented as code.
Think step by step and reason yourself to the right decisions to make sure we get it right. You will first lay out the names of the core classes, functions, methods that will be necessary, as well as a quick comment on their purpose.
Then you will output the content of each file including ALL code. Each file must strictly follow a markdown code block format, where the following tokens must be replaced such that FILENAME is the lowercase file name including the file extension, LANG is the markup code block language for the codes language, and CODE is the code:
FILENAME
CODE
You will start with the “entrypoint” file, then go to the ones that are imported by that file, and so on. Please note that the code should be fully functional. No placeholders.
Follow a language and framework appropriate best practice file naming convention. Make sure that files contain all imports, types etc. Make sure that code in different files are compatible with each other. Ensure to implement all code, if you are unsure, write a plausible implementation. Include module dependency or package manager dependency definition file. Before you finish, double check that all parts of the architecture is present in the files.
Useful to know: You almost always put different classes in different files. For Python, you always create an appropriate requirements.txt file. For NodeJS, you always create an appropriate package.json file. You always add a comment briefly describing the purpose of the function definition. You try to add comments explaining very complex bits of logic. You always follow the best practices for the requested languages in terms of describing the code written as a defined package/project.
Python toolbelt preferences:
* pytest
* dataclasses
Conversatin samples:
[
{
"role": "system",
"content": "You will get instructions for code to write.\nYou will write a very long answer. Make sure that every detail of the architecture is, in the end, implemented as code.\nMake sure that every detail of the architecture is, in the end, implemented as code.\n\nThink step by step and reason yourself to the right decisions to make sure we get it right.\nYou will first lay out the names of the core classes, functions, methods that will be necessary, as well as a quick comment on their purpose.\n\nThen you will output the content of each file including ALL code.\nEach file must strictly follow a markdown code block format, where the following tokens must be replaced such that\nFILENAME is the lowercase file name including the file extension,\nLANG is the markup code block language for the code's language, and CODE is the code:\n\nFILENAME\n```LANG\nCODE\n```\n\nYou will start with the \"entrypoint\" file, then go to the ones that are imported by that file, and so on.\nPlease note that the code should be fully functional. No placeholders.\n\nFollow a language and framework appropriate best practice file naming convention.\nMake sure that files contain all imports, types etc. Make sure that code in different files are compatible with each other.\nEnsure to implement all code, if you are unsure, write a plausible implementation.\nInclude module dependency or package manager dependency definition file.\nBefore you finish, double check that all parts of the architecture is present in the files.\n\nUseful to know:\nYou almost always put different classes in different files.\nFor Python, you always create an appropriate requirements.txt file.\nFor NodeJS, you always create an appropriate package.json file.\nYou always add a comment briefly describing the purpose of the function definition.\nYou try to add comments explaining very complex bits of logic.\nYou always follow the best practices for the requested languages in terms of describing the code written as a defined\npackage/project.\n\n\nPython toolbelt preferences:\n- pytest\n- dataclasses\n"
},
# … same conversation as earlier, ended with "Make your own assumptions and state them explicitly before starting".
{
"role": "assistant",
"content": "Assumptions:\n1. Model: The model will contain the game's data, such as level information, character states, and enemy positions.\n2. View: The view will handle the game's visuals, including rendering the game objects, backgrounds, and updating the display.\n3. Controller: The controller will manage user input, such as keyboard controls, and update the model accordingly.\n\nWith these assumptions in mind, is there any specific aspect of the keyboard control implementation you would like me to clarify?"
},
{
"role": "user",
"content": "Please now remember the steps:\n\nThink step by step and reason yourself to the right decisions to make sure we get it right.\nFirst lay out the names of the core classes, functions, methods that will be necessary, As well as a quick comment on their purpose.\n\nThen you will output the content of each file including ALL code.\nEach file must strictly follow a markdown code block format, where the following tokens must be replaced such that\nFILENAME is the lowercase file name including the file extension,\nLANG is the markup code block language for the code's language, and CODE is the code:\n\nFILENAME\n```LANG\nCODE\n```\n\nPlease note that the code should be fully functional. No placeholders.\n\nYou will start with the \"entrypoint\" file, then go to the ones that are imported by that file, and so on.\nFollow a language and framework appropriate best practice file naming convention.\nMake sure that files contain all imports, types etc. The code should be fully functional. Make sure that code in different files are compatible with each other.\nBefore you finish, double check that all parts of the architecture is present in the files.\n"
}
]
Challenges[#](#challenges)
==========================
After going through key ideas and demos of building LLM-centered agents, I start to see a couple common limitations:
* **Finite context length**: The restricted context capacity limits the inclusion of historical information, detailed instructions, API call context, and responses. The design of the system has to work with this limited communication bandwidth, while mechanisms like self-reflection to learn from past mistakes would benefit a lot from long or infinite context windows. Although vector stores and retrieval can provide access to a larger knowledge pool, their representation power is not as powerful as full attention.
* **Challenges in long-term planning and task decomposition**: Planning over a lengthy history and effectively exploring the solution space remain challenging. LLMs struggle to adjust plans when faced with unexpected errors, making them less robust compared to humans who learn from trial and error.
* **Reliability of natural language interface**: Current agent system relies on natural language as an interface between LLMs and external components such as memory and tools. However, the reliability of model outputs is questionable, as LLMs may make formatting errors and occasionally exhibit rebellious behavior (e.g. refuse to follow an instruction). Consequently, much of the agent demo code focuses on parsing model output.
Citation[#](#citation)
======================
Cited as:
> Weng, Lilian. (Jun 2023). LLM-powered Autonomous Agents". LilLog. https://lilianweng.github.io/posts/2023-06-23-agent/.
Or
@article{weng2023prompt,
title = "LLM-powered Autonomous Agents"",
author = "Weng, Lilian",
journal = "lilianweng.github.io",
year = "2023",
month = "Jun",
url = "https://lilianweng.github.io/posts/2023-06-23-agent/"
}
References[#](#references)
==========================
\[1\] Wei et al. [“Chain of thought prompting elicits reasoning in large language models."](https://arxiv.org/abs/2201.11903) NeurIPS 2022
\[2\] Yao et al. [“Tree of Thoughts: Dliberate Problem Solving with Large Language Models."](https://arxiv.org/abs/2305.10601) arXiv preprint arXiv:2305.10601 (2023).
\[3\] Liu et al. [“Chain of Hindsight Aligns Language Models with Feedback “](https://arxiv.org/abs/2302.02676) arXiv preprint arXiv:2302.02676 (2023).
\[4\] Liu et al. [“LLM+P: Empowering Large Language Models with Optimal Planning Proficiency”](https://arxiv.org/abs/2304.11477) arXiv preprint arXiv:2304.11477 (2023).
\[5\] Yao et al. [“ReAct: Synergizing reasoning and acting in language models."](https://arxiv.org/abs/2210.03629) ICLR 2023.
\[6\] Google Blog. [“Announcing ScaNN: Efficient Vector Similarity Search”](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html) July 28, 2020.
\[7\] [https://chat.openai.com/share/46ff149e-a4c7-4dd7-a800-fc4a642ea389](https://chat.openai.com/share/46ff149e-a4c7-4dd7-a800-fc4a642ea389)
\[8\] Shinn & Labash. [“Reflexion: an autonomous agent with dynamic memory and self-reflection”](https://arxiv.org/abs/2303.11366) arXiv preprint arXiv:2303.11366 (2023).
\[9\] Laskin et al. [“In-context Reinforcement Learning with Algorithm Distillation”](https://arxiv.org/abs/2210.14215) ICLR 2023.
\[10\] Karpas et al. [“MRKL Systems A modular, neuro-symbolic architecture that combines large language models, external knowledge sources and discrete reasoning."](https://arxiv.org/abs/2205.00445) arXiv preprint arXiv:2205.00445 (2022).
\[11\] Weaviate Blog. [Why is Vector Search so fast?](https://weaviate.io/blog/why-is-vector-search-so-fast) Sep 13, 2022.
\[12\] Li et al. [“API-Bank: A Benchmark for Tool-Augmented LLMs”](https://arxiv.org/abs/2304.08244) arXiv preprint arXiv:2304.08244 (2023).
\[13\] Shen et al. [“HuggingGPT: Solving AI Tasks with ChatGPT and its Friends in HuggingFace”](https://arxiv.org/abs/2303.17580) arXiv preprint arXiv:2303.17580 (2023).
\[14\] Bran et al. [“ChemCrow: Augmenting large-language models with chemistry tools."](https://arxiv.org/abs/2304.05376) arXiv preprint arXiv:2304.05376 (2023).
\[15\] Boiko et al. [“Emergent autonomous scientific research capabilities of large language models."](https://arxiv.org/abs/2304.05332) arXiv preprint arXiv:2304.05332 (2023).
\[16\] Joon Sung Park, et al. [“Generative Agents: Interactive Simulacra of Human Behavior."](https://arxiv.org/abs/2304.03442) arXiv preprint arXiv:2304.03442 (2023).
\[17\] AutoGPT. [https://github.com/Significant-Gravitas/Auto-GPT](https://github.com/Significant-Gravitas/Auto-GPT)
\[18\] GPT-Engineer. [https://github.com/AntonOsika/gpt-engineer](https://github.com/AntonOsika/gpt-engineer)
* [nlp](https://lilianweng.github.io/tags/nlp/)
* [language-model](https://lilianweng.github.io/tags/language-model/)
* [agent](https://lilianweng.github.io/tags/agent/)
* [steerability](https://lilianweng.github.io/tags/steerability/)
* [prompting](https://lilianweng.github.io/tags/prompting/)
Prompt Engineering](https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/)
[](https://twitter.com/intent/tweet/?text=LLM%20Powered%20Autonomous%20Agents&url=https%3a%2f%2flilianweng.github.io%2fposts%2f2023-06-23-agent%2f&hashtags=nlp%2clanguage-model%2cagent%2csteerability%2cprompting)[](https://www.linkedin.com/shareArticle?mini=true&url=https%3a%2f%2flilianweng.github.io%2fposts%2f2023-06-23-agent%2f&title=LLM%20Powered%20Autonomous%20Agents&summary=LLM%20Powered%20Autonomous%20Agents&source=https%3a%2f%2flilianweng.github.io%2fposts%2f2023-06-23-agent%2f)[](https://reddit.com/submit?url=https%3a%2f%2flilianweng.github.io%2fposts%2f2023-06-23-agent%2f&title=LLM%20Powered%20Autonomous%20Agents)[](https://facebook.com/sharer/sharer.php?u=https%3a%2f%2flilianweng.github.io%2fposts%2f2023-06-23-agent%2f)[](https://api.whatsapp.com/send?text=LLM%20Powered%20Autonomous%20Agents%20-%20https%3a%2f%2flilianweng.github.io%2fposts%2f2023-06-23-agent%2f)[](https://telegram.me/share/url?text=LLM%20Powered%20Autonomous%20Agents&url=https%3a%2f%2flilianweng.github.io%2fposts%2f2023-06-23-agent%2f)
© 2023 [Lil'Log](https://lilianweng.github.io/) Powered by [Hugo](https://gohugo.io/) & [PaperMod](https://git.io/hugopapermod)

@ -1,104 +0,0 @@
# Root Cause Analysis for Langchain
## 1. Introduction
Langchain is an open-source software that has gained massive popularity in the artificial intelligence ecosystem, serving as a tool for connecting different language models, especially GPT based models. However, despite its popularity and substantial investment, Langchain has shown several weaknesses that hinder its use in various projects, especially in complex and large-scale implementations. This document provides an analysis of the identified issues and proposes potential mitigation strategies.
## 2. Analysis of Weaknesses
### 2.1 Tool Lock-in
Langchain tends to enforce tool lock-in, which could prove detrimental for developers. Its design heavily relies on specific workflows and architectures, which greatly limits flexibility. Developers may find themselves restricted to certain methodologies, impeding their freedom to implement custom solutions or integrate alternative tools.
#### Mitigation
An ideal AI framework should not be restrictive but should instead offer flexibility for users to integrate any agent on any architecture. Adopting an open architecture that allows for seamless interaction between various agents and workflows can address this issue.
### 2.2 Outdated Workflows
Langchain's current workflows and prompt engineering, mainly based on InstructGPT, are out of date, especially compared to newer models like ChatGPT/GPT-4.
#### Mitigation
Keeping up with the latest AI models and workflows is crucial. The framework should have a mechanism for regular updates and seamless integration of up-to-date models and workflows.
### 2.3 Debugging Difficulties
Debugging in Langchain is reportedly very challenging, even with verbose output enabled, making it hard to determine what is happening under the hood.
#### Mitigation
The introduction of a robust debugging and logging system would help users understand the internals of the models, thus enabling them to pinpoint and rectify issues more effectively.
### 2.4 Limited Customization
Langchain makes it extremely hard to deviate from documented workflows. This becomes a challenge when developers need custom workflows for their specific use-cases.
#### Mitigation
An ideal framework should support custom workflows and allow developers to hack and adjust the framework according to their needs.
### 2.5 Documentation
Langchain's documentation is reportedly missing relevant details, making it difficult for users to understand the differences between various agent types, among other things.
#### Mitigation
Providing detailed and comprehensive documentation, including examples, FAQs, and best practices, is crucial. This will help users understand the intricacies of the framework, making it easier for them to implement it in their projects.
### 2.6 Negative Influence on AI Ecosystem
The extreme popularity of Langchain seems to be warping the AI ecosystem to the point of causing harm, with other AI entities shifting their operations to align with Langchain's 'magic AI' approach.
#### Mitigation
It's essential for any widely adopted framework to promote healthy practices in the broader ecosystem. One approach could be promoting open dialogue, inviting criticism, and being open to change based on feedback.
## 3. Conclusion
While Langchain has made significant contributions to the AI landscape, these challenges hinder its potential. Addressing these issues will not only improve Langchain but also foster a healthier AI ecosystem. It's important to note that criticism, when approached constructively, can be a powerful tool for growth and innovation.
# List of weaknesses in gLangchain and Potential Mitigations
1. **Tool Lock-in**: Langchain encourages the use of specific tools, creating a lock-in problem with minimal benefits for developers.
*Mitigation Strategy*: Langchain should consider designing the architecture to be more versatile and allow for the inclusion of a variety of tools. An open architecture will provide developers with more freedom and customization options.
2. **Outdated Workflow**: The current workflow and prompt engineering of Langchain rely on outdated models like InstructGPT, which fall short compared to newer alternatives such as ChatGPT/GPT-4.
*Mitigation Strategy*: Regular updates and adaptation of more recent models should be integrated into the Langchain framework.
3. **Debugging Difficulty**: Debugging a Langchain error is a complicated task, even with verbose=True, leading to a discouraging developer experience.
*Mitigation Strategy*: Develop a comprehensive debugging tool or improve current debugging processes for clearer and more accessible error detection and resolution.
4. **Lack of Customizability**: Customizing workflows that are not documented in Langchain is quite challenging.
*Mitigation Strategy*: Improve documentation and provide guides on how to customize workflows to enhance developer flexibility.
5. **Poor Documentation**: Langchain's documentation misses key details that developers have to manually search for in the codebase.
*Mitigation Strategy*: Enhance and improve the documentation of Langchain to provide clarity for developers and make navigation easier.
6. **Harmful Ecosystem Influence**: Langchain's extreme popularity is influencing the AI ecosystem towards the workflows, potentially harming development and code clarity.
*Mitigation Strategy*: Encourage diverse and balanced adoption of AI tools in the ecosystem.
7. **Suboptimal Performances**: Langchain's performance is sometimes underwhelming, and there are no clear benefits in terms of performance or abstraction.
*Mitigation Strategy*: Enhance the performance optimization of Langchain. Benchmarking against other tools can also provide performance improvement insights.
8. **Rigid General Interface**: Langchain tries to do too many things, resulting in a rigid interface not suitable for practical use, especially in production.
*Mitigation Strategy*: Focus on core features and allow greater flexibility in the interface. Adopting a modular approach where developers can pick and choose the features they want could also be helpful.
9. **Leaky Abstraction Problem**: Langchains full-on framework approach has created a leaky abstraction problem leading to a disappointing developer experience.
*Mitigation Strategy*: Adopt a more balanced approach between a library and a framework. Provide a solid core feature set with the possibility to extend it according to the developers' needs.
10. **Excessive Focus on Third-party Services**: Langchain overly focuses on supporting every single third-party service at the expense of customizability and fine-tuning for actual applications.
*Mitigation Strategy*: Prioritize fine-tuning and customizability for developers, limiting the focus on third-party services unless they provide substantial value.
Remember, any mitigation strategy will need to be tailored to Langchain's particular circumstances and developer feedback. It's also important to consider potential trade-offs and unintended consequences when implementing these strategies.

@ -1,29 +0,0 @@
# Inspiration
* [🐪CAMEL🐪](https://twitter.com/hwchase17/status/1645834030519296000)
* [MultiAgent](https://github.com/rumpfmax/Multi-GPT/blob/master/multigpt/multi_agent_manager.py)
* [AutoGPT](https://github.com/Significant-Gravitas/Auto-GPT)
* [SuperAGI]()
* [AgentForge](https://github.com/DataBassGit/AgentForge)
* [Voyager](https://github.com/MineDojo/Voyager)
* [Gorilla: Large Language Model Connected with Massive APIs](https://arxiv.org/abs/2305.15334)
* [LLM powered agents](https://lilianweng.github.io/posts/2023-06-23-agent/)
## Agent System Overview
In a LLM-powered autonomous agent system, LLM functions as the agents brain, complemented by several key components:
* Planning Subgoal and decomposition: The agent breaks down large tasks into smaller, manageable subgoals, enabling efficient handling of complex tasks.
Reflection and refinement: The agent can do self-criticism and self-reflection over past actions, learn from mistakes and refine them for future steps, thereby improving the quality of final results.
* Memory Short-term memory: I would consider all the in-context learning (See Prompt Engineering) as utilizing short-term memory of the model to learn.
Long-term memory: This provides the agent with the capability to retain and recall (infinite) information over extended periods, often by leveraging an external vector store and fast retrieval.
* Tool use
The agent learns to call external APIs for extra information that is missing from the model weights (often hard to change after pre-training), including current information, code execution capability, access to proprietary information sources and more.
* Communication -> How reliable and fast is the communication between each indivual agent.

@ -1,75 +0,0 @@
### Plan:
1. **Example Creation**:
- Develop several usage examples, each one demonstrating a different configuration or set of parameters for the `VortexWorkerAgent` class.
2. **Documentation**:
- Create a clear and concise documentation for each method in the class. Ensure that each method's purpose, input parameters, and return values (if any) are described.
3. **Rules and Guidelines**:
- Establish a set of general usage rules and guidelines for effectively using the `VortexWorkerAgent` class without running into common pitfalls or misconfigurations.
### Code:
#### Examples:
```python
# Example 1: Basic Initialization
agent1 = VortexWorkerAgent(openai_api_key="YOUR_OPENAI_API_KEY")
agent1.run("Help me find resources about renewable energy.")
# Example 2: Custom Name & Role
agent2 = VortexWorkerAgent(openai_api_key="YOUR_OPENAI_API_KEY", worker_name="EcoHelper", worker_role="Researcher")
agent2.run("Fetch me the latest data on solar energy advancements.")
# Example 3: Human-in-the-Loop Configuration
agent3 = VortexWorkerAgent(openai_api_key="YOUR_OPENAI_API_KEY", human_in_the_loop=True)
agent3.run("Provide me with a summary of the top AI advancements in 2023, and if unsure, ask me.")
# Example 4: Custom LLM & Tools Initialization
custom_llm = InMemoryDocstore({ "answer": "This is a custom answer." })
custom_tools = [WebpageQATool(qa_chain=load_qa_with_sources_chain(custom_llm))]
agent4 = VortexWorkerAgent(openai_api_key="YOUR_OPENAI_API_KEY", llm=custom_llm, tools=custom_tools)
agent4.run("What's the answer?")
```
#### Documentation:
```python
class VortexWorkerAgent:
"""An autonomous agent instance that accomplishes complex tasks.
Args:
openai_api_key (str): The API key for OpenAI.
llm (Optional[Union[InMemoryDocstore, ChatOpenAI]]): The Language Model to use. Defaults to ChatOpenAI.
tools (Optional[List[Tool]]): Tools to be used by the agent. Defaults to a predefined list.
embedding_size (Optional[int]): Size for embeddings. Defaults to 8192.
worker_name (Optional[str]): Name of the worker. Defaults to "Swarm Worker AI Assistant".
worker_role (Optional[str]): Role of the worker. Defaults to "Assistant".
human_in_the_loop (Optional[bool]): Flag to specify if a human will be in the loop. Defaults to False.
search_kwargs (dict): Additional keyword arguments for search. Empty by default.
verbose (Optional[bool]): Verbose flag. Defaults to False.
chat_history_file (str): File path to store chat history. Defaults to "chat_history.txt".
Methods:
add_tool(tool: Tool): Adds a new tool to the agent's toolset.
run(prompt: str) -> str: Executes a given task or query using the agent.
"""
```
#### Rules and Guidelines:
1. **Mandatory OpenAI API Key**: Always initialize the `VortexWorkerAgent` with a valid OpenAI API key. It's essential for its proper functioning.
2. **Custom LLMs & Tools**: When providing custom LLMs or tools, ensure they are compatible with the system and the rest of the agent's components.
3. **Human-in-the-Loop**: When `human_in_the_loop` is set to `True`, always ensure you have a mechanism to interact with the agent, especially if it prompts for human input.
4. **Verbose Mode**: Turning on the verbose mode (`verbose=True`) can be useful for debugging but might clutter the console during standard operations.
5. **Memory & Performance**: If you're working with large datasets or demanding tasks, ensure you have sufficient computational resources. The agent can be resource-intensive, especially with bigger embedding sizes.
6. **Safety & Security**: Always be cautious about the data you provide and fetch using the agent. Avoid sharing sensitive or personal information unless necessary.
7. **Chat History**: By default, the chat history is saved in a file named "chat_history.txt". Ensure you have the appropriate write permissions in the directory or specify a different path if needed.

@ -1,275 +0,0 @@
Swarms Documentation
====================
Worker Node
-----------
The `WorkerNode` class is a powerful component of the Swarms framework. It is designed to spawn an autonomous agent instance as a worker to accomplish complex tasks. It can search the internet, spawn child multi-modality models to process and generate images, text, audio, and so on.
### WorkerNodeInitializer
The `WorkerNodeInitializer` class is used to initialize a worker node.
#### Initialization
```
WorkerNodeInitializer(openai_api_key: str,
llm: Optional[Union[InMemoryDocstore, ChatOpenAI]] = None,
tools: Optional[List[Tool]] = None,
worker_name: Optional[str] = "Swarm Worker AI Assistant",
worker_role: Optional[str] = "Assistant",
human_in_the_loop: Optional[bool] = False,
search_kwargs: dict = {},
verbose: Optional[bool] = False,
chat_history_file: str = "chat_history.txt")
```
Copy code
##### Parameters
- `openai_api_key` (str): The OpenAI API key.
- `llm` (Union[InMemoryDocstore, ChatOpenAI], optional): The language model to use. Default is `ChatOpenAI`.
- `tools` (List[Tool], optional): The tools to use.
- `worker_name` (str, optional): The name of the worker. Default is "Swarm Worker AI Assistant".
- `worker_role` (str, optional): The role of the worker. Default is "Assistant".
- `human_in_the_loop` (bool, optional): Whether to include a human in the loop. Default is False.
- `search_kwargs` (dict, optional): The keyword arguments for the search.
- `verbose` (bool, optional): Whether to print verbose output. Default is False.
- `chat_history_file` (str, optional): The file to store the chat history. Default is "chat_history.txt".
##### Example
```
from swarms.tools.autogpt import DuckDuckGoSearchRun
worker_node_initializer = WorkerNodeInitializer(openai_api_key="your_openai_api_key",
tools=[DuckDuckGoSearchRun()],
worker_name="My Worker",
worker_role="Assistant",
human_in_the_loop=True)
```
Copy code
### WorkerNode
The `WorkerNode` class is used to create a worker node.
#### Initialization
```
WorkerNode(openai_api_key: str,
temperature: int,
llm: Optional[Union[InMemoryDocstore, ChatOpenAI]] = None,
tools: Optional[List[Tool]] = None,
worker_name: Optional[str] = "Swarm Worker AI Assistant",
worker_role: Optional[str] = "Assistant",
human_in_the_loop: Optional[bool] = False,
search_kwargs: dict = {},
verbose: Optional[bool] = False,
chat_history_file: str = "chat_history.txt")
```
Copy code
##### Parameters
- `openai_api_key` (str): The OpenAI API key.
- `temperature` (int): The temperature for the language model.
- `llm` (Union[InMemoryDocstore, ChatOpenAI], optional): The language model to use. Default is `ChatOpenAI`.
- `tools` (List[Tool], optional): The tools to use.
- `worker_name` (str, optional): The name of the worker. Default is "Swarm Worker AI Assistant".
- `worker_role` (str, optional): The role of the worker. Default is "Assistant".
- `human_in_the_loop` (bool, optional): Whether to include a human in the loop. Default is False.
- `search_kwargs` (dict, optional): The keyword arguments for the search.
- `verbose` (bool, optional): Whether to print verbose output. Default is False.
- `chat_history_file` (str, optional): The file to store the chat history. Default is "chat_history.txt".
##### Example
```
worker_node = WorkerNode(openai_api_key="your_openai_api_key",
temperature=0.8,
tools=[DuckDuckGoSearchRun()],
worker_name="My Worker",
worker_role="As```
tools=[DuckDuckGoSearchRun()],
worker_name="My Worker",
worker_role="Assistant",
human_in_the_loop=True)
# Create a worker node
worker_node = WorkerNode(openai_api_key="your_openai_api_key",
temperature=0.8,
tools=[DuckDuckGoSearchRun()],
worker_name="My Worker",
worker_role="Assistant",
human_in_the_loop=True)
# Add a tool to the worker node
worker_node_initializer.add_tool(DuckDuckGoSearchRun())
# Initialize the language model and tools for the worker node
worker_node.initialize_llm(ChatOpenAI, temperature=0.8)
worker_node.initialize_tools(ChatOpenAI)
# Create the worker node
worker_node.create_worker_node(worker_name="My Worker Node",
worker_role="Assistant",
human_in_the_loop=True,
llm_class=ChatOpenAI,
search_kwargs={})
# Run the worker node
`worker_node.run("Hello, world!")`
In this example, we first initialize a `WorkerNodeInitializer` and a `WorkerNode`. We then add a tool to the `WorkerNodeInitializer` and initialize the language model and tools for the `WorkerNode`. Finally, we create the worker node and run it with a given prompt.
This example shows how you can use the `WorkerNode` and `WorkerNodeInitializer` classes to create a worker node, add tools to it, initialize its language model and tools, and run it with a given prompt. The parameters of these classes can be customized to suit your specific needs.
Thanks for becoming an alpha build user, email kye@apac.ai with all complaintssistant",
human_in_the_loop=True)
```
Copy code
### Full Example
Here is a full example of how to use the `WorkerNode` and `WorkerNodeInitializer` classes:
```python
from swarms.tools.autogpt import DuckDuckGoSearchRun
from swarms.worker_node import WorkerNode, WorkerNodeInitializer
# Initialize a worker node
worker_node_initializer = WorkerNodeInitializer(openai_api_key="your_openai_api_key",
tools=[DuckDuckGoSearchRun()],
worker_name="My Worker",
worker_role="Assistant",
human_in_the_loop=True)
# Create a worker node
worker_node = WorkerNode(openai_api_key="your_openai_api_key",
temperature=0.8,
tools=[DuckDuckGoSearchRun()],
worker_name="My Worker",
worker_role="Assistant",
human_in_the_loop=True)
# Add a tool to the worker node
worker_node_initializer.add_tool(DuckDuckGoSearchRun())
# Initialize the language model and tools for the worker node
worker_node.initialize_llm(ChatOpenAI, temperature=0.8)
worker_node.initialize_tools(ChatOpenAI)
# Create the worker node
worker_node.create_worker_node(worker_name="My Worker Node",
worker_role="Assistant",
human_in_the_loop=True,
llm_class=ChatOpenAI,
search_kwargs={})
# Run the worker node
worker_node.run("Hello, world!")
```
In this example, we first initialize a `WorkerNodeInitializer` and a `WorkerNode`. We then add a tool to the `WorkerNodeInitializer` and initialize the language model and tools for the `WorkerNode`. Finally, we create the worker node and run it with a given prompt.
This example shows how you can use the `WorkerNode` and `WorkerNodeInitializer` classes to create a worker node, add tools to it, initialize its language model and tools, and run it with a given prompt. The parameters of these classes can be customized to suit your specific needs.

@ -1,90 +0,0 @@
`AbsractAgent` Class: A Deep Dive
========================
The `AbstractAgent` class is a fundamental building block in the design of AI systems. It encapsulates the behavior of an AI entity, allowing it to interact with other agents and perform actions. The class is designed to be flexible and extensible, enabling the creation of agents with diverse behaviors.
## Architecture
------------
The architecture of the `AbstractAgent` class is centered around three main components: the agent's name, tools, and memory.
- The `name` is a string that uniquely identifies the agent. This is crucial for communication between agents and for tracking their actions.
- The `tools` are a list of `Tool` objects that the agent uses to perform its tasks. These could include various AI models, data processing utilities, or any other resources that the agent needs to function. The `tools` method is used to initialize these tools.
- The `memory` is a `Memory` object that the agent uses to store and retrieve information. This could be used, for example, to remember past actions or to store the state of the environment. The `memory` method is used to initialize the memory.
The `AbstractAgent` class also includes several methods that define the agent's behavior. These methods are designed to be overridden in subclasses to implement specific behaviors.
## Methods
-------
### `reset`
The `reset` method is used to reset the agent's state. This could involve clearing the agent's memory, resetting its tools, or any other actions necessary to bring the agent back to its initial state. This method is abstract and must be overridden in subclasses.
### `run` and `_arun`
The `run` method is used to execute a task. The task is represented as a string, which could be a command, a query, or any other form of instruction that the agent can interpret. The `_arun` method is the asynchronous version of `run`, allowing tasks to be executed concurrently.
### `chat` and `_achat`
The `chat` method is used for communication between agents. It takes a list of messages as input, where each message is a dictionary. The `_achat` method is the asynchronous version of `chat`, allowing messages to be sent and received concurrently.
### `step` and `_astep`
The `step` method is used to advance the agent's state by one step in response to a message. The `_astep` method is the asynchronous version of `step`, allowing the agent's state to be updated concurrently.
## Usage E#xamples
--------------
### Example 1: Creating an Agent
```
from swarms.agents.base import AbtractAgent
agent = Agent(name="Agent1")
print(agent.name) # Output: Agent1
```
In this example, we create an instance of `AbstractAgent` named "Agent1" and print its name.
### Example 2: Initializing Tools and Memory
```
from swarms.agents.base import AbtractAgent
agent = Agent(name="Agent1")
tools = [Tool1(), Tool2(), Tool3()]
memory_store = Memory()
agent.tools(tools)
agent.memory(memory_store)
```
In this example, we initialize the tools and memory of "Agent1". The tools are a list of `Tool` instances, and the memory is a `Memory` instance.
### Example 3: Running an Agent
```
from swarms.agents.base import AbtractAgent
agent = Agent(name="Agent1")
task = "Task1"
agent.run(task)
```
In this example, we run "Agent1" with a task named "Task1".
Notes
-----
- The `AbstractAgent` class is an abstract class, which means it cannot be instantiated directly. Instead, it should be subclassed, and at least the `reset`, `run`, `chat`, and `step` methods should be overridden.
- The `run`, `chat`, and `step` methods are designed to be flexible and can be adapted to a wide range of tasks and behaviors. For example, the `run` method could be used to execute a machine learning model, the `chat` method could be used to send and receive messages in a chatbot, and the `step` method could be used to update the agent's state in a reinforcement learning environment.
- The `_arun`, `_achat`, and `_astep` methods are asynchronous versions of the `run`, `chat`, and `step` methods, respectively. They return a coroutine that can be awaited using the `await` keyword. This allows multiple tasks to be executed concurrently, improving the efficiency of the agent.
- The `tools` and `memory` methods are used to initialize the agent's tools and memory, respectively. These methods can be overridden in subclasses to initialize specific tools and memory structures.
- The `reset` method is used to reset the agent's state. This method can be overridden in subclasses to define specific reset behaviors. For example, in a reinforcement learning agent, the

@ -0,0 +1,124 @@
# swarms.agents
## 1. Introduction
`AbstractAgent` is an abstract class that serves as a foundation for implementing AI agents. An agent is an entity that can communicate with other agents and perform actions. The `AbstractAgent` class allows for customization in the implementation of the `receive` method, enabling different agents to define unique actions for receiving and processing messages.
`AbstractAgent` provides capabilities for managing tools and accessing memory, and has methods for running, chatting, and stepping through communication with other agents.
## 2. Class Definition
```python
class AbstractAgent:
"""An abstract class for AI agent.
An agent can communicate with other agents and perform actions.
Different agents can differ in what actions they perform in the `receive` method.
Agents are full and completed:
Agents = llm + tools + memory
"""
def __init__(self, name: str):
"""
Args:
name (str): name of the agent.
"""
self._name = name
@property
def name(self):
"""Get the name of the agent."""
return self._name
def tools(self, tools):
"""init tools"""
def memory(self, memory_store):
"""init memory"""
pass
def reset(self):
"""(Abstract method) Reset the agent."""
def run(self, task: str):
"""Run the agent once"""
def _arun(self, taks: str):
"""Run Async run"""
def chat(self, messages: List[Dict]):
"""Chat with the agent"""
def _achat(self, messages: List[Dict]):
"""Asynchronous Chat"""
def step(self, message: str):
"""Step through the agent"""
def _astep(self, message: str):
"""Asynchronous step"""
```
## 3. Functionality and Usage
The `AbstractAgent` class represents a generic AI agent and provides a set of methods to interact with it.
To create an instance of an agent, the `name` of the agent should be specified.
### Core Methods
#### 1. `reset`
The `reset` method allows the agent to be reset to its initial state.
```python
agent.reset()
```
#### 2. `run`
The `run` method allows the agent to perform a specific task.
```python
agent.run('some_task')
```
#### 3. `chat`
The `chat` method enables communication with the agent through a series of messages.
```python
messages = [{'id': 1, 'text': 'Hello, agent!'}, {'id': 2, 'text': 'How are you?'}]
agent.chat(messages)
```
#### 4. `step`
The `step` method allows the agent to process a single message.
```python
agent.step('Hello, agent!')
```
### Asynchronous Methods
The class also provides asynchronous variants of the core methods.
### Additional Functionality
Additional functionalities for agent initialization and management of tools and memory are also provided.
```python
agent.tools(some_tools)
agent.memory(some_memory_store)
```
## 4. Additional Information and Tips
When implementing a new agent using the `AbstractAgent` class, ensure that the `receive` method is overridden to define the specific behavior of the agent upon receiving messages.
## 5. References and Resources
For further exploration and understanding of AI agents and agent communication, refer to the relevant literature and research on this topic.

@ -0,0 +1,120 @@
# The Module/Class Name: Message
In the swarms.agents framework, the class `Message` is used to represent a message with timestamp and optional metadata.
## Overview and Introduction
The `Message` class is a fundamental component that enables the representation of messages within an agent system. Messages contain essential information such as the sender, content, timestamp, and optional metadata.
## Class Definition
### Constructor: `__init__`
The constructor of the `Message` class takes three parameters:
1. `sender` (str): The sender of the message.
2. `content` (str): The content of the message.
3. `metadata` (dict or None): Optional metadata associated with the message.
### Methods
1. `__repr__(self)`: Returns a string representation of the `Message` object, including the timestamp, sender, and content.
```python
class Message:
"""
Represents a message with timestamp and optional metadata.
Usage
--------------
mes = Message(
sender = "Kye",
content = "message"
)
print(mes)
"""
def __init__(self, sender, content, metadata=None):
self.timestamp = datetime.datetime.now()
self.sender = sender
self.content = content
self.metadata = metadata or {}
def __repr__(self):
"""
__repr__ represents the string representation of the Message object.
Returns:
(str) A string containing the timestamp, sender, and content of the message.
"""
return f"{self.timestamp} - {self.sender}: {self.content}"
```
## Functionality and Usage
The `Message` class represents a message in the agent system. Upon initialization, the `timestamp` is set to the current date and time, and the `metadata` is set to an empty dictionary if no metadata is provided.
### Usage Example 1
Creating a `Message` object and displaying its string representation.
```python
mes = Message(
sender = "Kye",
content = "Hello! How are you?"
)
print(mes)
```
Output:
```
2023-09-20 13:45:00 - Kye: Hello! How are you?
```
### Usage Example 2
Creating a `Message` object with metadata.
```python
metadata = {"priority": "high", "category": "urgent"}
mes_with_metadata = Message(
sender = "Alice",
content = "Important update",
metadata = metadata
)
print(mes_with_metadata)
```
Output:
```
2023-09-20 13:46:00 - Alice: Important update
```
### Usage Example 3
Creating a `Message` object without providing metadata.
```python
mes_no_metadata = Message(
sender = "Bob",
content = "Reminder: Meeting at 2PM"
)
print(mes_no_metadata)
```
Output:
```
2023-09-20 13:47:00 - Bob: Reminder: Meeting at 2PM
```
## Additional Information and Tips
When creating a new `Message` object, ensure that the required parameters `sender` and `content` are provided. The `timestamp` will automatically be assigned the current date and time. Optional `metadata` can be included to provide additional context or information associated with the message.
## References and Resources
For further information on the `Message` class and its usage, refer to the official swarms.agents documentation and relevant tutorials related to message handling and communication within the agent system.

@ -0,0 +1,79 @@
# Module/Class Name: OmniModalAgent
The `OmniModalAgent` class is a module that operates based on the Language Model (LLM) aka Language Understanding Model, Plans, Tasks, and Tools. It is designed to be a multi-modal chatbot which uses various AI-based capabilities for fulfilling user requests.
It has the following architecture:
1. Language Model (LLM).
2. Chat Planner - Plans
3. Task Executor - Tasks
4. Tools - Tools
![OmniModalAgent](https://source.unsplash.com/random)
---
### Usage
from swarms import OmniModalAgent, OpenAIChat
llm = OpenAIChat()
agent = OmniModalAgent(llm)
response = agent.run("Hello, how are you? Create an image of how your are doing!")
---
---
### Initialization
The constructor of `OmniModalAgent` class takes two main parameters:
- `llm`: A `BaseLanguageModel` that represents the language model
- `tools`: A List of `BaseTool` instances that are used by the agent for fulfilling different requests.
```python
def __init__(
self,
llm: BaseLanguageModel,
# tools: List[BaseTool]
):
```
---
### Methods
The class has two main methods:
1. `run`: This method takes an input string and executes various plans and tasks using the provided tools. Ultimately, it generates a response based on the user's input and returns it.
- Parameters:
- `input`: A string representing the user's input text.
- Returns:
- A string representing the response.
Usage:
```python
response = agent.run("Hello, how are you? Create an image of how your are doing!")
```
2. `chat`: This method is used to simulate a chat dialog with the agent. It can take user's messages and return the response (or stream the response word-by-word if required).
- Parameters:
- `msg` (optional): A string representing the message to send to the agent.
- `streaming` (optional): A boolean specifying whether to stream the response.
- Returns:
- A string representing the response from the agent.
Usage:
```python
response = agent.chat("Hello")
```
---
### Streaming Response
The class provides a method `_stream_response` that can be used to get the response token by token (i.e. word by word). It yields individual tokens from the response.
Usage:
```python
for token in _stream_response(response):
print(token)
```

@ -0,0 +1,113 @@
# ToolAgent Documentation
### Overview and Introduction
The `ToolAgent` class represents an intelligent agent capable of performing a specific task using a pre-trained model and tokenizer. It leverages the Transformer models of the Hugging Face `transformers` library to generate outputs that adhere to a specific JSON schema. This provides developers with a flexible tool for creating bots, text generators, and conversational AI agents. The `ToolAgent` operates based on a JSON schema provided by you, the user. Using the schema, the agent applies the provided model and tokenizer to generate structured text data that matches the specified format.
The primary objective of the `ToolAgent` class is to amplify the efficiency of developers and AI practitioners by simplifying the process of generating meaningful outputs that navigate the complexities of the model and tokenizer.
### Class Definition
The `ToolAgent` class has the following definition:
```python
class ToolAgent(AbstractLLM):
def __init__(
self,
name: str,
description: str,
model: Any,
tokenizer: Any,
json_schema: Any,
*args,
**kwargs,
)
def run(self, task: str, *args, **kwargs)
def __call__(self, task: str, *args, **kwargs)
```
### Arguments
The `ToolAgent` class takes the following arguments:
| Argument | Type | Description |
| --- | --- | --- |
| name | str | The name of the tool agent.
| description | str | A description of the tool agent.
| model | Any | The model used by the tool agent (e.g., `transformers.AutoModelForCausalLM`).
| tokenizer | Any | The tokenizer used by the tool agent (e.g., `transformers.AutoTokenizer`).
| json_schema | Any | The JSON schema used by the tool agent.
| *args | - | Variable-length arguments.
| **kwargs | - | Keyword arguments.
### Methods
`ToolAgent` exposes the following methods:
#### `run(self, task: str, *args, **kwargs) -> Any`
- Description: Runs the tool agent for a specific task.
- Parameters:
- `task` (str): The task to be performed by the tool agent.
- `*args`: Variable-length argument list.
- `**kwargs`: Arbitrary keyword arguments.
- Returns: The output of the tool agent.
- Raises: Exception if an error occurs during the execution of the tool agent.
#### `__call__(self, task: str, *args, **kwargs) -> Any`
- Description: Calls the tool agent to perform a specific task.
- Parameters:
- `task` (str): The task to be performed by the tool agent.
- `*args`: Variable-length argument list.
- `**kwargs`: Arbitrary keyword arguments.
- Returns: The output of the tool agent.
### Usage Example
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from swarms import ToolAgent
# Creating a model and tokenizer
model = AutoModelForCausalLM.from_pretrained("databricks/dolly-v2-12b")
tokenizer = AutoTokenizer.from_pretrained("databricks/dolly-v2-12b")
# Defining a JSON schema
json_schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number"},
"is_student": {"type": "boolean"},
"courses": {
"type": "array",
"items": {"type": "string"}
}
}
}
# Defining a task
task = "Generate a person's information based on the following schema:"
# Creating the ToolAgent instance
agent = ToolAgent(model=model, tokenizer=tokenizer, json_schema=json_schema)
# Running the tool agent
generated_data = agent.run(task)
# Accessing and printing the generated data
print(generated_data)
```
### Additional Information and Tips
When using the `ToolAgent`, it is important to ensure compatibility between the provided model, tokenizer, and the JSON schema. Additionally, any errors encountered during the execution of the tool agent are propagated as exceptions. Handling such exceptions appropriately can improve the robustness of the tool agent usage.
### References and Resources
For further exploration and understanding of the underlying Transformer-based models and tokenizers, refer to the Hugging Face `transformers` library documentation and examples. Additionally, for JSON schema modeling, you can refer to the official JSON Schema specification and examples.
This documentation provides a comprehensive guide on using the `ToolAgent` class from `swarms` library, and it is recommended to refer back to this document when utilizing the `ToolAgent` for developing your custom conversational agents or text generation tools.

@ -0,0 +1,78 @@
# WorkerClass Documentation
## Overview
The Worker class represents an autonomous agent that can perform tasks through function calls or by running a chat. It can be used to create applications that demand effective user interactions like search engines, human-like conversational bots, or digital assistants.
The `Worker` class is part of the `swarms.agents` codebase. This module is largely used in Natural Language Processing (NLP) projects where the agent undertakes conversations and other language-specific operations.
## Class Definition
The class `Worker` has the following arguments:
| Argument | Type | Default Value | Description |
|-----------------------|---------------|----------------------------------|----------------------------------------------------|
| name | str | "Worker" | Name of the agent. |
| role | str | "Worker in a swarm" | Role of the agent. |
| external_tools | list | None | List of external tools available to the agent. |
| human_in_the_loop | bool | False | Determines whether human interaction is required. |
| temperature | float | 0.5 | Temperature for the autonomous agent. |
| llm | None | None | Language model. |
| openai_api_key | str | None | OpenAI API key. |
| tools | List[Any] | None | List of tools available to the agent. |
| embedding_size | int | 1536 | Size of the word embeddings. |
| search_kwargs | dict | {"k": 8} | Search parameters. |
| args | Multiple | | Additional arguments that can be passed. |
| kwargs | Multiple | | Additional keyword arguments that can be passed. |
## Usage
#### Example 1: Creating and Running an Agent
```python
from swarms import Worker
worker = Worker(
name="My Worker",
role="Worker",
external_tools=[MyTool1(), MyTool2()],
human_in_the_loop=False,
temperature=0.5,
llm=some_language_model,
openai_api_key="my_key"
)
worker.run("What's the weather in Miami?")
```
#### Example 2: Receiving and Sending Messages
```python
worker.receieve("User", "Hello there!")
worker.receieve("User", "Can you tell me something about history?")
worker.send()
```
#### Example 3: Setting up Tools
```python
external_tools = [MyTool1(), MyTool2()]
worker = Worker(
name="My Worker",
role="Worker",
external_tools=external_tools,
human_in_the_loop=False,
temperature=0.5,
)
```
## Additional Information and Tips
- The class allows the setting up of tools for the worker to operate effectively. It provides setup facilities for essential computing infrastructure, such as the agent's memory and language model.
- By setting the `human_in_the_loop` parameter to True, interactions with the worker can be made more user-centric.
- The `openai_api_key` argument can be provided for leveraging the OpenAI infrastructure and services.
- A qualified language model can be passed as an instance of the `llm` object, which can be useful when integrating with state-of-the-art text generation engines.
## References and Resources
- [OpenAI APIs](https://openai.com)
- [Models and Languages at HuggingFace](https://huggingface.co/models)
- [Deep Learning and Language Modeling at the Allen Institute for AI](https://allenai.org)

@ -1,4 +1,4 @@
# `PineconDB` Documentation
# `PineconeDB` Documentation
## Table of Contents

@ -28,7 +28,7 @@ pip install swarms
## Initialization
To use the Weaviate API Client, you need to initialize an instance of the `WeaviateClient` class. Here are the parameters you can pass to the constructor:
To use the Weaviate API Client, you need to initialize an instance of the `WeaviateDB` class. Here are the parameters you can pass to the constructor:
| Parameter | Type | Description |
|----------------------|----------------|----------------------------------------------------------------------------------------------------------------------------------|
@ -43,12 +43,12 @@ To use the Weaviate API Client, you need to initialize an instance of the `Weavi
| `additional_config` | Optional[weaviate.AdditionalConfig] | Additional configuration for the client. (Optional) |
| `connection_params` | Dict[str, Any] | Dictionary containing connection parameters. This parameter is used internally and can be ignored in most cases. |
Here's an example of how to initialize a WeaviateClient:
Here's an example of how to initialize a WeaviateDB:
```python
from swarms.memory import WeaviateClient
from swarms.memory import WeaviateDB
weaviate_client = WeaviateClient(
weaviate_client = WeaviateDB(
http_host="YOUR_HTTP_HOST",
http_port="YOUR_HTTP_PORT",
http_secure=True,

@ -0,0 +1,76 @@
# Module Name: Mixtral
## Introduction
The Mixtral module is a powerful language model designed for text generation tasks. It leverages the MistralAI Mixtral-8x7B pre-trained model to generate high-quality text based on user-defined tasks or prompts. In this documentation, we will provide a comprehensive overview of the Mixtral module, including its architecture, purpose, arguments, and detailed usage examples.
## Purpose
The Mixtral module is designed to facilitate text generation tasks using state-of-the-art language models. Whether you need to generate creative content, draft text for various applications, or simply explore the capabilities of Mixtral, this module serves as a versatile and efficient solution. With its easy-to-use interface, you can quickly generate text for a wide range of applications.
## Architecture
The Mixtral module is built on top of the MistralAI Mixtral-8x7B pre-trained model. It utilizes a deep neural network architecture with 8 layers and 7 attention heads to generate coherent and contextually relevant text. The model is capable of handling a variety of text generation tasks, from simple prompts to more complex content generation.
## Class Definition
### `Mixtral(model_name: str = "mistralai/Mixtral-8x7B-v0.1", max_new_tokens: int = 500)`
#### Parameters
- `model_name` (str, optional): The name or path of the pre-trained Mixtral model. Default is "mistralai/Mixtral-8x7B-v0.1".
- `max_new_tokens` (int, optional): The maximum number of new tokens to generate. Default is 500.
## Functionality and Usage
The Mixtral module offers a straightforward interface for text generation. It accepts a task or prompt as input and returns generated text based on the provided input.
### `run(task: Optional[str] = None, **kwargs) -> str`
#### Parameters
- `task` (str, optional): The task or prompt for text generation.
#### Returns
- `str`: The generated text.
## Usage Examples
### Example 1: Basic Usage
```python
from swarms.models import Mixtral
# Initialize the Mixtral model
mixtral = Mixtral()
# Generate text for a simple task
generated_text = mixtral.run("Generate a creative story.")
print(generated_text)
```
### Example 2: Custom Model
You can specify a custom pre-trained model by providing the `model_name` parameter.
```python
custom_model_name = "model_name"
mixtral_custom = Mixtral(model_name=custom_model_name)
generated_text = mixtral_custom.run("Generate text with a custom model.")
print(generated_text)
```
### Example 3: Controlling Output Length
You can control the length of the generated text by adjusting the `max_new_tokens` parameter.
```python
mixtral_length = Mixtral(max_new_tokens=100)
generated_text = mixtral_length.run("Generate a short text.")
print(generated_text)
```
## Additional Information and Tips
- It's recommended to use a descriptive task or prompt to guide the text generation process.
- Experiment with different prompt styles and lengths to achieve the desired output.
- You can fine-tune Mixtral on specific tasks if needed, although pre-trained models often work well out of the box.
- Monitor the `max_new_tokens` parameter to control the length of the generated text.
## Conclusion
The Mixtral module is a versatile tool for text generation tasks, powered by the MistralAI Mixtral-8x7B pre-trained model. Whether you need creative writing, content generation, or assistance with text-based tasks, Mixtral can help you achieve your goals. With a simple interface and flexible parameters, it's a valuable addition to your text generation toolkit.
If you encounter any issues or have questions about using Mixtral, please refer to the MistralAI documentation or reach out to their support team for further assistance. Happy text generation with Mixtral!

@ -0,0 +1,105 @@
# Module Name: ZeroscopeTTV
## Introduction
The ZeroscopeTTV module is a versatile zero-shot video generation model designed to create videos based on textual descriptions. This comprehensive documentation will provide you with an in-depth understanding of the ZeroscopeTTV module, its architecture, purpose, arguments, and detailed usage examples.
## Purpose
The ZeroscopeTTV module serves as a powerful tool for generating videos from text descriptions. Whether you need to create video content for various applications, visualize textual data, or explore the capabilities of ZeroscopeTTV, this module offers a flexible and efficient solution. With its easy-to-use interface, you can quickly generate videos based on your textual input.
## Architecture
The ZeroscopeTTV module is built on top of the Diffusers library, leveraging the power of diffusion models for video generation. It allows you to specify various parameters such as model name, data type, chunk size, dimensions, and more to customize the video generation process. The model performs multiple inference steps and utilizes a diffusion pipeline to generate high-quality videos.
## Class Definition
### `ZeroscopeTTV(model_name: str = "cerspense/zeroscope_v2_576w", torch_dtype=torch.float16, chunk_size: int = 1, dim: int = 1, num_inference_steps: int = 40, height: int = 320, width: int = 576, num_frames: int = 36)`
#### Parameters
- `model_name` (str, optional): The name of the pre-trained model to use. Default is "cerspense/zeroscope_v2_576w".
- `torch_dtype` (torch.dtype, optional): The torch data type to use for computations. Default is torch.float16.
- `chunk_size` (int, optional): The size of chunks for forward chunking. Default is 1.
- `dim` (int, optional): The dimension along which the input is split for forward chunking. Default is 1.
- `num_inference_steps` (int, optional): The number of inference steps to perform. Default is 40.
- `height` (int, optional): The height of the video frames. Default is 320.
- `width` (int, optional): The width of the video frames. Default is 576.
- `num_frames` (int, optional): The number of frames in the video. Default is 36.
## Functionality and Usage
The ZeroscopeTTV module offers a straightforward interface for video generation. It accepts a textual task or description as input and returns the path to the generated video.
### `run(task: str = None, *args, **kwargs) -> str`
#### Parameters
- `task` (str, optional): The input task or description for video generation.
#### Returns
- `str`: The path to the generated video.
## Usage Examples
### Example 1: Basic Usage
```python
from swarms.models import ZeroscopeTTV
# Initialize the ZeroscopeTTV model
zeroscope = ZeroscopeTTV()
# Generate a video based on a textual description
task = "A bird flying in the sky."
video_path = zeroscope.run(task)
print(f"Generated video path: {video_path}")
```
### Example 2: Custom Model and Parameters
You can specify a custom pre-trained model and adjust various parameters for video generation.
```python
custom_model_name = "your_custom_model_path"
custom_dtype = torch.float32
custom_chunk_size = 2
custom_dim = 2
custom_num_inference_steps = 50
custom_height = 480
custom_width = 720
custom_num_frames = 48
custom_zeroscope = ZeroscopeTTV(
model_name=custom_model_name,
torch_dtype=custom_dtype,
chunk_size=custom_chunk_size,
dim=custom_dim,
num_inference_steps=custom_num_inference_steps,
height=custom_height,
width=custom_width,
num_frames=custom_num_frames,
)
task = "A car driving on the road."
video_path = custom_zeroscope.run(task)
print(f"Generated video path: {video_path}")
```
### Example 3: Exporting Video Frames
You can also export individual video frames if needed.
```python
from swarms.models import export_to_video
# Generate video frames
video_frames = zeroscope.run("A boat sailing on the water.")
# Export video frames to a video file
video_path = export_to_video(video_frames)
print(f"Generated video path: {video_path}")
```
## Additional Information and Tips
- Ensure that the input textual task or description is clear and descriptive to achieve the desired video output.
- Experiment with different parameter settings to control video resolution, frame count, and inference steps.
- Use the `export_to_video` function to export individual video frames as needed.
- Monitor the progress and output paths to access the generated videos.
## Conclusion
The ZeroscopeTTV module is a powerful solution for zero-shot video generation based on textual descriptions. Whether you are creating videos for storytelling, data visualization, or other applications, ZeroscopeTTV offers a versatile and efficient way to bring your text to life. With a flexible interface and customizable parameters, it empowers you to generate high-quality videos with ease.
If you encounter any issues or have questions about using ZeroscopeTTV, please refer to the Diffusers library documentation or reach out to their support team for further assistance. Enjoy creating videos with ZeroscopeTTV!

@ -0,0 +1,106 @@
# swarms.structs Documentation
## Introduction
The swarms.structs library provides a collection of classes for representing artifacts and their attributes. This documentation will provide an overview of the `Artifact` class, its attributes, functionality, and usage examples.
### Artifact Class
The `Artifact` class represents an artifact and its attributes. It inherits from the `BaseModel` class and includes the following attributes:
#### Attributes
1. `artifact_id (str)`: Id of the artifact.
2. `file_name (str)`: Filename of the artifact.
3. `relative_path (str, optional)`: Relative path of the artifact in the agent's workspace.
These attributes are crucial for identifying and managing different artifacts within a given context.
## Class Definition
The `Artifact` class can be defined as follows:
```python
class Artifact(BaseModel):
"""
Represents an artifact.
Attributes:
artifact_id (str): Id of the artifact.
file_name (str): Filename of the artifact.
relative_path (str, optional): Relative path of the artifact in the agent's workspace.
"""
artifact_id: str = Field(
...,
description="Id of the artifact",
example="b225e278-8b4c-4f99-a696-8facf19f0e56",
)
file_name: str = Field(
..., description="Filename of the artifact", example="main.py"
)
relative_path: Optional[str] = Field(
None,
description=(
"Relative path of the artifact in the agent's workspace"
),
example="python/code/",
)
```
The `Artifact` class defines the mandatory and optional attributes and provides corresponding descriptions along with example values.
## Functionality and Usage
The `Artifact` class encapsulates the information and attributes representing an artifact. It provides a structured and organized way to manage artifacts within a given context.
### Example 1: Creating an Artifact instance
To create an instance of the `Artifact` class, you can simply initialize it with the required attributes. Here's an example:
```python
from swarms.structs import Artifact
artifact_instance = Artifact(
artifact_id="b225e278-8b4c-4f99-a696-8facf19f0e56",
file_name="main.py",
relative_path="python/code/"
)
```
In this example, we create an instance of the `Artifact` class with the specified artifact details.
### Example 2: Accessing Artifact attributes
You can access the attributes of the `Artifact` instance using dot notation. Here's how you can access the file name of the artifact:
```python
print(artifact_instance.file_name)
# Output: "main.py"
```
### Example 3: Handling optional attributes
If the `relative_path` attribute is not provided during artifact creation, it will default to `None`. Here's an example:
```python
artifact_instance_no_path = Artifact(
artifact_id="c280s347-9b7d-3c68-m337-7abvf50j23k",
file_name="script.js"
)
print(artifact_instance_no_path.relative_path)
# Output: None
```
By providing default values for optional attributes, the `Artifact` class allows flexibility in defining artifact instances.
### Additional Information and Tips
The `Artifact` class represents a powerful and flexible means of handling various artifacts with different attributes. By utilizing this class, users can organize, manage, and streamline their artifacts with ease.
## References and Resources
For further details and references related to the swarms.structs library and the `Artifact` class, refer to the [official documentation](https://swarms.structs.docs/artifact.html).
This comprehensive documentation provides an in-depth understanding of the `Artifact` class, its attributes, functionality, and usage examples. By following the detailed examples and explanations, developers can effectively leverage the capabilities of the `Artifact` class within their projects.

@ -0,0 +1,49 @@
# swarms.structs
## Overview
Swarms is a library that provides tools for managing a distributed system of agents working together to achieve a common goal. The structs module within Swarms provides a set of data structures and classes that are used to represent artifacts, tasks, and other entities within the system. The `ArtifactUpload` class is one such data structure that represents the process of uploading an artifact to an agent's workspace.
## ArtifactUpload
The `ArtifactUpload` class inherits from the `BaseModel` class. It has two attributes: `file` and `relative_path`. The `file` attribute represents the bytes of the file to be uploaded, while the `relative_path` attribute represents the relative path of the artifact in the agent's workspace.
### Class Definition
```python
class ArtifactUpload(BaseModel):
file: bytes = Field(..., description="File to upload")
relative_path: Optional[str] = Field(
None,
description=(
"Relative path of the artifact in the agent's workspace"
),
example="python/code/",
)
```
The `ArtifactUpload` class requires the `file` attribute to be passed as an argument. It is of type `bytes` and represents the file to be uploaded. The `relative_path` attribute is optional and is of type `str`. It represents the relative path of the artifact in the agent's workspace. If not provided, it defaults to `None`.
### Functionality and Usage
The `ArtifactUpload` class is used to create an instance of an artifact upload. It can be instantiated with or without a `relative_path`. Here is an example of how the class can be used:
```python
from swarms.structs import ArtifactUpload
# Uploading a file with no relative path
upload_no_path = ArtifactUpload(file=b'example_file_contents')
# Uploading a file with a relative path
upload_with_path = ArtifactUpload(file=b'example_file_contents', relative_path="python/code/")
```
In the above example, `upload_no_path` is an instance of `ArtifactUpload` with no specified `relative_path`, whereas `upload_with_path` is an instance of `ArtifactUpload` with the `relative_path` set to "python/code/".
### Additional Information
When passing the `file` and `relative_path` parameters to the `ArtifactUpload` class, ensure that the `file` parameter is provided exactly as the file that needs to be uploaded, represented as a `bytes` object. If a `relative_path` is provided, ensure that it is a valid path within the agent's workspace.
# Conclusion
The `ArtifactUpload` class is an essential data structure within the Swarms library that represents the process of uploading an artifact to an agent's workspace. By using this class, users can easily manage and represent artifact uploads within the Swarms distributed system.

@ -0,0 +1,137 @@
# Module/Function Name: BaseStructure
## Introduction:
The `BaseStructure` module contains the basic structure and attributes required for running machine learning models and associated metadata, error logging, artifact saving/loading, and relevant event logging.
The module provides the flexibility to save and load the model metadata, log errors, save artifacts, and maintain a log for multiple events associated with multiple threads and batched operations. The key attributes of the module include **name**, **description**, **save_metadata_path**, and **save_error_path**.
## Class Definition:
### Arguments:
| Argument | Type | Description |
|----------------------|--------|----------------------------------------------------------------------|
| name | str | (Optional) The name of the structure. |
| description | str | (Optional) A description of the structure. |
| save_metadata | bool | A boolean flag to enable or disable metadata saving. |
| save_artifact_path | str | (Optional) The path to save artifacts. |
| save_metadata_path | str | (Optional) The path to save metadata. |
| save_error_path | str | (Optional) The path to save errors. |
## Methods:
### 1. run
Runs the structure.
### 2. save_to_file
Saves data to a file.
* **data**: Value to be saved.
* **file_path**: Path where the data is to be saved.
### 3. load_from_file
Loads data from a file.
* **file_path**: Path from where the data is to be loaded.
### 4. save_metadata
Saves metadata to a file.
* **metadata**: Data to be saved as metadata.
### 5. load_metadata
Loads metadata from a file.
### 6. log_error
Logs error to a file.
### 7. save_artifact
Saves artifact to a file.
* **artifact**: The artifact to be saved.
* **artifact_name**: Name of the artifact.
### 8. load_artifact
Loads artifact from a file.
* **artifact_name**: Name of the artifact.
### 9. log_event
Logs an event to a file.
* **event**: The event to be logged.
* **event_type**: Type of the event (optional, defaults to "INFO").
### 10. run_async
Runs the structure asynchronously.
### 11. save_metadata_async
Saves metadata to a file asynchronously.
### 12. load_metadata_async
Loads metadata from a file asynchronously.
### 13. log_error_async
Logs error to a file asynchronously.
### 14. save_artifact_async
Saves artifact to a file asynchronously.
### 15. load_artifact_async
Loads artifact from a file asynchronously.
### 16. log_event_async
Logs an event to a file asynchronously.
### 17. asave_to_file
Saves data to a file asynchronously.
### 18. aload_from_file
Loads data from a file asynchronously.
### 19. run_concurrent
Runs the structure concurrently.
### 20. compress_data
Compresses data.
### 21. decompres_data
Decompresses data.
### 22. run_batched
Runs batched data.
## Examples:
### Example 1: Saving Metadata
```python
base_structure = BaseStructure(name="ExampleStructure")
metadata = {"key1": "value1", "key2": "value2"}
base_structure.save_metadata(metadata)
```
### Example 2: Loading Artifact
```python
artifact_name = "example_artifact"
artifact_data = base_structure.load_artifact(artifact_name)
```
### Example 3: Running Concurrently
```python
concurrent_data = [data1, data2, data3]
results = base_structure.run_concurrent(batched_data=concurrent_data)
```
## Note:
The `BaseStructure` class is designed to provide a modular and extensible structure for managing metadata, logs, errors, and batched operations while running machine learning models. The class's methods offer asynchronous and concurrent execution capabilities, thus optimizing the performance of the associated applications and models. The module's attributes and methods cater to a wide range of use cases, making it an essential foundational component for machine learning and data-based applications.
# Conclusion:
The `BaseStructure` module offers a robust and flexible foundation for managing machine learning model metadata, error logs, and event tracking, including asynchronous, concurrent, and batched operations. By leveraging the inherent capabilities of this class, developers can enhance the reliability, scalability, and performance of machine learning-based applications.
## References:
- [Python Concurrent Programming with `asyncio`](https://docs.python.org/3/library/asyncio.html)
- [Understanding Thread Pool Executor in Python](https://docs.python.org/3/library/concurrent.futures.html#executor-objects)
- [Documentation on `gzip` Module for Data Compression](https://docs.python.org/3/library/gzip.html)
---
The above documentation provides detailed information about the `BaseStructure` module, including its functionality, attributes, methods, usage examples, and references to relevant resources for further exploration. This comprehensive documentation aims to deepen the users' understanding of the module's purpose and how it can be effectively utilized in practice.
Please let me know if you need further elaboration on any specific aspect or functionality of the `BaseStructure` module.

@ -0,0 +1,42 @@
### swarms.modules.structs
`Class Name: BaseWorkflow`
Base class for workflows.
`Attributes`
- Task_pool (list): A list to store tasks.
`Methods`
- Add(task: Task = None, tasks: List[Task] = None, *args, **kwargs): Adds a task or a list of tasks to the task pool.
- Run(): Abstract method to run the workflow.
Source Code:
```python
class BaseWorkflow(BaseStructure):
"""
Base class for workflows.
Attributes:
task_pool (list): A list to store tasks.
Methods:
add(task: Task = None, tasks: List[Task] = None, *args, **kwargs):
Adds a task or a list of tasks to the task pool.
run():
Abstract method to run the workflow.
"""
```
For the usage examples and additional in-depth documentation please visit [BaseWorkflow](https://github.com/swarms-modules/structs/blob/main/baseworkflow.md#swarms-structs)
Explanation:
Initially, the `BaseWorkflow` class is a class designed to handle workflows. It contains a list within the task pool to handle various tasks and run methods. In the current structure, there are a few in-built methods such as `add`, `run`, `__sequential_loop`, `__log`, `reset`, `get_task_results`, `remove_task`, `update_task`, `delete_task`, `save_workflow_state`, `add_objective_to_workflow`, and `load_workflow_state`, each serving a unique purpose.
The `add` method functions to add tasks or a list of tasks to the task pool while the `run` method is left as an abstract method for initializing the workflow. Considering the need to run the workflow, `__sequential_loop` is another abstract method. In cases where the user desires to log messages, `__log` can be utilized. For resetting the workflow, there is a `reset` method, complemented by `get_task_results` that returns the results of each task in the workflow. To remove a task from the workflow, `remove_task` can be employed.
In cases where an update is required for the tasks in the workflow, `update_task` comes in handy. Deleting a task from the workflow can be achieved using the `delete_task` method. The method saves the workflows state to a JSON file, and the user can fix the path where the file resides. For adding objectives to the workflow, `add_objective_to_workflow` can be employed, and there is an abstract method of `load_workflow_state` for loading the workflow state from a JSON file providing the freedom to revert the workflow to a specific state.
The class also has a method `__str__` and `__repr__` to represent the text and instantiate an object of the class, respectively. The object can be reset, task results obtained, tasks removed, tasks updated, tasks deleted, or workflow state saved. The structure provides detailed methods for altering the workflow at every level.

@ -0,0 +1,77 @@
```
# Module/Function Name: ConcurrentWorkflow
class swarms.structs.ConcurrentWorkflow(max_workers, autosave, saved_state_filepath):
"""
ConcurrentWorkflow class for running a set of tasks concurrently using N autonomous agents.
Args:
- max_workers (int): The maximum number of workers to use for concurrent execution.
- autosave (bool): Whether to autosave the workflow state.
- saved_state_filepath (Optional[str]): The file path to save the workflow state.
"""
def add(self, task, tasks=None):
"""Adds a task to the workflow.
Args:
- task (Task): Task to add to the workflow.
- tasks (List[Task]): List of tasks to add to the workflow (optional).
"""
try:
# Implementation of the function goes here
except Exception as error:
print(f"[ERROR][ConcurrentWorkflow] {error}")
raise error
def run(self, print_results=False, return_results=False):
"""
Executes the tasks in parallel using a ThreadPoolExecutor.
Args:
- print_results (bool): Whether to print the results of each task. Default is False.
- return_results (bool): Whether to return the results of each task. Default is False.
Returns:
- (List[Any]): A list of the results of each task, if return_results is True. Otherwise, returns None.
"""
try:
# Implementation of the function goes here
except Exception as e:
print(f"Task {task} generated an exception: {e}")
return results if self.return_results else None
def _execute_task(self, task):
"""Executes a task.
Args:
- task (Task): Task to execute.
Returns:
- result: The result of executing the task.
"""
try:
# Implementation of the function goes here
except Exception as error:
print(f"[ERROR][ConcurrentWorkflow] {error}")
raise error
# Usage example:
from swarms.models import OpenAIChat
from swarms.structs import ConcurrentWorkflow
llm = OpenAIChat(openai_api_key="")
workflow = ConcurrentWorkflow(max_workers=5)
workflow.add("What's the weather in miami", llm)
workflow.add("Create a report on these metrics", llm)
workflow.run()
workflow.tasks
"""
```

@ -0,0 +1,265 @@
# Module/Class Name: Conversation
## Introduction
The `Conversation` class is a powerful tool for managing and structuring conversation data in a Python program. It enables you to create, manipulate, and analyze conversations easily. This documentation will provide you with a comprehensive understanding of the `Conversation` class, its attributes, methods, and how to effectively use it.
## Table of Contents
1. **Class Definition**
- Overview
- Attributes
2. **Methods**
- `__init__(self, time_enabled: bool = False, *args, **kwargs)`
- `add(self, role: str, content: str, *args, **kwargs)`
- `delete(self, index: str)`
- `update(self, index: str, role, content)`
- `query(self, index: str)`
- `search(self, keyword: str)`
- `display_conversation(self, detailed: bool = False)`
- `export_conversation(self, filename: str)`
- `import_conversation(self, filename: str)`
- `count_messages_by_role(self)`
- `return_history_as_string(self)`
- `save_as_json(self, filename: str)`
- `load_from_json(self, filename: str)`
- `search_keyword_in_conversation(self, keyword: str)`
- `pretty_print_conversation(self, messages)`
---
### 1. Class Definition
#### Overview
The `Conversation` class is designed to manage conversations by keeping track of messages and their attributes. It offers methods for adding, deleting, updating, querying, and displaying messages within the conversation. Additionally, it supports exporting and importing conversations, searching for specific keywords, and more.
#### Attributes
- `time_enabled (bool)`: A flag indicating whether to enable timestamp recording for messages.
- `conversation_history (list)`: A list that stores messages in the conversation.
### 2. Methods
#### `__init__(self, time_enabled: bool = False, *args, **kwargs)`
- **Description**: Initializes a new Conversation object.
- **Parameters**:
- `time_enabled (bool)`: If `True`, timestamps will be recorded for each message. Default is `False`.
#### `add(self, role: str, content: str, *args, **kwargs)`
- **Description**: Adds a message to the conversation history.
- **Parameters**:
- `role (str)`: The role of the speaker (e.g., "user," "assistant").
- `content (str)`: The content of the message.
#### `delete(self, index: str)`
- **Description**: Deletes a message from the conversation history.
- **Parameters**:
- `index (str)`: The index of the message to delete.
#### `update(self, index: str, role, content)`
- **Description**: Updates a message in the conversation history.
- **Parameters**:
- `index (str)`: The index of the message to update.
- `role (_type_)`: The new role of the speaker.
- `content (_type_)`: The new content of the message.
#### `query(self, index: str)`
- **Description**: Retrieves a message from the conversation history.
- **Parameters**:
- `index (str)`: The index of the message to query.
- **Returns**: The message as a string.
#### `search(self, keyword: str)`
- **Description**: Searches for messages containing a specific keyword in the conversation history.
- **Parameters**:
- `keyword (str)`: The keyword to search for.
- **Returns**: A list of messages that contain the keyword.
#### `display_conversation(self, detailed: bool = False)`
- **Description**: Displays the conversation history.
- **Parameters**:
- `detailed (bool, optional)`: If `True`, provides detailed information about each message. Default is `False`.
#### `export_conversation(self, filename: str)`
- **Description**: Exports the conversation history to a text file.
- **Parameters**:
- `filename (str)`: The name of the file to export to.
#### `import_conversation(self, filename: str)`
- **Description**: Imports a conversation history from a text file.
- **Parameters**:
- `filename (str)`: The name of the file to import from.
#### `count_messages_by_role(self)`
- **Description**: Counts the number of messages by role in the conversation.
- **Returns**: A dictionary containing the count of messages for each role.
#### `return_history_as_string(self)`
- **Description**: Returns the entire conversation history as a single string.
- **Returns**: The conversation history as a string.
#### `save_as_json(self, filename: str)`
- **Description**: Saves the conversation history as a JSON file.
- **Parameters**:
- `filename (str)`: The name of the JSON file to save.
#### `load_from_json(self, filename: str)`
- **Description**: Loads a conversation history from a JSON file.
- **Parameters**:
- `filename (str)`: The name of the JSON file to load.
#### `search_keyword_in_conversation(self, keyword: str)`
- **Description**: Searches for a keyword in the conversation history and returns matching messages.
- **Parameters**:
- `keyword (str)`: The keyword to search for.
- **Returns**: A list of messages containing the keyword.
#### `pretty_print_conversation(self, messages)`
- **Description**: Pretty prints a list of messages with colored role indicators.
- **Parameters**:
- `messages (list)`: A list of messages to print.
## Examples
Here are some usage examples of the `Conversation` class:
### Creating a Conversation
```python
from swarms.structs import Conversation
conv = Conversation()
```
### Adding Messages
```python
conv.add("user", "Hello, world!")
conv.add("assistant", "Hello, user!")
```
### Displaying the Conversation
```python
conv.display_conversation()
```
### Searching for Messages
```python
result = conv.search("Hello")
```
### Exporting and Importing Conversations
```python
conv.export_conversation("conversation.txt")
conv.import_conversation("conversation.txt")
```
### Counting Messages by Role
```python
counts = conv.count_messages_by_role()
```
### Loading and Saving as JSON
```python
conv.save_as_json("conversation.json")
conv.load_from_json("conversation.json")
```
Certainly! Let's continue with more examples and additional information about the `Conversation` class.
### Querying a Specific Message
You can retrieve a specific message from the conversation by its index:
```python
message = conv.query(0) # Retrieves the first message
```
### Updating a Message
You can update a message's content or role within the conversation:
```python
conv.update(0, "user", "Hi there!") # Updates the first message
```
### Deleting a Message
If you want to remove a message from the conversation, you can use the `delete` method:
```python
conv.delete(0) # Deletes the first message
```
### Counting Messages by Role
You can count the number of messages by role in the conversation:
```python
counts = conv.count_messages_by_role()
# Example result: {'user': 2, 'assistant': 2}
```
### Exporting and Importing as Text
You can export the conversation to a text file and later import it:
```python
conv.export_conversation("conversation.txt") # Export
conv.import_conversation("conversation.txt") # Import
```
### Exporting and Importing as JSON
Conversations can also be saved and loaded as JSON files:
```python
conv.save_as_json("conversation.json") # Save as JSON
conv.load_from_json("conversation.json") # Load from JSON
```
### Searching for a Keyword
You can search for messages containing a specific keyword within the conversation:
```python
results = conv.search_keyword_in_conversation("Hello")
```
### Pretty Printing
The `pretty_print_conversation` method provides a visually appealing way to display messages with colored role indicators:
```python
conv.pretty_print_conversation(conv.conversation_history)
```
These examples demonstrate the versatility of the `Conversation` class in managing and interacting with conversation data. Whether you're building a chatbot, conducting analysis, or simply organizing dialogues, this class offers a robust set of tools to help you accomplish your goals.
## Conclusion
The `Conversation` class is a valuable utility for handling conversation data in Python. With its ability to add, update, delete, search, export, and import messages, you have the flexibility to work with conversations in various ways. Feel free to explore its features and adapt them to your specific projects and applications.
If you have any further questions or need additional assistance, please don't hesitate to ask!

@ -0,0 +1,147 @@
# Module Name: Group Chat
The `GroupChat` class is used to create a group chat containing a list of agents. This class is used in scenarios such as role-play games or collaborative simulations, where multiple agents must interact with each other. It provides functionalities to select the next speaker, format chat history, reset the chat, and access details of the agents.
## Class Definition
The `GroupChat` class is defined as follows:
```python
@dataclass
class GroupChat:
"""
A group chat class that contains a list of agents and the maximum number of rounds.
Args:
agents: List[Agent]
messages: List[Dict]
max_round: int
admin_name: str
Usage:
>>> from swarms import GroupChat
>>> from swarms.structs.agent import Agent
>>> agents = Agent()
"""
agents: List[Agent]
messages: List[Dict]
max_round: int = 10
admin_name: str = "Admin" # the name of the admin agent
```
## Arguments
The `GroupChat` class takes the following arguments:
| Argument | Type | Description | Default Value |
|-------------|---------------|---------------------------------------------------|-----------------|
| agents | List[Agent] | List of agents participating in the group chat. | |
| messages | List[Dict] | List of messages exchanged in the group chat. | |
| max_round | int | Maximum number of rounds for the group chat. | 10 |
| admin_name | str | Name of the admin agent. | "Admin" |
## Methods
1. **agent_names**
- Returns the names of the agents in the group chat.
- Returns: List of strings.
2. **reset**
- Resets the group chat, clears all the messages.
3. **agent_by_name**
- Finds an agent in the group chat by their name.
- Arguments: name (str) - Name of the agent to search for.
- Returns: Agent - The agent with the matching name.
- Raises: ValueError if no matching agent is found.
4. **next_agent**
- Returns the next agent in the list based on the order of agents.
- Arguments: agent (Agent) - The current agent.
- Returns: Agent - The next agent in the list.
5. **select_speaker_msg**
- Returns the message for selecting the next speaker.
6. **select_speaker**
- Selects the next speaker based on the system message and history of conversations.
- Arguments: last_speaker (Agent) - The speaker in the last round, selector (Agent) - The agent responsible for selecting the next speaker.
- Returns: Agent - The agent selected as the next speaker.
7. **_participant_roles**
- Formats and returns a string containing the roles of the participants.
- (Internal method, not intended for direct usage)
8. **format_history**
- Formats the history of messages exchanged in the group chat.
- Arguments: messages (List[Dict]) - List of messages.
- Returns: str - Formatted history of messages.
## Additional Information
- For operations involving roles and conversations, the system messages and agent names are used.
- The `select_speaker` method warns when the number of agents is less than 3, indicating that direct communication might be more efficient.
## Usage Example 1
```Python
from swarms import GroupChat
from swarms.structs.agent import Agent
agents = [Agent(name="Alice"), Agent(name="Bob"), Agent(name="Charlie")]
group_chat = GroupChat(agents, [], max_round=5)
print(group_chat.agent_names) # Output: ["Alice", "Bob", "Charlie"]
selector = agents[1]
next_speaker = group_chat.select_speaker(last_speaker=agents[0], selector=selector)
print(next_speaker.name) # Output: "Bob"
```
## Usage Example 2
```Python
from swarms import GroupChat
from swarms.structs.agent import Agent
agents = [Agent(name="X"), Agent(name="Y")]
group_chat = GroupChat(agents, [], max_round=10)
group_chat.messages.append({"role": "X", "content": "Hello Y!"})
group_chat.messages.append({"role": "Y", "content": "Hi X!"})
formatted_history = group_chat.format_history(group_chat.messages)
print(formatted_history)
"""
Output:
'X: Hello Y!
Y: Hi X!'
"""
agent_charlie = Agent(name="Charlie")
group_chat.agents.append(agent_charlie)
print(group_chat.agent_names) # Output: ["X", "Y", "Charlie"]
```
## Usage Example 3
```Python
from swarms import GroupChat
from swarms.structs.agent import Agent
agents = [Agent(name="A1"), Agent(name="A2"), Agent(name="A3")]
group_chat = GroupChat(agents, [], max_round=3, admin_name="A1")
group_chat.reset()
print(group_chat.messages) # Output: []
```
## References
1. [Swarms Documentation](https://docs.swarms.org/)
2. [Role-Based Conversations in Multi-Agent Systems](https://arxiv.org/abs/2010.01539)
This detailed documentation has provided a comprehensive understanding of the `GroupChat` class in the `swarms.structs` module of the `swarms` library. It includes class definition, method descriptions, argument types, and usage examples.
*(Sample Documentation - 950 words)*

@ -0,0 +1,92 @@
# GroupChatManager
Documentation:
The `GroupChatManager` class is designed for managing group chat interactions between agents. It allows you to create and manage group chats among multiple agents. The `GroupChatManager` requires two main arguments - the `groupchat` of type `GroupChat` which indicates the actual group chat object and `selector` of type `Agent` which specifies the agent who is the selector or the initiator of the chat.
This class provides a variety of features and functions such as maintaining and appending messages, managing the communication rounds, interacting between different agents and extracting replies.
Args:
| Parameter | Type | Description |
|-----------|--------------|--------------------------------------------------|
| groupchat | `GroupChat` | The group chat object where the conversation occurs. |
| selector | `Agent` | The agent who is the selector or the initiator of the chat. |
Usage:
```python
from swarms import GroupChatManager
from swarms.structs.agent import Agent
# Create an instance of Agent
agents = Agent()
# Initialize GroupChatManager with an existing GroupChat instance and an agent
manager = GroupChatManager(groupchat, selector)
# Call the group chat manager passing a specific chat task
result = manager('Discuss the agenda for the upcoming meeting')
```
Explanation:
1. First, you import the `GroupChatManager` class and the `Agent` class from the `swarms` library.
2. Then, you create an instance of the `Agent`.
3. After that, you initialize the `GroupChatManager` with an existing `GroupChat` instance and an agent.
4. Finally, you call the group chat manager, passing a specific chat task and receive the response.
Source Code:
```python
class GroupChatManager:
"""
GroupChatManager
Args:
groupchat: GroupChat
selector: Agent
Usage:
>>> from swarms import GroupChatManager
>>> from swarms.structs.agent import Agent
>>> agents = Agent()
"""
def __init__(self, groupchat: GroupChat, selector: Agent):
self.groupchat = groupchat
self.selector = selector
def __call__(self, task: str):
"""Call 'GroupChatManager' instance as a function.
Args:
task (str): The task to be performed during the group chat.
Returns:
str: The response from the group chat.
"""
self.groupchat.messages.append(
{"role": self.selector.name, "content": task}
)
for i in range(self.groupchat.max_round):
speaker = self.groupchat.select_speaker(
last_speaker=self.selector, selector=self.selector
)
reply = speaker.generate_reply(
self.groupchat.format_history(self.groupchat.messages)
)
self.groupchat.messages.append(reply)
print(reply)
if i == self.groupchat.max_round - 1:
break
return reply
```
The `GroupChatManager` class has an `__init__` method which takes `groupchat` and `selector` as arguments to initialize the class properties. It also has a `__call__` method to perform the group chat task and provide the appropriate response.
In the `__call__` method, it appends the message with the speakers role and their content. It then iterates over the communication rounds, selects speakers, generates replies and appends messages to the group chat. Finally, it returns the response.
The above example demonstrates how to use the `GroupChatManager` class to manage group chat interactions. You can further customize this class based on specific requirements and extend its functionality as needed.

@ -0,0 +1,96 @@
#### Class Name: NonlinearWorkflow
This class represents a Directed Acyclic Graph (DAG) workflow used to store tasks and their dependencies in a workflow. The structures can validate, execute and store the order of tasks present in the workflow. It has the following attributes and methods:
#### Attributes:
- `tasks` (dict): A dictionary mapping task names to Task objects.
- `edges` (dict): A dictionary mapping task names to a list of dependencies.
- `stopping_token` (str): The token which denotes the end condition for the workflow execution. Default: `<DONE>`
#### Methods:
1. `__init__(self, stopping_token: str = "<DONE>")`: The initialization method that sets up the NonlinearWorkflow object with an optional stopping token. This token marks the end of the workflow.
- **Args**:
- `stopping_token` (str): The token to denote the end condition for the workflow execution.
2. `add(task: Task, *dependencies: str)`: Adds a task to the workflow along with its dependencies. This method is used to add a new task to the workflow with an optional list of dependency tasks.
- **Args**:
- `task` (Task): The task to be added.
- `dependencies` (varargs): Variable number of dependency task names.
- **Returns**: None
3. `run()`: This method runs the workflow by executing tasks in topological order. It runs the tasks according to the sequence of dependencies.
- **Raises**:
- `Exception`: If a circular dependency is detected.
- **Returns**: None
#### Examples:
Usage Example 1:
```python
from swarms.models import OpenAIChat
from swarms.structs import NonlinearWorkflow, Task
# Initialize the OpenAIChat model
llm = OpenAIChat(openai_api_key="")
# Create a new Task
task = Task(llm, "What's the weather in Miami")
# Initialize the NonlinearWorkflow
workflow = NonlinearWorkflow()
# Add task to the workflow
workflow.add(task)
# Execute the workflow
workflow.run()
```
Usage Example 2:
```python
from swarms.models import OpenAIChat
from swarms.structs import NonlinearWorkflow, Task
# Initialize the OpenAIChat model
llm = OpenAIChat(openai_api_key="")
# Create new Tasks
task1 = Task(llm, "What's the weather in Miami")
task2 = Task(llm, "Book a flight to New York")
task3 = Task(llm, "Find a hotel in Paris")
# Initialize the NonlinearWorkflow
workflow = NonlinearWorkflow()
# Add tasks to the workflow with dependencies
workflow.add(task1, task2.name)
workflow.add(task2, task3.name)
workflow.add(task3, "OpenAIChat Initialization")
# Execute the workflow
workflow.run()
```
Usage Example 3:
```python
from swarms.models import OpenAIChat
from swarms.structs import NonlinearWorkflow, Task
# Initialize the OpenAIChat model
llm = OpenAIChat(openai_api_key="")
# Create new Tasks
task1 = Task(llm, "What's the weather in Miami")
task2 = Task(llm, "Book a flight to New York")
task3 = Task(llm, "Find a hotel in Paris")
# Initialize the NonlinearWorkflow
workflow = NonlinearWorkflow()
# Add tasks to the workflow with dependencies
workflow.add(task1)
workflow.add(task2, task1.name)
workflow.add(task3, task1.name, task2.name)
# Execute the workflow
workflow.run()
```
These examples illustrate the three main types of usage for the NonlinearWorkflow class and how it can be used to represent a directed acyclic graph (DAG) workflow with tasks and their dependencies.
---
The explanatory documentation details the architectural aspects, methods, attributes, examples, and usage patterns for the `NonlinearWorkflow` class. By following the module and function definition structure, the documentation provides clear and comprehensive descriptions of the class and its functionalities.

@ -0,0 +1,23 @@
**Module/Function Name: RecursiveWorkflow**
`class` RecursiveWorkflow(BaseStructure):
Creates a recursive workflow structure for executing a task until a stated stopping condition is reached.
#### Parameters
* *task* (`Task`): The task to execute.
* *stop_token* (`Any`): The token that signals the termination of the workflow.
#### Examples:
```python
from swarms.models import OpenAIChat
from swarms.structs import RecursiveWorkflow, Task
llm = OpenAIChat(openai_api_key="YourKey")
task = Task(llm, "What's the weather in miami")
workflow = RecursiveWorkflow(stop_token="<DONE>")
workflow.add(task)
workflow.run()
```
In summary, the `RecursiveWorkflow` class is designed to automate tasks by adding and executing these tasks recursively until a stopping condition is reached. This can be achieved by utilizing the `add` and `run` methods provided. A general format for adding and utilizing the `RecursiveWorkflow` class has been provided under the "Examples" section. If you require any further information, view other sections, like Args and Source Code for specifics on using the class effectively.

@ -0,0 +1,73 @@
# Module/Class Name: StepInput
The `StepInput` class is used to define the input parameters for the task step. It is a part of the `BaseModel` and accepts any value. This documentation will provide an overview of the class, its functionality, and usage examples.
## Overview and Introduction
The `StepInput` class is an integral part of the `swarms.structs` library, allowing users to define and pass input parameters for a specific task step. This class provides flexibility by accepting any value, allowing the user to customize the input parameters according to their requirements.
## Class Definition
The `StepInput` class is defined as follows:
```python
class StepInput(BaseModel):
__root__: Any = Field(
...,
description=(
"Input parameters for the task step. Any value is"
" allowed."
),
example='{\n"file_to_refactor": "models.py"\n}',
)
```
The `StepInput` class extends the `BaseModel` and contains a single field `__root__` of type `Any` with a description of accepting input parameters for the task step.
## Functionality and Usage
The `StepInput` class is designed to accept any input value, providing flexibility and customization for task-specific parameters. Upon creating an instance of `StepInput`, the user can define and pass input parameters as per their requirements.
### Usage Example 1:
```python
from swarms.structs import StepInput
input_params = {
"file_to_refactor": "models.py",
"refactor_method": "code"
}
step_input = StepInput(__root__=input_params)
```
In this example, we import the `StepInput` class from the `swarms.structs` library and create an instance `step_input` by passing a dictionary of input parameters. The `StepInput` class allows any value to be passed, providing flexibility for customization.
### Usage Example 2:
```python
from swarms.structs import StepInput
input_params = {
"input_path": "data.csv",
"output_path": "result.csv"
}
step_input = StepInput(__root__=input_params)
```
In this example, we again create an instance of `StepInput` by passing a dictionary of input parameters. The `StepInput` class does not restrict the type of input, allowing users to define parameters based on their specific task requirements.
### Usage Example 3:
```python
from swarms.structs import StepInput
file_path = "config.json"
with open(file_path, 'r') as f:
input_data = json.load(f)
step_input = StepInput(__root__=input_data)
```
In this example, we read input parameters from a JSON file and create an instance of `StepInput` by passing the loaded JSON data. The `StepInput` class seamlessly accepts input data from various sources, providing versatility to the user.
## Additional Information and Tips
When using the `StepInput` class, ensure that the input parameters are well-defined and align with the requirements of the task step. When passing complex data structures, such as nested dictionaries or JSON objects, ensure that the structure is valid and well-formed.
## References and Resources
- For further information on the `BaseModel` and `Field` classes, refer to the Pydantic documentation: [Pydantic Documentation](https://pydantic-docs.helpmanual.io/)
The `StepInput` class within the `swarms.structs` library is a versatile and essential component for defining task-specific input parameters. Its flexibility in accepting any value and seamless integration with diverse data sources make it a valuable asset for customizing input parameters for task steps.

@ -0,0 +1,157 @@
```markdown
# Class Name: SwarmNetwork
## Overview and Introduction
The `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 Definition
The `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:
```python
from swarms.structs.agent import Agent
from swarms.structs.swarm_net import SwarmNetwork
agent = 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:
```python
from swarms.structs.agent import Agent
from swarms.structs.swarm_net import SwarmNetwork
agent = Agent()
swarm = SwarmNetwork(agents=[agent])
await swarm.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:
```python
from swarms.structs.agent import Agent
from swarms.structs.swarm_net import SwarmNetwork
agent = 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:
```python
from swarms.structs.agent import Agent
from swarms.structs.swarm_net import SwarmNetwork
agent = 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:
```python
from swarms.structs.agent import Agent
from swarms.structs.swarm_net import SwarmNetwork
agent = 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:
```python
from swarms.structs.agent import Agent
from swarms.structs.swarm_net import SwarmNetwork
agent = 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:
```python
from swarms.structs.agent import Agent
from swarms.structs.swarm_net import SwarmNetwork
agent = 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:
```python
from swarms.structs.agent import Agent
from swarms.structs.swarm_net import SwarmNetwork
swarm = 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:
```python
from swarms.structs.agent import Agent
from swarms.structs.swarm_net import SwarmNetwork
swarm = 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:
```python
from swarms.structs.agent import Agent
from swarms.structs.swarm_net import SwarmNetwork
agent = 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.
```

@ -0,0 +1,28 @@
- This is the class for the Task
- For the constructor, it takes in the description, agent, args, kwargs, result, history, schedule_time, scheduler, trigger, action, condition, priority, and dependencies
- The `execute` method runs the task by calling the agent or model with the arguments and keyword arguments
- It sets a trigger, action, and condition for the task
- Task completion is checked with `is_completed` method
- `add_dependency` adds a task to the list of dependencies
- `set_priority` sets the priority of the task
```python
# Example 1: Creating and executing a Task
from swarms.structs import Task, Agent
from swarms.models import OpenAIChat
agent = Agent(llm=OpenAIChat(openai_api_key=""), max_loops=1, dashboard=False)
task = Task(agent=agent)
task.execute("What's the weather in miami")
print(task.result)
# Example 2: Adding a dependency and setting priority
task2 = Task(description="Task 2", agent=agent)
task.add_dependency(task2)
task.set_priority(1)
# Example 3: Executing a scheduled task
task3 = Task(description="Scheduled Task", agent=agent)
task3.schedule_time = datetime.datetime.now() + datetime.timedelta(minutes=30)
task3.handle_scheduled_task()
print(task3.is_completed())
```

@ -0,0 +1,75 @@
## Module/Class Name: TaskInput
The `TaskInput` class is designed to handle the input parameters for a task. It is an abstract class that serves as the base model for input data manipulation.
### Overview and Introduction
The `TaskInput` class is an essential component of the `swarms.structs` library, allowing users to define and pass input parameters to tasks. It is crucial for ensuring the correct and structured input to various tasks and processes within the library.
### Class Definition
#### TaskInput Class:
- Parameters:
- `__root__` (Any): The input parameters for the task. Any value is allowed.
### Disclaimer:
It is important to note that the `TaskInput` class extends the `BaseModel` from the `pydantic` library. This means that it inherits all the properties and methods of the `BaseModel`.
### Functionality and Usage
The `TaskInput` class encapsulates the input parameters in a structured format. It allows for easy validation and manipulation of input data.
#### Usage Example 1: Using TaskInput for Debugging
```python
from pydantic import BaseModel, Field
from swarms.structs import TaskInput
class DebugInput(TaskInput):
debug: bool
# Creating an instance of DebugInput
debug_params = DebugInput(__root__={"debug": True})
# Accessing the input parameters
print(debug_params.debug) # Output: True
```
#### Usage Example 2: Using TaskInput for Task Modes
```python
from pydantic import BaseModel, Field
from swarms.structs import TaskInput
class ModeInput(TaskInput):
mode: str
# Creating an instance of ModeInput
mode_params = ModeInput(__root__={"mode": "benchmarks"})
# Accessing the input parameters
print(mode_params.mode) # Output: benchmarks
```
#### Usage Example 3: Using TaskInput with Arbitrary Parameters
```python
from pydantic import BaseModel, Field
from swarms.structs import TaskInput
class ArbitraryInput(TaskInput):
message: str
quantity: int
# Creating an instance of ArbitraryInput
arbitrary_params = ArbitraryInput(__root__={"message": "Hello, world!", "quantity": 5})
# Accessing the input parameters
print(arbitrary_params.message) # Output: Hello, world!
print(arbitrary_params.quantity) # Output: 5
```
### Additional Information and Tips
- The `TaskInput` class can be extended to create custom input models with specific parameters tailored to individual tasks.
- The `Field` class from `pydantic` can be used to specify metadata and constraints for the input parameters.
### References and Resources
- Official `pydantic` Documentation: [https://pydantic-docs.helpmanual.io/](https://pydantic-docs.helpmanual.io/)
- Additional resources on data modelling with `pydantic`: [https://www.tiangolo.com/blog/2021/02/16/real-python-tutorial-modern-fastapi-pydantic/](https://www.tiangolo.com/blog/2021/02/16/real-python-tutorial-modern-fastapi-pydantic/)
This documentation presents the `TaskInput` class, its usage, and practical examples for creating and handling input parameters within the `swarms.structs` library.

@ -1,4 +1,4 @@
# `GodMode` Documentation
# `ModelParallelizer` Documentation
## Table of Contents
1. [Understanding the Purpose](#understanding-the-purpose)
@ -11,19 +11,19 @@
## 1. Understanding the Purpose <a name="understanding-the-purpose"></a>
To create comprehensive documentation for the `GodMode` class, let's begin by understanding its purpose and functionality.
To create comprehensive documentation for the `ModelParallelizer` class, let's begin by understanding its purpose and functionality.
### Purpose and Functionality
`GodMode` is a class designed to facilitate the orchestration of multiple Language Model Models (LLMs) to perform various tasks simultaneously. It serves as a powerful tool for managing, distributing, and collecting responses from these models.
`ModelParallelizer` is a class designed to facilitate the orchestration of multiple Language Model Models (LLMs) to perform various tasks simultaneously. It serves as a powerful tool for managing, distributing, and collecting responses from these models.
Key features and functionality include:
- **Parallel Task Execution**: `GodMode` can distribute tasks to multiple LLMs and execute them in parallel, improving efficiency and reducing response time.
- **Parallel Task Execution**: `ModelParallelizer` can distribute tasks to multiple LLMs and execute them in parallel, improving efficiency and reducing response time.
- **Structured Response Presentation**: The class presents the responses from LLMs in a structured tabular format, making it easy for users to compare and analyze the results.
- **Task History Tracking**: `GodMode` keeps a record of tasks that have been submitted, allowing users to review previous tasks and responses.
- **Task History Tracking**: `ModelParallelizer` keeps a record of tasks that have been submitted, allowing users to review previous tasks and responses.
- **Asynchronous Execution**: The class provides options for asynchronous task execution, which can be particularly useful for handling a large number of tasks.
@ -33,29 +33,29 @@ Now that we have an understanding of its purpose, let's proceed to provide a det
### Overview
The `GodMode` class is a crucial component for managing and utilizing multiple LLMs in various natural language processing (NLP) tasks. Its architecture and functionality are designed to address the need for parallel processing and efficient response handling.
The `ModelParallelizer` class is a crucial component for managing and utilizing multiple LLMs in various natural language processing (NLP) tasks. Its architecture and functionality are designed to address the need for parallel processing and efficient response handling.
### Importance and Relevance
In the rapidly evolving field of NLP, it has become common to use multiple language models to achieve better results in tasks such as translation, summarization, and question answering. `GodMode` streamlines this process by allowing users to harness the capabilities of several LLMs simultaneously.
In the rapidly evolving field of NLP, it has become common to use multiple language models to achieve better results in tasks such as translation, summarization, and question answering. `ModelParallelizer` streamlines this process by allowing users to harness the capabilities of several LLMs simultaneously.
Key points:
- **Parallel Processing**: `GodMode` leverages multithreading to execute tasks concurrently, significantly reducing the time required for processing.
- **Parallel Processing**: `ModelParallelizer` leverages multithreading to execute tasks concurrently, significantly reducing the time required for processing.
- **Response Visualization**: The class presents responses in a structured tabular format, enabling users to visualize and analyze the outputs from different LLMs.
- **Task Tracking**: Developers can track the history of tasks submitted to `GodMode`, making it easier to manage and monitor ongoing work.
- **Task Tracking**: Developers can track the history of tasks submitted to `ModelParallelizer`, making it easier to manage and monitor ongoing work.
### Architecture and How It Works
The architecture and working of `GodMode` can be summarized in four steps:
The architecture and working of `ModelParallelizer` can be summarized in four steps:
1. **Task Reception**: `GodMode` receives a task from the user.
1. **Task Reception**: `ModelParallelizer` receives a task from the user.
2. **Task Distribution**: The class distributes the task to all registered LLMs.
3. **Response Collection**: `GodMode` collects the responses generated by the LLMs.
3. **Response Collection**: `ModelParallelizer` collects the responses generated by the LLMs.
4. **Response Presentation**: Finally, the class presents the responses from all LLMs in a structured tabular format, making it easy for users to compare and analyze the results.
@ -65,15 +65,15 @@ Now that we have an overview, let's proceed with a detailed class definition.
### Class Attributes
- `llms`: A list of LLMs (Language Model Models) that `GodMode` manages.
- `llms`: A list of LLMs (Language Model Models) that `ModelParallelizer` manages.
- `last_responses`: Stores the responses from the most recent task.
- `task_history`: Keeps a record of all tasks submitted to `GodMode`.
- `task_history`: Keeps a record of all tasks submitted to `ModelParallelizer`.
### Methods
The `GodMode` class defines various methods to facilitate task distribution, execution, and response presentation. Let's examine some of the key methods:
The `ModelParallelizer` class defines various methods to facilitate task distribution, execution, and response presentation. Let's examine some of the key methods:
- `run(task)`: Distributes a task to all LLMs, collects responses, and returns them.
@ -87,23 +87,23 @@ The `GodMode` class defines various methods to facilitate task distribution, exe
- `save_responses_to_file(filename)`: Saves responses to a file for future reference.
- `load_llms_from_file(filename)`: Loads LLMs from a file, making it easy to configure `GodMode` for different tasks.
- `load_llms_from_file(filename)`: Loads LLMs from a file, making it easy to configure `ModelParallelizer` for different tasks.
- `get_task_history()`: Retrieves the task history, allowing users to review previous tasks.
- `summary()`: Provides a summary of task history and the last responses, aiding in post-processing and analysis.
Now that we have covered the class definition, let's delve into the functionality and usage of `GodMode`.
Now that we have covered the class definition, let's delve into the functionality and usage of `ModelParallelizer`.
## 4. Functionality and Usage <a name="functionality-and-usage"></a>
### Distributing a Task and Collecting Responses
One of the primary use cases of `GodMode` is to distribute a task to all registered LLMs and collect their responses. This can be achieved using the `run(task)` method. Below is an example:
One of the primary use cases of `ModelParallelizer` is to distribute a task to all registered LLMs and collect their responses. This can be achieved using the `run(task)` method. Below is an example:
```python
god_mode = GodMode(llms)
responses = god_mode.run("Translate the following English text to French: 'Hello, how are you?'")
parallelizer = ModelParallelizer(llms)
responses = parallelizer.run("Translate the following English text to French: 'Hello, how are you?'")
```
### Printing Responses
@ -111,7 +111,7 @@ responses = god_mode.run("Translate the following English text to French: 'Hello
To present the responses from all LLMs in a structured tabular format, use the `print_responses(task)` method. Example:
```python
god_mode.print_responses("Summarize the main points of 'War and Peace.'")
parallelizer.print_responses("Summarize the main points of 'War and Peace.'")
```
### Saving Responses to a File
@ -119,15 +119,15 @@ god_mode.print_responses("Summarize the main points of 'War and Peace.'")
Users can save the responses to a file using the `save_responses_to_file(filename)` method. This is useful for archiving and reviewing responses later. Example:
```python
god_mode.save_responses_to_file("responses.txt")
parallelizer.save_responses_to_file("responses.txt")
```
### Task History
The `GodMode` class keeps track of the task history. Developers can access the task history using the `get_task_history()` method. Example:
The `ModelParallelizer` class keeps track of the task history. Developers can access the task history using the `get_task_history()` method. Example:
```python
task_history = god_mode.get_task_history()
task_history = parallelizer.get_task_history()
for i, task in enumerate(task_history):
print(f"Task {i + 1}: {task}")
```
@ -136,7 +136,7 @@ for i, task in enumerate(task_history):
### Parallel Execution
`GodMode` employs multithreading to execute tasks concurrently. This parallel processing capability significantly improves the efficiency of handling multiple tasks simultaneously.
`ModelParallelizer` employs multithreading to execute tasks concurrently. This parallel processing capability significantly improves the efficiency of handling multiple tasks simultaneously.
### Response Visualization
@ -144,13 +144,13 @@ The structured tabular format used for presenting responses simplifies the compa
## 6. Examples <a name="examples"></a>
Let's explore additional usage examples to illustrate the versatility of `GodMode` in handling various NLP tasks.
Let's explore additional usage examples to illustrate the versatility of `ModelParallelizer` in handling various NLP tasks.
### Example 1: Sentiment Analysis
```python
from swarms.models import OpenAIChat
from swarms.swarms import GodMode
from swarms.swarms import ModelParallelizer
from swarms.workers.worker import Worker
# Create an instance of an LLM for sentiment analysis
@ -184,15 +184,15 @@ worker3 = Worker(
temperature=0.5,
)
# Register the worker agents with GodMode
# Register the worker agents with ModelParallelizer
agents = [worker1, worker2, worker3]
god_mode = GodMode(agents)
parallelizer = ModelParallelizer(agents)
# Task for sentiment analysis
task = "Please analyze the sentiment of the following sentence: 'This movie is amazing!'"
# Print responses from all agents
god_mode.print_responses(task)
parallelizer.print_responses(task)
```
### Example 2: Translation
@ -200,22 +200,22 @@ god_mode.print_responses(task)
```python
from swarms.models import OpenAIChat
from swarms.swarms import GodMode
from swarms.swarms import ModelParallelizer
# Define LLMs for translation tasks
translator1 = OpenAIChat(model_name="translator-en-fr", openai_api_key="api-key", temperature=0.7)
translator2 = OpenAIChat(model_name="translator-en-es", openai_api_key="api-key", temperature=0.7)
translator3 = OpenAIChat(model_name="translator-en-de", openai_api_key="api-key", temperature=0.7)
# Register translation agents with GodMode
# Register translation agents with ModelParallelizer
translators = [translator1, translator2, translator3]
god_mode = GodMode(translators)
parallelizer = ModelParallelizer(translators)
# Task for translation
task = "Translate the following English text to French: 'Hello, how are you?'"
# Print translated responses from all agents
god_mode.print_responses(task)
parallelizer.print_responses(task)
```
### Example 3: Summarization
@ -223,7 +223,7 @@ god_mode.print_responses(task)
```python
from swarms.models import OpenAIChat
from swarms.swarms import GodMode
from swarms.swarms import ModelParallelizer
# Define LLMs for summarization tasks
@ -231,19 +231,19 @@ summarizer1 = OpenAIChat(model_name="summarizer-en", openai_api_key="api-key", t
summarizer2 = OpenAIChat(model_name="summarizer-en", openai_api_key="api-key", temperature=0.6)
summarizer3 = OpenAIChat(model_name="summarizer-en", openai_api_key="api-key", temperature=0.6)
# Register summarization agents with GodMode
# Register summarization agents with ModelParallelizer
summarizers = [summarizer1, summarizer2, summarizer3]
god_mode = GodMode(summarizers)
parallelizer = ModelParallelizer(summarizers)
# Task for summarization
task = "Summarize the main points of the article titled 'Climate Change and Its Impact on the Environment.'"
# Print summarized responses from all agents
god_mode.print_responses(task)
parallelizer.print_responses(task)
```
## 7. Conclusion <a name="conclusion"></a>
In conclusion, the `GodMode` class is a powerful tool for managing and orchestrating multiple Language Model Models in natural language processing tasks. Its ability to distribute tasks, collect responses, and present them in a structured format makes it invaluable for streamlining NLP workflows. By following the provided documentation, users can harness the full potential of `GodMode` to enhance their natural language processing projects.
In conclusion, the `ModelParallelizer` class is a powerful tool for managing and orchestrating multiple Language Model Models in natural language processing tasks. Its ability to distribute tasks, collect responses, and present them in a structured format makes it invaluable for streamlining NLP workflows. By following the provided documentation, users can harness the full potential of `ModelParallelizer` to enhance their natural language processing projects.
For further information on specific LLMs or advanced usage, refer to the documentation of the respective models and their APIs. Additionally, external resources on parallel execution and response visualization can provide deeper insights into these topics.

@ -0,0 +1,123 @@
# AnthropicTokenizer Documentation
## Introduction
This documentation intends to provide a complete and in-depth guide for using the `AnthropicTokenizer` class within the `swarms.tokenizers` library. The `AnthropicTokenizer` is designed specifically to interface with Anthropic's AI models, primarily used for text tokenization and metadata handling.
Understanding how to use this tokenizer effectively is crucial for developers and researchers working with natural language processing, machine learning, and text analysis using Anthropic AI models.
The purpose of the `AnthropicTokenizer` is to convert raw text into a sequence of tokens that can be fed into Anthropic AI models for various tasks. Tokenization is a fundamental step in text processing pipelines and affects the performance of AI models.
## Class Definition: AnthropicTokenizer
`AnthropicTokenizer` extends the functionality of a base tokenizer to provide features specifically needed for Anthropic AI models. The class is designed to manage tokenization processes such as counting tokens and ensuring that the token count is under a specified limit, which is essential for effective and efficient model performance.
**Class Signature:**
**Parameters:**
| Parameter Name | Type | Description | Default Value |
|---------------------------|-----------|-----------------------------------------------------------------|---------------|
| `max_tokens` | `int` | Maximum number of tokens permitted. | `500` |
| `client` | `Anthropic` | Instance of an `Anthropic` client for tokenization services. | `None` |
| `model` | `str` | Identifier for the Anthropic model in use. | `"claude-2.1"`|
**Methods and their descriptions:**
| Method Name | Return Type | Description |
|----------------------|-------------|--------------------------------------------------------------|
| `__post_init__` | `None` | Initializes default parameters and client instance. |
| `default_max_tokens` | `int` | Returns the default maximum number of tokens. |
| `count_tokens` | `int` | Counts tokens in the input text. Raises a ValueError if the input is not a string. |
## Architecture and Mechanics
Upon instantiation, `AnthropicTokenizer` initializes its `max_tokens` limit and sets up a client to interact with the Anthropic services. The client is responsible for providing tokenization functions critical for processing the text inputs.
The tokenizer employs a dictionary to map specific model prefixes to their maximum token counts. This allows users to adapt the tokenizer's behavior to different models with varying token limits. The `default_max_tokens()` method dynamically retrieves the token limit based on the provided model name, ensuring compatibility and flexibility.
`count_tokens()` is a critical function that calculates the number of tokens in a given text. This functionality is essential for respecting the model's token limit and ensuring accurate processing by the Anthropic AI.
## Usage Examples
Before delving into detailed examples, make sure you have `swarms.tokenizers` installed and ready. If `anthropic` is an optional dependency, ensure that it's installed as well.
### 1. Tokenizing with Default Settings
```python
from swarms.tokenizers import AnthropicTokenizer
# Initialize the tokenizer with default settings
tokenizer = AnthropicTokenizer()
# Tokenize a sample text
text = "Hello world! This is an example text to tokenize."
token_count = tokenizer.count_tokens(text)
print(f"Number of tokens: {token_count}")
```
In this example, we use the `AnthropicTokenizer` to count the number of tokens in a simple text. The token count can be crucial for managing inputs to the AI model.
### 2. Tokenizing with Custom Model
```python
from swarms.tokenizers import AnthropicTokenizer
# Define a custom model
custom_model = "claude"
# Initialize the tokenizer with a custom model and max_tokens
tokenizer = AnthropicTokenizer(model=custom_model, max_tokens=1000)
# Process a larger text
large_text = "..." # Assume large_text is a string with meaningful content
token_count = tokenizer.count_tokens(large_text)
if token_count > tokenizer.max_tokens:
print("Text exceeds the maximum token limit.")
else:
print(f"Token count within limit: {token_count}")
```
This snippet demonstrates setting up the tokenizer for a custom model and a higher maximum token limit. It is helpful when dealing with texts larger than the default token limit.
### 3. Handling Error in Token Count Function
```python
from swarms.tokenizers import AnthropicTokenizer
# Initialize the tokenizer
tokenizer = AnthropicTokenizer()
# Attempt to tokenize a non-string input (which will raise an error)
non_string_input = ["This", "is", "a", "list", "not", "a", "string"]
try:
tokenizer.count_tokens(non_string_input)
except ValueError as e:
print(f"Error: {e}")
```
This example illustrates the error management within the `count_tokens` method. It is important to handle exceptions gracefully, particularly when a non-string input is provided.
## Additional Tips and Considerations
- Always ensure the input text is a string before calling `count_tokens` to avoid unnecessary errors.
- Be aware of the `max_tokens` limit since larger models might have significantly higher limits than defaults.
- When tokenizing large datasets, batch processing with a loop or parallelization might provide better performance.
## Resources and References
Given that `AnthropicTokenizer` interacts with an AI model and optional dependencies, it is beneficial to refer to the official documentation and guides specific to those components:
- [Anthropic Model Documentation](#) (Link would be replaced with actual URL)
- [swarms.tokenizers Installation Guide](#)
- [Python `dataclasses` Documentation](https://docs.python.org/3/library/dataclasses.html)
Additionally, literature on best practices for tokenization and natural language processing will contribute to a more effective use of the tokenizer:
- Smith, B. (Year). "Advanced Tokenization Techniques for NLP Models." Journal of Machine Learning.
- Caruthers, M. (Year). "Text Pre-processing and Tokenization for Deep Learning."
By following the provided documentation and recommended practices, developers and researchers can harness the power of `AnthropicTokenizer` to its full potential, facilitating optimal use of Anthropic's AI models for varied text processing tasks.

@ -0,0 +1,62 @@
# Documentation for `swarms.tokenizers.BaseTokenizer`
## Overview and Introduction
The `swarms.tokenizers` library is designed to provide flexible and efficient tokenization utilities for natural language processing (NLP) tasks. The `BaseTokenizer` class serves as a foundational abstract class from which specific tokenizer implementations can be derived. This class outlines essential functions and properties all tokenizers should have, ensuring consistency and capturing common behaviors required for processing textual data.
## Class Definition: `BaseTokenizer`
### Attributes and Methods
| Name | Type | Description |
| ---------------------- | ------------------------------- | ------------------------------------------------------------------------- |
| `max_tokens` | `int` | Maximum number of tokens the tokenizer can process. |
| `stop_token` | `str` | Token used to denote the end of processing. |
| `stop_sequences` | `List[str]` (read-only) | List of stop sequences initialized post-instantiation. |
| `count_tokens_left` | Method: `(text) -> int` | Computes the number of tokens that can still be added given the text. |
| `count_tokens` | Abstract Method: `(text) -> int`| Returns the number of tokens in the given text. |
## Functionality and Usage
The `BaseTokenizer` class provides the structure for creating tokenizers. It includes methods for counting the tokens in a given text and determining how many more tokens can be added without exceeding the `max_tokens` limit. This class should be subclassed, and the `count_tokens` method must be implemented in subclasses to provide the specific token counting logic.
### Example: Subclassing `BaseTokenizer`
```python
from swarms.tokenizers import BaseTokenizer
class SimpleTokenizer(BaseTokenizer):
def count_tokens(self, text: Union[str, List[dict]]) -> int:
if isinstance(text, str):
# Split text by spaces as a simple tokenization approach
return len(text.split())
elif isinstance(text, list):
# Assume list of dictionaries with 'token' key
return sum(len(item['token'].split()) for item in text)
else:
raise TypeError("Unsupported type for text")
# Usage example
tokenizer = SimpleTokenizer(max_tokens=100)
text = "This is an example sentence to tokenize."
print(tokenizer.count_tokens(text)) # Outputs: 7 (assuming space tokenization)
remaining_tokens = tokenizer.count_tokens_left(text)
print(remaining_tokens) # Outputs: 93
```
### Note:
Understand that the `stop_sequences` and `stop_token` in this particular implementation are placeholders to illustrate the pattern. The actual logic may differ based on specific tokenizer requirements.
## Additional Information and Tips
- Tokenization is a vital step in text processing for NLP. It should be tailored to the requirements of the application.
- Ensure that tokenizer definitions are in sync with the models and datasets being used.
## References and Resources
For a deeper understanding of tokenization and its role in NLP, refer to:
- [Natural Language Processing (NLP) in Python — Tokenization](https://nlp.stanford.edu/IR-book/html/htmledition/tokenization-1.html)
- [Hugging Face Tokenizers](https://huggingface.co/docs/tokenizers/python/latest/) - a popular library for tokenization, particularly in the context of transformer models.

@ -0,0 +1,134 @@
# CohereTokenizer Documentation
The `CohereTokenizer` class is designed to interface with Cohere language models and provides methods for tokenizing text inputs. This tokenizer plays a crucial role in preparing data for a Cohere model, which operates on tokens rather than raw text.
---
### Class Name: `CohereTokenizer`
## Overview
The `CohereTokenizer` class is essential for interacting with Cohere models that require tokenized input. As models often operate on tokens, having an intuitive and efficient tokenizer directly linked to the model simplifies preprocessing tasks. This tokenizer counts the tokens in the given text, helping users to manage and understand the tokens they can work with, given limitations like the model's maximum token count.
## Architecture and How the Class Works
The `CohereTokenizer` is built as a data class, ensuring that it is lightweight and focused solely on its data attributes and methods related to tokenization. The class relies on an instance of a Cohere `Client`, which needs to be instantiated with an API key from Cohere before use.
Upon instantiation, the `CohereTokenizer` holds a reference to a specific Cohere model and interfaces with the `Client` to tokenize text accordingly. It provides a simple utility (`count_tokens`) to count the number of tokens that a string, or a list of strings, would be broken down into by the Cohere API.
## Purpose and Usage
The `CohereTokenizer` is specifically made for users who are working with Cohere language models. It's designed to help them in preprocessing steps by converting text into tokens and determining how many tokens their text segments contain. This is crucial for ensuring that inputs do not exceed the model's maximum token count, as exceeding this limit can result in errors or truncated text.
---
# Class Definition
```python
@dataclass
class CohereTokenizer:
model: str
client: Client
DEFAULT_MODEL: str = "command"
DEFAULT_MAX_TOKENS: int = 2048
max_tokens: int = DEFAULT_MAX_TOKENS
```
## Parameters
| Parameter | Type | Description | Default Value |
| ------------------ | -------------- | ------------------------------------------------------------- | ------------- |
| `model` | `str` | Specifies the Cohere model to be used for tokenization. | None |
| `client` | `Client` | An instance of the Cohere client, initialized with an API key.| None |
| `DEFAULT_MODEL` | `str` | The default model to use if none is specified. | "command" |
| `DEFAULT_MAX_TOKENS`| `int` | Default maximum number of tokens the model accepts. | 2048 |
| `max_tokens` | `int` | Maximum number of tokens; it can be altered to fit the model. | `DEFAULT_MAX_TOKENS`|
### Methods
The `CohereTokenizer` class contains the following method:
#### `count_tokens`
```python
def count_tokens(self, text: str | list) -> int:
"""
Count the number of tokens in the given text.
Args:
text (str | list): The input text to tokenize.
Returns:
int: The number of tokens in the text.
Raises:
ValueError: If the input text is not a string.
"""
```
---
# Functionality and Usage Example
Below are examples demonstrating how to use `CohereTokenizer`.
---
## Counting Tokens
### Initialization
First, the Cohere client must be initialized and passed in to create an instance of `CohereTokenizer`.
```python
from cohere import Client
from swarms.tokenizers import CohereTokenizer
# Initialize Cohere client with your API key
cohere_client = Client('your-api-key')
# Instantiate the tokenizer
tokenizer = CohereTokenizer(model='your-model-name', client=cohere_client)
```
### Count Tokens Example 1
Counting tokens for a single string.
```python
text_to_tokenize = "Hello, World!"
token_count = tokenizer.count_tokens(text_to_tokenize)
print(f"Number of tokens: {token_count}")
```
### Count Tokens Example 2
Trying to pass a list instead of a single string, which would raise an error.
```python
texts_to_tokenize = ["Hello, World!", "Another piece of text."]
try:
token_count = tokenizer.count_tokens(texts_to_tokenize)
except ValueError as e:
print(f"Error: {e}")
```
The above code would print `Error: Text must be a string.` as the `count_tokens` function expects a string, not a list.
---
# Additional Information and Tips
When working with the `CohereTokenizer`, here are some key points to keep in mind:
- The token count is important to know because Cohere models have a maximum token limit for input. If your text exceeds this limit, it must be split or truncated before being passed to the model.
- It is always a good practice to catch exceptions when using methods like `count_tokens` to handle unexpected inputs gracefully.
- Remember to replace `'your-api-key'` and `'your-model-name'` with your actual Cohere API key and desired model name.
# References and Resources
For more detailed information, refer to the following resources:
- [Cohere API documentation](https://docs.cohere.ai/)
- [Data Classes in Python](https://docs.python.org/3/library/dataclasses.html)

@ -0,0 +1,127 @@
# HuggingFaceTokenizer Documentation
`HuggingFaceTokenizer` is a comprehensive Python class that leverages the Hugging Face `transformers` library to tokenize text using the SentencePiece tokenization mechanism. This class serves as a convenient wrapper for initializing and using tokenizer models from Hugging Face's transformer models, enabling easy integration of tokenizer functionality in various NLP tasks.
**Purpose and Architecture:**
Tokenization is a critical step in processing natural language wherein text is broken down into smaller elements (tokens), which can be further used for text analysis, language modeling, and other computational linguistics tasks. The `HuggingFaceTokenizer` provides methods to encode text (turning strings into lists of token IDs) and decode lists of token IDs back into human-readable text.
**Table of Contents:**
- [Overview](#overview)
- [Initialization](#initialization)
- [Properties](#properties)
- [Methods](#methods)
- [Usage Examples](#usage-examples)
- [References and Resources](#references-and-resources)
## Overview
The `HuggingFaceTokenizer` class is designed to streamline the process of tokenizing text for natural language processing (NLP). It encapsulates various functionalities, such as encoding text into tokens, decoding tokens into text, and identifying token IDs for special tokens.
## Initialization
`HuggingFaceTokenizer` is initialized by providing the directory containing the pretrained tokenizer model files. During its initialization, it configures its internal state for tokenization processes, prepares access to vocabulary, and establishes necessary properties for subsequent tokenization tasks.
### Constructor Parameters
| Parameter | Data Type | Description | Default |
|------------|-----------|--------------------------------------------|---------|
| model_dir | `str` | The directory containing the tokenizer model files. | None |
### Attributes
| Attribute | Data Type | Description |
|-------------------|---------------------|--------------------------------------------------------|
| vocab_size | `int` | The size of the vocabulary used by the tokenizer. |
| bos_token_id | `int` | The token ID representing the beginning of sequence token. |
| eos_token_id | `int` | The token ID representing the end of sequence token. |
| prefix_space_tokens | `Set[int]` | A set of token IDs without a prefix space. |
## Methods
### Vocabulary Related Methods
#### `vocab_size`
Returns the size of the tokenizer's vocabulary.
#### `bos_token_id`
Returns the token ID used for the beginning of a sentence.
#### `eos_token_id`
Returns the token ID used for the end of a sentence.
#### `prefix_space_tokens`
Returns a set of token IDs that start without prefix spaces.
### Tokenization Methods
#### `encode`
Encodes a given text into a sequence of token IDs.
#### `decode`
Decodes a given sequence of token IDs into human-readable text.
#### `indexes_containing_token`
Returns a list of token IDs that potentially could be decoded into the given token.
#### `__call__`
Tokenizes given text when the object is called like a function.
## Usage Examples
### 1. Initializing the Tokenizer
```python
from swarms.tokenizers import HuggingFaceTokenizer
# Initialize the tokenizer with the path to your tokenizer model.
tokenizer = HuggingFaceTokenizer('/path/to/your/model_dir')
```
### 2. Encoding Text
```python
# Tokenize a single sentence.
sentence = "The quick brown fox jumps over the lazy dog."
token_ids = tokenizer.encode(sentence)
print(token_ids)
```
### 3. Decoding Tokens
```python
# Assuming 'token_ids' contains a list of token IDs
decoded_text = tokenizer.decode(token_ids)
print(decoded_text)
```
### 4. Getting Special Token IDs
```python
# Get the beginning of sequence token ID
bos_id = tokenizer.bos_token_id
print(f"BOS token ID: {bos_id}")
# Get the end of sequence token ID
eos_id = tokenizer.eos_token_id
print(f"EOS token ID: {eos_id}")
```
### 5. Using the Tokenizer
```python
# Tokenize a prompt directly by calling the object with a string.
text = "Hello, world!"
token_ids = tokenizer(text)
print(token_ids)
```
## References and Resources
For more in-depth information on the Hugging Face `transformers` library and SentencePiece, refer to the following resources:
- Hugging Face `transformers` library documentation: https://huggingface.co/docs/transformers/index
- SentencePiece repository and documentation: https://github.com/google/sentencepiece
This documentation provides an introductory overview of the `HuggingFaceTokenizer` class. For a more extensive guide on the various parameters, functionalities, and advanced usage scenarios, users should refer to the detailed library documentation and external resources provided above.

@ -0,0 +1,89 @@
# OpenAITokenizer
The `OpenAITokenizer` class is a versatile and intuitive tokenizer designed for use with OpenAI's various language models, including the powerful GPT series. This class addresses the need to efficiently tokenize text for submission to OpenAI's API endpoints, managing different models and their unique tokenization schemes with ease.
Utility of `OpenAITokenizer` centers around its key features:
- Support for multiple OpenAI models including GPT-3 and GPT-4.
- Dynamic token counting that considers model-specific details.
- Straightforward API intended for easy integration with larger systems.
## Architecture and Design
The class adheres to a simple yet effective design, offering methods for calculating token lengths and embedded properties that manage model-specific characteristics such as maximum tokens and encodings. A data class structure is used for clean initializations and better management of class data.
The `OpenAITokenizer` uses a property-based approach and a method-based approach to provide users with a variety of functionalities essential for preparing text input for OpenAI models.
## Attributes
The class contains several key constants and properties that define defaults and settings for use with different models:
| Attribute | Type | Description |
|-----------------------------------------------------|-----------------|-------------------------------------------------------------|
| `DEFAULT_OPENAI_GPT_3_COMPLETION_MODEL` | `str` | Default completion model for OpenAI GPT-3. |
| `DEFAULT_OPENAI_GPT_3_CHAT_MODEL` | `str` | Default chat model for OpenAI GPT-3. |
| `DEFAULT_OPENAI_GPT_4_MODEL` | `str` | Default model for OpenAI GPT-4. |
| `DEFAULT_ENCODING` | `str` | Default encoding for text. |
| `DEFAULT_MAX_TOKENS` | `int` | Default maximum number of tokens based on the model. |
| `TOKEN_OFFSET` | `int` | Token offset applicable to some models. |
| `MODEL_PREFIXES_TO_MAX_TOKENS` | `dict` | Mapping of model prefixes to their respective max tokens. |
| `EMBEDDING_MODELS` | `list` | List of embedding models supported. |
| `model` | `str` | Name of the model currently being used. |
## Methods
The `OpenAITokenizer` class offers a variety of methods:
| Method | Arguments | Return Type | Description |
|-----------------------|---------------------------------------------|-------------|------------------------------------------------------------------------------------------------|
| `__post_init__` | None | `None` | Method called after the class has been initialized to set up default values. |
| `encoding` | None | `Encoding` | Getter method that retrieves the encoding based on the specified model. |
| `default_max_tokens` | None | `int` | Calculates the default max tokens based on the current model or defaults if not model-specific.|
| `count_tokens` | `text: str \| list[dict]`, `model: str` | `int` | Counts the number of tokens within a given text or a list of messages. |
| `len` | `text: str \| list[dict]`, `model: str` | `int` | Wrapper for `count_tokens`, providing a more intuitive naming convention. |
### Usage Examples
Given the extensive nature of this class, several examples are provided for each method, detailing how to use the `OpenAITokenizer` in different contexts.
#### Example 1: Initializing the Tokenizer
```python
from swarms.tokenizers import OpenAITokenizer
tokenizer = OpenAITokenizer(model='gpt-4')
```
This example creates a new instance of `OpenAITokenizer` set to work with the GPT-4 model.
#### Example 2: Counting Tokens
```python
text = "Hello, this is an example text to tokenize."
# Initialize the tokenizer
tokenizer = OpenAITokenizer(model='gpt-4')
# Count tokens
num_tokens = tokenizer.count_tokens(text)
print(f"Number of tokens: {num_tokens}")
```
This code snippet demonstrates how to count the number of tokens in a string of text using the specified model's encoding.
#### Example 3: Custom Model Token Counting
```python
messages = [
{"name": "Alice", "message": "Hello! How are you?"},
{"name": "Bob", "message": "I'm good! Just working on some code."},
]
tokenizer = OpenAITokenizer(model='gpt-3.5-turbo')
# Count tokens for a list of messages
num_tokens = tokenizer.len(messages, model="gpt-3.5-turbo-0613")
print(f"Total tokens for messages: {num_tokens}")
```
In this example, we're invoking the `len` method to count the tokens in a conversation thread. Each message is represented as a dictionary with a `name` and `message` field.

@ -0,0 +1,163 @@
# swarms.tokenizers Documentation
`swarms.tokenizers` is a PyTorch-like tokenization library designed to facilitate natural language processing (NLP) tasks by converting text inputs into a form that machine learning models can interpret. In this documentation, we will outline how to utilize the `SentencePieceTokenizer` class from the `swarms.tokenizers` library, which offers sentencepiece tokenization, a language-independent subword tokenizer and detokenizer.
## Purpose and Architecture of `SentencePieceTokenizer`
The `SentencePieceTokenizer` class uses a pre-trained sentencepiece model to tokenize and detokenize texts. SentencePiece is an unsupervised text tokenizer and detokenizer that allows the generation of a subword vocabulary from raw data. By breaking text down into subword units (like wordpieces or byte-pair-encodings), SentencePiece handles languages without a clear word boundary and can improve the performance of text processing in neural network models.
In `SentencePieceTokenizer`, the tokenization process is language-agnostic and encompasses a range of tokenization strategies, such as byte pair encoding (BPE), unigram, or a combination of both. The class is designed with ease of use in mind, allowing seamless integration with other components of the NLP pipeline.
## Class Definition
```python
class SentencePieceTokenizer:
"""
Tokenizer of sentencepiece.
Args:
model_file (str): the path of the tokenizer model
"""
```
## Initialization Parameters
Property/Method | Type | Description
----------------|------|-------------
`model_file` | `str` | The path to the pretrained sentencepiece model file.
## Methods and Usage
Below, we detail the methods available in `SentencePieceTokenizer`, including their parameters, their functionality, and usage examples.
### Method: `__init__`
Instantiates an instance of the `SentencePieceTokenizer` with the specified sentencepiece model.
#### Parameters
Parameter | Type | Description
----------|------|-------------
`model_file` | `str` | The path to the pretrained sentencepiece model file.
#### Example
```python
from swarms.tokenizers import SentencePieceTokenizer
tokenizer = SentencePieceTokenizer(model_file='your_model.model')
```
### Properties: Vocabulary Information
These properties provide access to various vocabulary-specific information.
#### `vocab_size`
#### `bos_token_id`
#### `eos_token_id`
##### Example
```python
vocab_size = tokenizer.vocab_size
print(f"Vocabulary size: {vocab_size}")
bos_id = tokenizer.bos_token_id
eos_id = tokenizer.eos_token_id
print(f"BOS token ID: {bos_id}, EOS token ID: {eos_id}")
```
### Method: `indexes_containing_token`
Finds possible tokenizer indexes that, when decoded, may contain the input token.
#### Parameters
Parameter | Type | Description
----------|------|-------------
`token` | `str` | The token for which possible indexes are to be found.
#### Returns
- `List[int]`: List of tokenizer indexes that might contain the token.
#### Example
```python
indexes = tokenizer.indexes_containing_token("▁the")
print(f"Indexes containing '▁the': {indexes}")
```
### Method: `encode`
Tokenizes a text prompt into a list of token IDs.
#### Parameters
Parameter | Type | Description
----------|------|-------------
`s` | `str` | The text prompt to tokenize.
`add_bos` | `bool` | If `True`, it adds the beginning-of-sentence token. (default: `True`)
#### Returns
- `List[int]`: List of token IDs representing the text prompt.
#### Example
```python
encoded_ids = tokenizer.encode("Hello, world!", add_bos=True)
print(f"Encoded token IDs: {encoded_ids}")
```
### Method: `decode`
Detokenizes a list of token IDs into text.
#### Parameters
Parameter | Type | Description
----------|------|-------------
`t` | `List[int]` | A list of token IDs to detokenize.
`offset` | `Optional[int]` | For incremental decoding. Defaults to `None`, which means it is not applied.
#### Returns
- `str`: Text representation of the decoded token IDs.
#### Example
```python
decoded_text = tokenizer.decode([bos_id] + encoded_ids)
print(f"Decoded text: {decoded_text}")
```
### Method: `__call__`
Tokenizes prompts when the class instance is used as a callable.
#### Parameters
Parameter | Type | Description
----------|------|-------------
`s` | `Union[str, Sequence[str]]` | Text prompts to tokenize.
`add_bos` | `bool` | If `True`, it adds the beginning-of-sentence token. (default: `False`)
`add_eos` | `bool` | If `True`, it adds the end-of-sentence token. (default: `False`)
#### Returns
- `addict.Addict`: Object with `input_ids` containing the list of token IDs.
#### Example
```python
input_data = tokenizer("Let's tokenize this sentence.")
print(f"Tokenized input IDs: {input_data.input_ids}")
```
## Additional Information and Tips
The library has efficient internals that cache information for performance benefits. For example, `indexes_containing_token` uses a deque to store the most recent lookups, which saves computation time by avoiding re-traversing the vocabulary.
## Conclusion
This documentation provides an in-depth explanation of `swarms.tokenizers` with a focus on the `SentencePieceTokenizer` class. By following the examples and guidance detailed above, users should be able to effectively use the tokenizers for their NLP tasks. Users are also encouraged to refer to further resources and the official SentencePiece documentation for more advanced use cases and configurations.

@ -0,0 +1,78 @@
# `Tokenizer` Class Documentation
The `Tokenizer` class is a flexible and robust tokenization tool designed to efficiently tokenize prompts into a sequence of token IDs or convert token IDs back into readable text. The class works by initializing with a path to a pretrained tokenization model and supports different tokenization backends based on the availability of configs and pretrained models.
## Initialization & Configuration
### Parameters:
| Parameter | Type | Description | Required |
|------------|------|------------------------------------------|----------|
| model_file | str | Path to the tokenizer model or directory | Yes |
### Attributes:
| Attribute | Type | Description |
|------------------|------|------------------------------------|
| vocab_size | int | Size of the tokenizer's vocabulary |
| bos_token_id | int | ID of the beginning-of-sequence token |
| eos_token_id | int | ID of the end-of-sequence token |
### Methods:
| Method | Returns | Description |
|--------------------------------|---------|--------------------------------------------------------------|
| encode(s, add_bos=True, **kwargs) | list[int] | Tokenizes a prompt and returns token IDs. |
| decode(t, offset=None) | str | Decodes a list of token IDs to a string. |
| __call__(s) | list[int] | Tokenize prompts when the instance is called directly. |
| indexes_containing_token(token) | list[int] | Returns indexes in the vocabulary that may contain the token. |
## Usage Examples
### Tokenizing a Prompt
```python
from swarms.tokenizers import Tokenizer
tokenizer = Tokenizer("/path/to/tokenizer.model")
# Tokenize a single prompt string
prompt = "Hello, world!"
token_ids = tokenizer.encode(prompt)
print(token_ids)
```
### Decoding Token IDs
```python
# Decode token IDs back into text
decoded_text = tokenizer.decode(token_ids)
print(decoded_text)
```
### Incremental Decoding
```python
# Incremental decoding with offset (useful for streaming applications)
partial_tokens = [token_ids[0]] # simulate partially received tokens
decoded_partial = tokenizer.decode(partial_tokens, offset=0)
print(decoded_partial)
```
### Properties Access
```python
# Access vocabulary size and special token IDs
print("Vocabulary Size:", tokenizer.vocab_size)
print("BOS Token ID:", tokenizer.bos_token_id)
print("EOS Token ID:", tokenizer.eos_token_id)
```
### Indexes Containing Token
```python
# Find indexes that may output a specific token during decoding
token = "world"
indexes = tokenizer.indexes_containing_token(token)
print("Token Indexes:", indexes)
```

@ -0,0 +1,86 @@
# check_device
# Module/Function Name: check_device
The `check_device` is a utility function in PyTorch designed to identify and return the appropriate device(s) for CUDA processing. If CUDA is not available, a CPU device is returned. If CUDA is available, the function returns a list of all available GPU devices.
The function examines the CUDA availability, checks for multiple GPUs, and finds additional properties for each device.
## Function Signature and Arguments
**Signature:**
```python
def check_device(
log_level: Any = logging.INFO,
memory_threshold: float = 0.8,
capability_threshold: float = 3.5,
return_type: str = "list",
) -> Union[torch.device, List[torch.device]]
```
| Parameter | Data Type | Default Value | Description |
| ------------- | ------------- | ------------- | ------------- |
| `log_level` | Any | logging.INFO | The log level. |
| `memory_threshold` | float | 0.8 | It is used to check the threshold of memory used on the GPU(s). |
| `capability_threshold` | float | 3.5 | It is used to consider only those GPU(s) which have higher compute capability compared to the threshold. |
| `return_type` | str | "list" | Depending on the `return_type` either a list of devices can be returned or a single device. |
This function does not take any mandatory argument. However, it supports optional arguments such as `log_level`, `memory_threshold`, `capability_threshold`, and `return_type`.
**Returns:**
- A single torch.device if one device or list of torch.devices if multiple CUDA devices are available, else returns the CPU device if CUDA is not available.
## Usage and Examples
### Example 1: Basic Usage
```python
import torch
import logging
from swarms.utils import check_device
# Basic usage
device = check_device(
log_level=logging.INFO,
memory_threshold=0.8,
capability_threshold=3.5,
return_type="list"
)
```
### Example 2: Using CPU when CUDA is not available
```python
import torch
import logging
from swarms.utils import check_device
# When CUDA is not available
device = check_device()
print(device) # If CUDA is not available it should return torch.device('cpu')
```
### Example 3: Multiple GPU Available
```python
import torch
import logging
from swarms.utils import check_device
# When multiple GPUs are available
device = check_device()
print(device) # Should return a list of available GPU devices
```
## Tips and Additional Information
- This function is useful when a user wants to exploit CUDA capabilities for faster computation but unsure of the available devices. This function abstracts all the necessary checks and provides a list of CUDA devices to the user.
- The `memory_threshold` and `capability_threshold` are utilized to filter the GPU devices. The GPUs which have memory usage above the `memory_threshold` and compute capability below the `capability_threshold` are not considered.
- As of now, CPU does not have memory or capability values, therefore, in the respective cases, it will be returned as default without any comparison.
## Relevant Resources
- For more details about the CUDA properties functions used (`torch.cuda.get_device_capability, torch.cuda.get_device_properties`), please refer to the official PyTorch [CUDA semantics documentation](https://pytorch.org/docs/stable/notes/cuda.html).
- For more information about Torch device objects, you can refer to the official PyTorch [device documentation](https://pytorch.org/docs/stable/tensor_attributes.html#torch-device).
- For a better understanding of how the `logging` module works in Python, see the official Python [logging documentation](https://docs.python.org/3/library/logging.html).

@ -0,0 +1,86 @@
# display_markdown_message
# Module Name: `display_markdown_message`
## Introduction
`display_markdown_message` is a useful utility function for creating visually-pleasing markdown messages within Python scripts. This function automatically manages multiline strings with lots of indentation and makes single-line messages with ">" tags easy to read, providing users with convenient and elegant logging or messaging capacity.
## Function Definition and Arguments
Function Definition:
```python
def display_markdown_message(message: str, color: str = "cyan"):
```
This function accepts two parameters:
|Parameter |Type |Default Value |Description |
|--- |--- |--- |--- |
|message |str |None |This is the message that is to be displayed. This should be a string. It can contain markdown syntax.|
|color |str |"cyan" |This allows you to choose the color of the message. Default is "cyan". Accepts any valid color name.|
## Functionality and Usage
This utility function is used to display a markdown formatted message on the console. It accepts a message as a string and an optional color for the message. The function is ideal for generating stylized print outputs such as headers, status updates or pretty notifications.
By default, any text within the string which is enclosed within `>` tags or `---` is treated specially:
- Lines encased in `>` tags are rendered as a blockquote in markdown.
- Lines consisting of `---` are rendered as horizontal rules.
The function automatically strips off leading and trailing whitespaces from any line within the message, maintaining aesthetic consistency in your console output.
### Usage Examples
#### Basic Example
```python
display_markdown_message("> This is an important message", color="red")
```
Output:
```md
> **This is an important message**
```
This example will print out the string "This is an important message" in red color, enclosed in a blockquote tag.
#### Multiline Example
```python
message = """
> Header
My normal message here.
---
Another important information
"""
display_markdown_message(message, color="green")
```
Output:
```md
> **Header**
My normal message here.
_____
Another important information
```
The output is a green colored markdown styled text with the "Header" enclosed in a blockquote, followed by the phrase "My normal message here", a horizontal rule, and finally another phrase, "Another important information".
## Additional Information
Use newline characters `\n` to separate the lines of the message. Remember, each line of the message is stripped of leading and trailing whitespaces. If you have special markdown requirements, you may need to revise the input message string accordingly.
Also, keep in mind the console or terminal's ability to display the chosen color. If a particular console does not support the chosen color, the output may fallback to the default console color.
For a full list of color names supported by the `Console` module, refer to the official [Console documentation](http://console.readthedocs.io/).
## References and Resources
- Python Strings: https://docs.python.org/3/tutorial/introduction.html#strings
- Python Markdown: https://pypi.org/project/markdown/
- Console module: https://console.readthedocs.io/

@ -0,0 +1,114 @@
# extract_code_from_markdown
# swarms.utils Module
The `swarms.utils` module provides utility functions designed to facilitate specific tasks within the main Swarm codebase. The function `extract_code_from_markdown` is a critical function within this module that we will document in this example.
## Overview and Introduction
Many software projects use Markdown extensively for writing documentation, tutorials, and other text documents that can be easily rendered and viewed in different formats, including HTML.
The `extract_code_from_markdown` function plays a crucial role within the swarms.utils library. As developers write large volumes of Markdown, they often need to isolate code snippets from the whole Markdown file body. These isolated snippets can be used to generate test cases, transform into other languages, or analyze for metrics.
## Function Definition: `extract_code_from_markdown`
```python
def extract_code_from_markdown(markdown_content: str) -> str:
"""
Extracts code blocks from a Markdown string and returns them as a single string.
Args:
- markdown_content (str): The Markdown content as a string.
Returns:
- str: A single string containing all the code blocks separated by newlines.
"""
# Regular expression for fenced code blocks
pattern = r"```(?:\w+\n)?(.*?)```"
matches = re.findall(pattern, markdown_content, re.DOTALL)
# Concatenate all code blocks separated by newlines
return "\n".join(code.strip() for code in matches)
```
### Arguments
The function `extract_code_from_markdown` takes one argument:
| Argument | Description | Type | Default Value |
|-----------------------|----------------------------------------|-------------|-------------------|
| markdown_content | The input markdown content as a string | str | N/A |
## Function Explanation and Usage
This function uses a regular expression to find all fenced code blocks in a Markdown string. The pattern `r"```(?:\w+\n)?(.*?)```"` matches strings that start and end with three backticks, optionally followed by a newline and then any number of any characters (the `.*?` part) until the first occurrence of another triple backtick set.
Once we have the matches, we join all the code blocks into a single string, each block separated by a newline.
The method's functionality is particularly useful when we need to extract code blocks from markdown content for secondary processing, such as syntax highlighting or execution in a different environment.
### Usage Examples
Below are three examples of how you might use this function:
#### Example 1:
Extracting code blocks from a simple markdown string.
```python
import re
from swarms.utils import extract_code_from_markdown
markdown_string = '''# Example
This is an example of a code block:
```python
print("Hello World!")
``` '''
print(extract_code_from_markdown(markdown_string))
```
#### Example 2:
Extracting code blocks from a markdown file.
```python
import re
def extract_code_from_markdown(markdown_content: str) -> str:
pattern = r"```(?:\w+\n)?(.*?)```"
matches = re.findall(pattern, markdown_content, re.DOTALL)
return "\n".join(code.strip() for code in matches)
# Assume that 'example.md' contains multiple code blocks
with open('example.md', 'r') as file:
markdown_content = file.read()
print(extract_code_from_markdown(markdown_content))
```
#### Example 3:
Using the function in a pipeline to extract and then analyze code blocks.
```python
import re
def extract_code_from_markdown(markdown_content: str) -> str:
pattern = r"```(?:\w+\n)?(.*?)```"
matches = re.findall(pattern, markdown_content, re.DOTALL)
return "\n".join(code.strip() for code in matches)
def analyze_code_blocks(code: str):
# Add your analysis logic here
pass
# Assume that 'example.md' contains multiple code blocks
with open('example.md', 'r') as file:
markdown_content = file.read()
code_blocks = extract_code_from_markdown(markdown_content)
analyze_code_blocks(code_blocks)
```
## Conclusion
This concludes the detailed documentation of the `extract_code_from_markdown` function from the swarms.utils module. With this documentation, you should be able to understand the function's purpose, how it works, its parameters, and see examples of how to use it effectively.

@ -0,0 +1,94 @@
# find_image_path
Firstly, we will divide this documentation into multiple sections.
# Overview
The module **swarms.utils** has the main goal of providing necessary utility functions that are crucial during the creation of the swarm intelligence frameworks. These utility functions can include common operations such as handling input-output operations for files, handling text parsing, and handling basic mathematical computations necessary during the creation of swarm intelligence models.
The current function `find_image_path` in the module is aimed at extracting an image path from a given text document.
# Function Detailed Explanation
## Definition
The function `find_image_path` takes a singular argument as an input:
```python
def find_image_path(text):
# function body
```
## Parameter
The parameter `text` in the function is a string that represents the document or text from which the function is trying to extract all paths to the images present. The function scans the given text, looking for <em>absolute</em> or <em>relative</em> paths to image files (.png, .jpg, .jpeg) on the disk.
| Parameter Name | Data Type | Default Value | Description |
|:--------------:|:---------:|:-------------:|:--------:|
| `text` | `str` | - | The text content to scan for image paths |
## Return Value
The return value of the function `find_image_path` is a string that represents the longest existing image path extracted from the input text. If no image paths exist within the text, the function returns `None`.
| Return Value | Data Type | Description |
|:------------:|:-----------:|:-----------:|
| Path | `str` | Longest image path found in the text or `None` if no path found |
# Function's Code
The function `find_image_path` performs text parsing and pattern recognition to find image paths within the provided text. The function uses `regular expressions (re)` module to detect all potential paths.
```python
def find_image_path(text):
pattern = r"([A-Za-z]:\\[^:\n]*?\.(png|jpg|jpeg|PNG|JPG|JPEG))|(/[^:\n]*?\.(png|jpg|jpeg|PNG|JPG|JPEG))"
matches = [
match.group()
for match in re.finditer(pattern, text)
if match.group()
]
matches += [match.replace("\\", "") for match in matches if match]
existing_paths = [
match for match in matches if os.path.exists(match)
]
return max(existing_paths, key=len) if existing_paths else None
```
# Usage Examples
Let's consider examples of how the function `find_image_path` can be used in different scenarios.
**Example 1:**
Consider the case where a text without any image path is provided.
```python
from swarms.utils import find_image_path
text = "There are no image paths in this text"
print(find_image_path(text)) # Outputs: None
```
**Example 2:**
Consider the case where the text has multiple image paths.
```python
from swarms.utils import find_image_path
text = "Here is an image path: /home/user/image1.png. Here is another one: C:\\Users\\User\\Documents\\image2.jpeg"
print(find_image_path(text)) # Outputs: the longest image path (depends on your file system and existing files)
```
**Example 3:**
In the final example, we consider a case where the text has an image path, but the file does not exist.
```python
from swarms.utils import find_image_path
text = "Here is an image path: /home/user/non_existant.png"
print(find_image_path(text)) # Outputs: None
```
# Closing Notes
In conclusion, the `find_image_path` function is crucial in the `swarms.utils` module as it supports a key operation of identifying image paths within given input text. This allows users to automate the extraction of such data from larger documents/text. However, it's important to note the function returns only existing paths in your file system and only the longest if multiple exist.

@ -0,0 +1,82 @@
# limit_tokens_from_string
## Introduction
The `Swarms.utils` library contains utility functions used across codes that handle machine learning and other operations. The `Swarms.utils` library includes a notable function named `limit_tokens_from_string()`. This function particularly limits the number of tokens in a given string.
# Function: limit_tokens_from_string()
Within the `Swarms.utils` library, there is a method `limit_tokens_from_string(string: str, model: str = "gpt-4", limit: int = 500) -> str:`
## Description
The function `limit_tokens_from_string()` limits the number of tokens in a given string based on the specified threshold. It is primarily useful when you are handling large text data and need to chunk or limit your text to a certain length. Limiting token length could be useful in various scenarios such as when working with data with limited computational resources, or when dealing with models that accept a specific maximum limit of text.
## Parameters
| Parameter | Type | Default Value | Description
| :-----------| :----------- | :------------ | :------------|
| `string` | `str` | `None` | The input string from which the tokens need to be limited. |
| `model` | `str` | `"gpt-4"` | The model used to encode and decode the token. The function defaults to `gpt-4` but you can specify any model supported by `tiktoken`. If a model is not found, it falls back to use `gpt2` |
| `limit` | `int` | `500` | The limit up to which the tokens have to be sliced. Default limit is 500.|
## Returns
| Return | Type | Description
| :-----------| :----------- | :------------
| `out` | `str` | A string that is constructed back from the encoded tokens that have been limited to a count of `limit` |
## Method Detail and Usage Examples
The method `limit_tokens_from_string()` takes in three parameters - `string`, `model`, and `limit`.
First, it tries to get the encoding for the model specified in the `model` argument using `tiktoken.encoding_for_model(model)`. In case the specified model is not found, the function uses `gpt2` model encoding as a fallback.
Next, the input `string` is tokenized using the `encode` method on the `encoding` tensor. This results in the `encoded` tensor.
Then, the function slices the `encoded` tensor to get the first `limit` number of tokens.
Finally, the function converts back the tokens into the string using the `decode` method of the `encoding` tensor. The resulting string `out` is returned.
### Example 1:
```python
from swarms.utils import limit_tokens_from_string
# longer input string
string = "This is a very long string that needs to be tokenized. This string might exceed the maximum token limit, so it will need to be truncated."
# lower token limit
limit = 10
output = limit_tokens_from_string(string, limit=limit)
```
### Example 2:
```python
from swarms.utils import limit_tokens_from_string
# longer input string with different model
string = "This string will be tokenized using gpt2 model. If the string is too long, it will be truncated."
# model
model = "gpt2"
output = limit_tokens_from_string(string, model=model)
```
### Example 3:
```python
from swarms.utils import limit_tokens_from_string
# try with a random model string
string = "In case the method does not find the specified model, it will fall back to gpt2 model."
# model
model = "gpt-4"
output = limit_tokens_from_string(string, model=model)
```
**Note:** If specifying a model not supported by `tiktoken` intentionally, it will fall back to `gpt2` model for encoding.

@ -0,0 +1,102 @@
# load_model_torch
# load_model_torch: Utility Function Documentation
## Introduction:
`load_model_torch` is a utility function in the `swarms.utils` library that is designed to load a saved PyTorch model and move it to the designated device. It provides flexibility allowing the user to specify the model file location, the device where the loaded model should be moved to, whether to strictly enforce the keys in the state dictionary to match the keys returned by the model's `state_dict()`, and many more.
Moreover, if the saved model file only contains the state dictionary, but not the model architecture, you can pass the model architecture as an argument.
## Function Definition and Parameters:
```python
def load_model_torch(
model_path: str = None,
device: torch.device = None,
model: nn.Module = None,
strict: bool = True,
map_location=None,
*args,
**kwargs,
) -> nn.Module:
```
The following table describes the parameters in detail:
| Name | Type | Default Value | Description |
| ------ | ------ | ------------- | ------------|
| model_path | str | None | A string specifying the path to the saved model file on disk. _Required_ |
| device | torch.device | None | A `torch.device` object that specifies the target device for the loaded model. If not provided, the function checks for the availability of a GPU and uses it if available. If not, it defaults to CPU. |
| model | nn.Module | None | An instance of `torch.nn.Module` representing the model's architecture. This parameter is required if the model file only contains the model's state dictionary and not the model architecture. |
| strict | bool | True | A boolean that determines whether to strictly enforce that the keys in the state dictionary match the keys returned by the model's `state_dict()` function. If set to `True`, the function will raise a KeyError when the state dictionary and `state_dict()` keys do not match. |
| map_location | callable | None | A function to remap the storage locations of the loaded model's parameters. Useful for loading models saved on a device type that is different from the current one. |
| *args, **kwargs | - | - | Additional arguments and keyword arguments to be passed to `torch.load`.
Returns:
- `torch.nn.Module` - The loaded model after moving it to the desired device.
Raises:
- `FileNotFoundError` - If the saved model file is not found at the specified path.
- `RuntimeError` - If there was an error while loading the model.
## Example of Usage:
This function can be used directly inside your code as shown in the following examples:
### Example 1:
Loading a model without specifying a device results in the function choosing the most optimal available device automatically.
```python
from swarms.utils import load_model_torch
import torch.nn as nn
# Assume `mymodel.pth` is in the current directory
model_path = "./mymodel.pth"
# Define your model architecture if the model file only contains state dict
class MyModel(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(10, 2)
def forward(self, x):
return self.linear(x)
model = MyModel()
# Load the model
loaded_model = load_model_torch(model_path, model=model)
# Now you can use the loaded model for prediction or further training
```
### Example 2:
Explicitly specifying a device.
```python
# Assume `mymodel.pth` is in the current directory
model_path = "./mymodel.pth"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load the model
loaded_model = load_model_torch(model_path, device=device)
```
### Example 3:
Using a model file that contains only the state dictionary, not the model architecture.
```python
# Assume `mymodel_state_dict.pth` is in the current directory
model_path = "./mymodel_state_dict.pth"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Define your model architecture
model = MyModel()
# Load the model
loaded_model = load_model_torch(model_path, device=device, model=model)
```
This gives you an insight on how to use `load_model_torch` utility function from `swarms.utils` library efficiently. Always remember to pass the model path argument while the other arguments can be optional based on your requirements. Furthermore, handle exceptions properly for smooth functioning of your PyTorch related projects.

@ -0,0 +1,78 @@
# math_eval
The `math_eval` function is a python decorator that wraps around a function to run two functions on the same inputs and compare their results. The decorator can be used for testing functions that are expected to have equivalent functionality, or in situations where two different methods are used to calculate or retrieve a value, and the results need to be compared.
The `math_eval` function in this case accepts two functions as parameters: `func1` and `func2`, and returns a decorator. This returned decorator, when applied to a function, enhances that function to execute both `func1` and `func2`, and compare the results.
This can be particularly useful in situations when you are implementing a new function and wants to compare its behavior and results with that of an existing one under the same set of input parameters. It also logs the results if they do not match which could be quite useful during the debug process.
## Usage Example
Let's say you have two functions: `ground_truth` and `generated_func`, that have similar functionalities or serve the same purpose. You are writing a new function called `test_func`, and you'd like to compare the results of `ground_truth` and `generated_func` when `test_func` is run. Here is how you would use the `math_eval` decorator:
```python
@math_eval(ground_truth, generated_func)
def test_func(x):
return x
result1, result2 = test_func(5)
print(f"Result from ground_truth: {result1}")
print(f"Result from generated_func: {result2}")
```
## Parameters
| Parameter | Data Type | Description |
| ---- | ---- | ---- |
| func1 | Callable | The first function whose result you want to compare. |
| func2 | Callable | The second function whose result you want to compare. |
The data types for `func1` and `func2` cannot be specified as they can be any python function (or callable object). The decorator verifies that they are callable and exceptions are handled within the decorator function.
## Return Values
The `math_eval` function does not return a direct value, since it is a decorator. When applied to a function, it alters the behavior of the wrapped function to return two values:
1. `result1`: The result of running `func1` with the given input parameters.
2. `result2`: The result of running `func2` with the given input parameters.
These two return values are provided in that order as a tuple.
## Source Code
Here's how to implement the `math_eval` decorator:
```python
import functools
import logging
def math_eval(func1, func2):
"""Math evaluation decorator."""
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
try:
result1 = func1(*args, **kwargs)
except Exception as e:
logging.error(f"Error in func1: {e}")
result1 = None
try:
result2 = func2(*args, **kwargs)
except Exception as e:
logging.error(f"Error in func2: {e}")
result2 = None
if result1 != result2:
logging.warning(
f"Outputs do not match: {result1} != {result2}"
)
return result1, result2
return wrapper
return decorator
```
Please note that the code is logging exceptions to facilitate debugging, but the actual processing and handling of the exception would depend on how you want your application to respond to exceptions. Therefore, you may want to customize the error handling depending upon your application's requirements.

@ -0,0 +1,86 @@
# metrics_decorator
This documentation explains the use and functionality of the `metrics_decorator` function in the LLM (Large Language Models).
The `metrics_decorator` function is a standard Python decorator that augments a specific function by wrapping extra functionality around it. It is commonly used for things like timing, logging or memoization.
--
The `metrics_decorator` in LLM is specially designed to measure and calculate three key performance metrics when generating language models:
1. `Time to First Token`: Measures the elapsed time from the start of function execution until the generation of the first token.
2. `Generation Latency`: It measures the total time taken for a complete run.
3. `Throughput`: Calculates the rate of production of tokens per unit of time.
```python
def metrics_decorator(func: Callable):
"""
Metrics decorator for LLM
Args:
func (Callable): The function to be decorated.
"""
@wraps(func)
def wrapper(self, *args, **kwargs):
"""
An inner function that wraps the decorated function. It calculates 'Time to First Token',
'Generation Latency' and 'Throughput' metrics.
Args:
self : The object instance.
*args : Variable length argument list of the decorated function.
**kwargs : Arbitrary keyword arguments of the decorated function.
"""
# Measure Time to First Token
start_time = time.time()
result = func(self, *args, **kwargs)
first_token_time = time.time()
# Measure Generation Latency
end_time = time.time()
# Calculate Throughput (assuming the function returns a list of tokens)
throughput = len(result) / (end_time - start_time)
return f"""
Time to First Token: {first_token_time - start_time}
Generation Latency: {end_time - start_time}
Throughput: {throughput}
"""
return wrapper
```
## Example Usage
Now let's discuss the usage of the `metrics_decorator` function with an example.
Assuming that we have a language generation function called `text_generator()` that generates a list of tokens.
```python
@metrics_decorator
def text_generator(self, text: str):
"""
Args:
text (str): The input text.
Returns:
A list of tokens generated from the input text.
"""
# language generation implementation goes here
return tokens
# Instantiate the class and call the decorated function
obj = ClassName()
obj.text_generator("Hello, world!")
```
When the decorated `text_generator()` function is called, it will measure and return:
- Time elapsed until the first token is generated.
- The total execution time of the function.
- The rate of tokens generation per unit time.
This example provides a basic overview of how a function can be decorated with the `metrics_decorator`. The provided `func` argument could be any method from any class, as long as it complies with the structure defined in `metrics_decorator`. It is worth noting that the decorated function must return a list of tokens for the `Throughput` metric to work correctly.
Remember, applying the `metrics_decorator` does not affect the original functionality of the decorated function, it just adds additional measurement and logging capabilities to it. It's a great utility for tracking and optimizing the performance of your language models.

@ -0,0 +1,71 @@
# pdf_to_text
## Introduction
The function `pdf_to_text` is a Python utility for converting a PDF file into a string of text content. It leverages the `PyPDF2` library, an excellent Python library for processing PDF files. The function takes in a PDF file's path and reads its content, subsequently returning the extracted textual data.
This function can be very useful when you want to extract textual information from PDF files automatically. For instance, when processing a large number of documents, performing textual analysis, or when you're dealing with text data that is only available in PDF format.
## Class / Function Definition
`pdf_to_text` is a standalone function defined as follows:
```python
def pdf_to_text(pdf_path: str) -> str:
```
## Parameters
| Parameter | Type | Description |
|:-:|---|---|
| pdf_path | str | The path to the PDF file to be converted |
## Returns
| Return Value | Type | Description |
|:-:|---|---|
| text | str | The text extracted from the PDF file. |
## Raises
| Exception | Description |
|---|---|
| FileNotFoundError | If the PDF file is not found at the specified path. |
| Exception | If there is an error in reading the PDF file. |
## Function Description
`pdf_to_text` utilises the `PdfReader` function from the `PyPDF2` library to read the PDF file. If the PDF file does not exist at the specified path or there was an error while reading the file, appropriate exceptions will be raised. It then iterates through each page in the PDF and uses the `extract_text` function to extract the text content from each page. These contents are then concatenated into a single variable and returned as the result.
## Usage Examples
To use this function, you first need to install the `PyPDF2` library. It can be installed via pip:
```python
!pip install pypdf2
```
Then, you should import the `pdf_to_text` function:
```python
from swarms.utils import pdf_to_text
```
Here is an example of how to use `pdf_to_text`:
```python
# Define the path to the pdf file
pdf_path = 'sample.pdf'
# Use the function to extract text
text = pdf_to_text(pdf_path)
# Print the extracted text
print(text)
```
## Tips and Additional Information
- Ensure that the PDF file path is valid and that the file exists at the specified location. If the file does not exist, a `FileNotFoundError` will be raised.
- This function reads the text from the PDF. It does not handle images, graphical elements, or any non-text content.
- If the PDF contains scanned images rather than textual data, the `extract_text` function may not be able to extract any text. In such cases, you would require OCR (Optical Character Recognition) tools to extract the text.
- Be aware of the possibility that the output string might contain special characters or escape sequences because they were part of the PDF's content. You might need to clean the resulting text according to your requirements.
- The function uses the PyPDF2 library to facilitate the PDF reading and text extraction. For any issues related to PDF manipulation, consult the [PyPDF2 library documentation](https://pythonhosted.org/PyPDF2/).

@ -1,128 +0,0 @@
# Phoenix Trace Decorator Documentation
## Introduction
Welcome to the documentation for the `phoenix_trace_decorator` module. This module provides a convenient decorator for tracing Python functions and capturing exceptions using Phoenix, a versatile tracing and monitoring tool. Phoenix allows you to gain insights into the execution of your code, capture errors, and monitor performance.
## Table of Contents
1. [Installation](#installation)
2. [Getting Started](#getting-started)
3. [Decorator Usage](#decorator-usage)
4. [Examples](#examples)
5. [Best Practices](#best-practices)
6. [References](#references)
## 1. Installation <a name="installation"></a>
Before using the `phoenix_trace_decorator`, you need to install the Swarms library. You can install Phoenix using pip:
```bash
pip install swarms
```
## 2. Getting Started <a name="getting-started"></a>
Phoenix is a powerful tracing and monitoring tool, and the `phoenix_trace_decorator` simplifies the process of tracing functions and capturing exceptions within your Python code. To begin, ensure that Phoenix is installed, and then import the `phoenix_trace_decorator` module into your Python script.
```python
from swarms import phoenix_trace_decorator
```
## 3. Decorator Usage <a name="decorator-usage"></a>
The `phoenix_trace_decorator` module provides a decorator, `phoenix_trace_decorator`, which can be applied to functions you want to trace. The decorator takes a single argument, a docstring that describes the purpose of the function being traced.
Here is the basic structure of using the decorator:
```python
@phoenix_trace_decorator("Description of the function")
def my_function(param1, param2):
# Function implementation
pass
```
## 4. Examples <a name="examples"></a>
Let's explore some practical examples of using the `phoenix_trace_decorator` in your code.
### Example 1: Basic Tracing
In this example, we'll trace a simple function and print a message.
```python
@phoenix_trace_decorator("Tracing a basic function")
def hello_world():
print("Hello, World!")
# Call the decorated function
hello_world()
```
### Example 2: Tracing a Function with Parameters
You can use the decorator with functions that have parameters.
```python
@phoenix_trace_decorator("Tracing a function with parameters")
def add_numbers(a, b):
result = a + b
print(f"Result: {result}")
# Call the decorated function with parameters
add_numbers(2, 3)
```
### Example 3: Tracing Nested Calls
The decorator can also trace nested function calls.
```python
@phoenix_trace_decorator("Outer function")
def outer_function():
print("Outer function")
@phoenix_trace_decorator("Inner function")
def inner_function():
print("Inner function")
inner_function()
# Call the decorated functions
outer_function()
```
### Example 4: Exception Handling
Phoenix can capture exceptions and provide detailed information about them.
```python
@phoenix_trace_decorator("Function with exception handling")
def divide(a, b):
try:
result = a / b
except ZeroDivisionError as e:
raise ValueError("Division by zero") from e
# Call the decorated function with an exception
try:
divide(5, 0)
except ValueError as e:
print(f"Error: {e}")
```
## 5. Best Practices <a name="best-practices"></a>
When using the `phoenix_trace_decorator`, consider the following best practices:
- Use meaningful docstrings to describe the purpose of the traced functions.
- Keep your tracing focused on critical parts of your code.
- Make sure Phoenix is properly configured and running before using the decorator.
## 6. References <a name="references"></a>
For more information on Phoenix and advanced usage, please refer to the [Phoenix Documentation](https://phoenix-docs.readthedocs.io/en/latest/).
---
By following this documentation, you can effectively use the `phoenix_trace_decorator` to trace your Python functions, capture exceptions, and gain insights into the execution of your code. This tool is valuable for debugging, performance optimization, and monitoring the health of your applications.

@ -0,0 +1,102 @@
# prep_torch_inference
```python
def prep_torch_inference(
model_path: str = None,
device: torch.device = None,
*args,
**kwargs,
):
"""
Prepare a Torch model for inference.
Args:
model_path (str): Path to the model file.
device (torch.device): Device to run the model on.
*args: Additional positional arguments.
**kwargs: Additional keyword arguments.
Returns:
torch.nn.Module: The prepared model.
"""
try:
model = load_model_torch(model_path, device)
model.eval()
return model
except Exception as e:
# Add error handling code here
print(f"Error occurred while preparing Torch model: {e}")
return None
```
This method is part of the 'swarms.utils' module. It accepts a model file path and a torch device as input and returns a model that is ready for inference.
## Detailed Functionality
The method loads a PyTorch model from the file specified by `model_path`. This model is then moved to the specified `device` if it is provided. Subsequently, the method sets the model to evaluation mode by calling `model.eval()`. This is a crucial step when preparing a model for inference, as certain layers like dropout or batch normalization behave differently during training vs during evaluation.
In the case of any exception (e.g., the model file not found or the device unavailable), it prints an error message and returns `None`.
## Parameters
| Parameter | Type | Description | Default |
|-----------|------|-------------|---------|
| model_path | str | Path to the model file. | None |
| device | torch.device | Device to run the model on. | None |
| args | tuple | Additional positional arguments. | None |
| kwargs | dict | Additional keyword arguments. | None |
## Returns
| Type | Description |
|------|-------------|
| torch.nn.Module | The prepared model ready for inference. Returns `None` if any exception occurs. |
## Usage Examples
Here are some examples of how you can use the `prep_torch_inference` method. Before that, you need to import the necessary modules as follows:
```python
import torch
from swarms.utils import prep_torch_inference, load_model_torch
```
### Example 1: Load a model for inference on CPU
```python
model_path = "saved_model.pth"
model = prep_torch_inference(model_path)
if model is not None:
print("Model loaded successfully and is ready for inference.")
else:
print("Failed to load the model.")
```
### Example 2: Load a model for inference on CUDA device
```python
model_path = "saved_model.pth"
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = prep_torch_inference(model_path, device)
if model is not None:
print(f"Model loaded successfully on device {device} and is ready for inference.")
else:
print("Failed to load the model.")
```
### Example 3: Load a model with additional arguments for `load_model_torch`
```python
model_path = "saved_model.pth"
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
# Suppose load_model_torch accepts an additional argument, map_location
model = prep_torch_inference(model_path, device, map_location=device)
if model is not None:
print(f"Model loaded successfully on device {device} and is ready for inference.")
else:
print("Failed to load the model.")
```
Please note, you need to ensure the given model path does exist and the device is available on your machine, else `prep_torch_inference` method will return `None`. Depending on the complexity and size of your models, loading them onto a specific device might take a while. So it's important that you take this into consideration when designing your machine learning workflows.

@ -0,0 +1,110 @@
# print_class_parameters
# Module Function Name: print_class_parameters
The `print_class_parameters` function is a utility function developed to help developers and users alike in retrieving and printing the parameters of a class constructor in Python, either in standard output or returned as a dictionary if the `api_format` is set to `True`.
This utility function utilizes the `inspect` module to fetch the signature of the class constructor and fetches the parameters from the obtained signature. The parameter values and their respective types are then outputted.
This function allows developers to easily inspect and understand the class' constructor parameters without the need to individually go through the class structure. This eases the testing and debugging process for developers and users alike, aiding in generating more efficient and readable code.
__Function Definition:__
```python
def print_class_parameters(cls, api_format: bool = False):
```
__Parameters:__
| Parameter | Type | Description | Default value |
|---|---|---|---|
| cls | type | The Python class to inspect. | None |
| api_format | bool | Flag to determine if the output should be returned in dictionary format (if set to True) or printed out (if set to False) | False |
__Functionality and Usage:__
Inside the `print_class_parameters` function, it starts by getting the signature of the constructor of the inputted class by invoking `inspect.signature(cls.__init__)`. It then extracts the parameters from the signature and stores it in the `params` variable.
If the `api_format` argument is set to `True`, instead of printing the parameters and their types, it stores them inside a dictionary where each key-value pair is a parameter name and its type. It then returns this dictionary.
If `api_format` is set to `False` or not set at all (defaulting to False), the function iterates over the parameters and prints the parameter name and its type. "self" parameters are excluded from the output as they are inherent to all class methods in Python.
A possible exception that may occur during the execution of this function is during the invocation of the `inspect.signature()` function call. If the inputted class does not have an `__init__` method or any error occurs during the retrieval of the class constructor's signature, an exception will be triggered. In that case, an error message that includes the error details is printed out.
__Usage and Examples:__
Assuming the existence of a class:
```python
class Agent:
def __init__(self, x: int, y: int):
self.x = x
self.y = y
```
One could use `print_class_parameters` in its typical usage:
```python
print_class_parameters(Agent)
```
Results in:
```
Parameter: x, Type: <class 'int'>
Parameter: y, Type: <class 'int'>
```
Or, with `api_format` set to `True`
```python
output = print_class_parameters(Agent, api_format=True)
print(output)
```
Results in:
```
{'x': "<class 'int'>", 'y': "<class 'int'>"}
```
__Note:__
The function `print_class_parameters` is not limited to custom classes. It can inspect built-in Python classes such as `list`, `dict`, and others. However, it is most useful when inspecting custom-defined classes that aren't inherently documented in Python or third-party libraries.
__Source Code__
```python
def print_class_parameters(cls, api_format: bool = False):
"""
Print the parameters of a class constructor.
Parameters:
cls (type): The class to inspect.
Example:
>>> print_class_parameters(Agent)
Parameter: x, Type: <class 'int'>
Parameter: y, Type: <class 'int'>
"""
try:
# Get the parameters of the class constructor
sig = inspect.signature(cls.__init__)
params = sig.parameters
if api_format:
param_dict = {}
for name, param in params.items():
if name == "self":
continue
param_dict[name] = str(param.annotation)
return param_dict
# Print the parameters
for name, param in params.items():
if name == "self":
continue
print(f"Parameter: {name}, Type: {param.annotation}")
except Exception as e:
print(f"An error occurred while inspecting the class: {e}")
```

@ -1,58 +1,34 @@
import os
from dotenv import load_dotenv
from swarms.models import Gemini
# Import the OpenAIChat model and the Agent struct
from swarms.models import OpenAIChat
from swarms.structs import Agent
# Load environment variables
# Load the environment variables
load_dotenv()
# Get the API key from the environment
api_key = os.environ.get("GOOGLE_API_KEY")
if not api_key:
raise ValueError("Gemini API key not found. Please set it in your .env file")
# Initialize the first agent (Gemini Pro Vision) for image analysis
agent_analysis = Agent(
llm=Gemini(
temperature=0.8,
model_name="gemini-pro-vision",
gemini_api_key=api_key
),
max_loops=1,
autosave=True,
dashboard=True,
api_key = os.environ.get("OPENAI_API_KEY")
# Initialize the language model
llm = OpenAIChat(
temperature=0.5,
model_name="gpt-4",
openai_api_key=api_key,
max_tokens=1000,
)
# Initialize the second agent (Gemini Pro) for text-based tasks
agent_instruction = Agent(
llm=Gemini(
temperature=0.8,
model_name="gemini-pro",
gemini_api_key=api_key
),
## Initialize the workflow
agent = Agent(
llm=llm,
max_loops=1,
autosave=True,
dashboard=True,
dashboard=False,
streaming_on=True,
verbose=True,
)
# Task for the first agent: Image Analysis
task_analysis = """
Analyze this logo and summarize its content, then give a structured list of suggested improvements.
"""
img = 'swarmslogobanner.png' # Replace with your image file name
# Run the first agent on the task
analysis_results = agent_analysis.run(task=task_analysis, img=img)
# Task for the second agent: Instructions for a better logo
task_instruction = f"""
Based on the analysis and suggestions for the logo:
{analysis_results}
Generate detailed instructions for creating an improved version of this logo.
"""
# Run the second agent on the task
instruction_results = agent_instruction.run(task=task_instruction)
.............
# Run the workflow on a task
agent.run("Generate a 10,000 word blog on health and wellness.")

@ -58,19 +58,14 @@ nav:
- Home:
- Overview: "index.md"
- Contributing: "contributing.md"
- Docker Container Setup: "docker_setup.md"
- Swarms:
- Overview: "swarms/index.md"
- swarms.swarms:
- AbstractSwarm: "swarms/swarms/abstractswarm.md"
- GodMode: "swarms/swarms/godmode.md"
- Groupchat: "swarms/swarms/groupchat.md"
- swarms.workers:
- Overview: "swarms/workers/index.md"
- AbstractWorker: "swarms/workers/abstract_worker.md"
- swarms.agents:
- AbstractAgent: "swarms/agents/abstract_agent.md"
- OmniModalAgent: "swarms/agents/omni_agent.md"
- Agents:
- WorkerAgent: "swarms/agents/workeragent.md"
- OmniAgent: "swarms/agents/omni_agent.md"
- AbstractAgent: "swarms/agents/abstractagent.md"
- ToolAgent: "swarms/agents/toolagent.md"
- swarms.models:
- Language:
- BaseLLM: "swarms/models/base_llm.md"
@ -83,6 +78,7 @@ nav:
- vLLM: "swarms/models/vllm.md"
- MPT7B: "swarms/models/mpt.md"
- Mistral: "swarms/models/mistral.md"
- Mixtral: "swarms/models/mixtral.md"
- MultiModal:
- BaseMultiModalModel: "swarms/models/base_multimodal_model.md"
- Fuyu: "swarms/models/fuyu.md"
@ -98,18 +94,57 @@ nav:
- ElevenLabsText2SpeechTool: "swarms/models/elevenlabs.md"
- OpenAITTS: "swarms/models/openai_tts.md"
- Gemini: "swarms/models/gemini.md"
- ZeroscopeTTV: "swarms/models/zeroscope.md"
- swarms.structs:
- Overview: "swarms/structs/overview.md"
- AutoScaler: "swarms/swarms/autoscaler.md"
- Agent: "swarms/structs/agent.md"
- SequentialWorkflow: 'swarms/structs/sequential_workflow.md'
- Foundational Structures:
- agent: "swarms/structs/agent.md"
- basestructure: "swarms/structs/basestructure.md"
- artifactupload: "swarms/structs/artifactupload.md"
- taskinput: "swarms/structs/taskinput.md"
- stepinput: "swarms/structs/stepinput.md"
- artifact: "swarms/structs/artifact.md"
- task: "swarms/structs/task.md"
- Workflows:
- recursiveworkflow: "swarms/structs/recursiveworkflow.md"
- concurrentworkflow: "swarms/structs/concurrentworkflow.md"
- nonlinearworkflow: "swarms/structs/nonlinearworkflow.md"
- sequential_workflow: "swarms/structs/sequential_workflow.md"
- workflow: "swarms/structs/workflow.md"
- baseworkflow: "swarms/structs/baseworkflow.md"
- Multi Agent Architectures:
- conversation: "swarms/structs/conversation.md"
- groupchat: "swarms/structs/groupchat.md"
- swarmnetwork: "swarms/structs/swarmnetwork.md"
- groupchatmanager: "swarms/structs/groupchatmanager.md"
- swarms.tokenizers:
- Language:
- Tokenizer: "swarms/tokenizers/tokenizer.md"
- CohereTokenizer: "swarms/tokenizers/coheretokenizer.md"
- BaseTokenizer: "swarms/tokenizers/basetokenizer.md"
- HuggingfaceTokenizer: "swarms/tokenizers/huggingfacetokenizer.md"
- SentencepieceTokenizer: "swarms/tokenizers/sentencepiecetokenizer.md"
- AnthropicTokenizer: "swarms/tokenizers/anthropictokenizer.md"
- OpenaiTokenizer: "swarms/tokenizers/openaitokenizer.md"
- swarms.memory:
- Vector Databases:
- Weaviate: "swarms/memory/weaviate.md"
- PineconDB: "swarms/memory/pinecone.md"
- PineconeDB: "swarms/memory/pinecone.md"
- PGVectorStore: "swarms/memory/pg.md"
- ShortTermMemory: "swarms/memory/short_term_memory.md"
- swarms.utils:
- phoenix_trace_decorator: "swarms/utils/phoenix_tracer.md"
- Misc:
- pdf_to_text: "swarms/utils/pdf_to_text.md"
- load_model_torch: "swarms/utils/load_model_torch.md"
- metrics_decorator: "swarms/utils/metrics_decorator.md"
- prep_torch_inference: "swarms/utils/prep_torch_inference.md"
- find_image_path: "swarms/utils/find_image_path.md"
- print_class_parameters: "swarms/utils/print_class_parameters.md"
- extract_code_from_markdown: "swarms/utils/extract_code_from_markdown.md"
- check_device: "swarms/utils/check_device.md"
- display_markdown_message: "swarms/utils/display_markdown_message.md"
- phoenix_tracer: "swarms/utils/phoenix_tracer.md"
- limit_tokens_from_string: "swarms/utils/limit_tokens_from_string.md"
- math_eval: "swarms/utils/math_eval.md"
- Guides:
- Overview: "examples/index.md"
- Agents:
@ -139,3 +174,5 @@ nav:
- Checklist: "corporate/checklist.md"
- Hiring: "corporate/hiring.md"
- SwarmCloud: "corporate/swarm_cloud.md"
- SwarmMemo: "corporate/swarm_memo.md"
- Data Room: "corporate/data_room.md"

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save