Type something to search...
Explore Swarm Multi-Agent Framework Locally

Explore Swarm Multi-Agent Framework Locally

Swarm is an experimental sample framework to simulate lightweight multi-agent framework for educational purpose. Usually it works with Open AI Key but we can change it to use local Ollama or LM Studio Models.

Setup:

## Create a new Conda or Python Virtual Environment and activate it
conda install python==3.10
pip install torch openai
pip install transformers accelerate huggingface_hub
pip install git+ssh://git@github.com/openai/swarm.git

To use with Open AI Key:

export OPEN_API_KEY = Your Key

To use Ollama or LM Studio Local LLMs — Update to Local URL:

## Find the location site-packages/swarm on the conda or python virtual env
## Locate the file core.py
class Swarm:
    def __init__(self, client=None):
        if not client:
          # Actual Code
          #client = OpenAI()
          # Update the Base URL and API Key to Ollama / LM Studio
          # In this demo we are using LM Studio and Llama 3.1
          client = OpenAI(base_url="http://localhost:1234/v1",api_key="random")
        self.client = client

Clone Repo:

Clone the Repo — where you can find examples directory with different use cases like basic, airline and weather etc.

git clone https://github.com/openai/swarm.git
cd swarm/examples

Sample Code:

from swarm import Swarm, Agent

client = Swarm()


it_agent = Agent(
    name="IT Agent",
    instructions="You are an IT Expert with 10 Years of Experience.",
)

sales_agent = Agent(
    name="Sales Agent",
    instructions="You are a Sales Expert with 5 Years of Experience and knows about best selling mobiles.",
)

def transfer_to_sales_agent():
    print("Sales agent in action")
    """Transfer sales related questions to sales team immediately."""
    return sales_agent

def transfer_to_it_agent():
    print("IT agent in action")
    """Transfer IT users immediately."""
    return it_agent

english_agent = Agent(
    name="English Agent",
    instructions="You only speak English.",
    functions=[transfer_to_sales_agent,transfer_to_it_agent],
)


messages = [{"role": "user", "content": "How to install pandas lib?"}]
response = client.run(agent=english_agent, messages=messages)

print(response.messages[-1]["content"])

messages = [{"role": "user", "content": "What are the best selling items?"}]
response = client.run(agent=english_agent, messages=messages)

print(response.messages[-1]["content"])

References:

https://github.com/openai/swarm

https://github.com/victorb/ollama-swarm/tree/main

Given that it is an experimental release, there is still much room for improvement. The airline agent example code [swarm/examples/airline] was interesting, so try those examples. Give it a try and share your experience in the comments. Thanks.

Related Posts

10 Creative Ways to Use ChatGPT Search The Web Feature

10 Creative Ways to Use ChatGPT Search The Web Feature

For example, prompts and outputs Did you know you can use the “search the web” feature of ChatGPT for many tasks other than your basic web search? For those who don't know, ChatGPT’s new

Read More
📚 10 Must-Learn Skills to Stay Ahead in AI and Tech 🚀

📚 10 Must-Learn Skills to Stay Ahead in AI and Tech 🚀

In an industry as dynamic as AI and tech, staying ahead means constantly upgrading your skills. Whether you’re aiming to dive deep into AI model performance, master data analysis, or transform trad

Read More
10 Powerful Perplexity AI Prompts to Automate Your Marketing Tasks

10 Powerful Perplexity AI Prompts to Automate Your Marketing Tasks

In today’s fast-paced digital world, marketers are always looking for smarter ways to streamline their efforts. Imagine having a personal assistant who can create audience profiles, suggest mar

Read More
10+ Top ChatGPT Prompts for UI/UX Designers

10+ Top ChatGPT Prompts for UI/UX Designers

AI technologies, such as machine learning, natural language processing, and data analytics, are redefining traditional design methodologies. From automating repetitive tasks to enabling personal

Read More
100 AI Tools to Finish Months of Work in Minutes

100 AI Tools to Finish Months of Work in Minutes

The rapid advancements in artificial intelligence (AI) have transformed how businesses operate, allowing people to complete tasks that once took weeks or months in mere minutes. From content creat

Read More
17 Mindblowing GitHub Repositories You Never Knew Existed

17 Mindblowing GitHub Repositories You Never Knew Existed

Github Hidden Gems!! Repositories To Bookmark Right Away Learning to code is relatively easy, but mastering the art of writing better code is much tougher. GitHub serves as a treasur

Read More