Swarms

Swarms on SwarmZero.ai allow you to group multiple AI Agents into a coordinated workflow to handle more complex tasks. Each agent within a Swarm has a specific function but works collaboratively to achieve a larger goal. This approach allows users to combine various specialized agents to process information, interact with external services, and automate tasks seamlessly and efficiently.

SwarmZero makes it simple to create Swarms using a no-code or low-code interface. Users can visually organize their agents, specify their interactions, and set up workflows that respond to real-time data. By utilizing AI, Machine Learning, and Large Language Models (LLMs), Swarms can operate autonomously or with user inputs, depending on the task complexity.

Installation

To get started, install the necessary framework via pip:

pip install swarmzero

Alternatively, you can add it to your requirements.txt:

swarmzero==x.y.z

Creating a Swarm

You can create a swarm of agents to collaborate on complex tasks. Here's an example of how to set up and use a swarm:

from swarmzero.swarm import Swarm
from swarmzero.agent import Agent
from swarmzero.sdk_context import SDKContext

import asyncio

# Create SDK Context
sdk_context = SDKContext(config_path="./swarmzero_config_example.toml")


def save_report():
    return "save_item_to_csv"


def search_on_web():
    return "search_on_web"


# Create individual agents
agent1 = Agent(name="Research Agent", instruction="Conduct research on given topics", sdk_context=sdk_context,
               functions=[search_on_web])
agent2 = Agent(name="Analysis Agent", instruction="Analyze data and provide insights", sdk_context=sdk_context,
               functions=[save_report])
agent3 = Agent(name="Report Agent", instruction="Compile findings into a report", sdk_context=sdk_context, functions=[])

# Create swarm
swarm = Swarm(name="Research Team", description="A swarm of agents that collaborate on research tasks",
              instruction="Be helpful and collaborative", functions=[], agents=[agent1, agent2, agent3])


async def chat_with_swarm():
    return await swarm.chat("Can you analyze the following data: [1, 2, 3, 4, 5]")


if __name__ == "__main__":
    asyncio.run(chat_with_swarm())

Interested in Building Interesting Swarms with SwarmZero.ai?

Follow the tutorial below:

Build a Web3 dApp with a Swarm of AI Agents

Last updated

Was this helpful?