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 git+https://github.com/hivenetwork-ai/hive-agent-py.git@main

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

hive-agent @ git+https://github.com/hivenetwork-ai/hive-agent-py@main

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 hive_agent.swarm import HiveSwarm
from hive_agent.agent import HiveAgent
from hive_agent.sdk_context import SDKContext

from hive_agent.llms.utils import llm_from_config
from hive_agent.utils import tools_from_funcs
from hive_agent.llms.claude import ClaudeLLM
import asyncio

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

def save_report():
    return "save_item_to_csv"

def search_on_web():
    return "search_on_web"

#You can use the default config using default_config or the config of a specific agent by using the get_config method.
llm = llm_from_config(sdk_context.get_config("target_agent_id"))
tools = tools_from_funcs([search_on_web])
claude = ClaudeLLM(llm=llm, tools=tools)
    
# Create individual agents
agent1 = HiveAgent(name="Research Agent", instruction="Conduct research on given topics", sdk_context=sdk_context, functions=[search_on_web], llm=claude)
agent2 = HiveAgent(name="Analysis Agent", instruction="Analyze data and provide insights", sdk_context=sdk_context, functions=[save_report])
agent3 = HiveAgent(name="Report Agent", instruction="Compile findings into a report", sdk_context=sdk_context, functions=[])

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


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