Home

Awesome

Page arXiv License Issues Twitter Follow Wechat Coverage Status

<p align="left"> <a href=""><img src="swarm/utils/assets/logo.png" alt="GPTSwarm" width="430px"></a> </p>

🐝 GPTSwarm is a graph-based framework for LLM-based agents, providing two high-level features:

About GPTSwarm

<img src="assets/gpt_swarm.png" alt="Framework" width="799">

At a granular level, GPTSwarm is a library that includes the following components:

ModuleDescription
swarm.environmentDomain-specific operations, agents, tools, and tasks
swarm.graphGraph-related functions for creating and executing agent graphs and swarm composite graphs
swarm.llmInterface for selecting LLM backends and calculating their operational costs
swarm.memoryIndex-based memory
swarm.optimizerOptimization algorithms designed to enhance agent performance and overall swarm efficiency

Visualizations of the graphs

<img src="assets/swarm_vis.png" alt="Edge optimization" width="800">

News

Edge optimization example

Here is the edge optimization process that updates edge probabilities toward improvement of the benchmark score. Notice that within an agent, the edges are fixed, whereas the inter-agent connections are getting optimized towards either edge pruning (value 0, blue) or creation (value 1, red).

<img src="assets/edge_opt.gif" alt="Edge optimization" width="300">

Quickstart

Clone the repo

git clone https://github.com/metauto-ai/GPTSwarm.git
cd GPTSwarm/

Install packages

conda create -n swarm python=3.10
conda activate swarm
pip install poetry
poetry install

You should add API keys in .env.template and change its name to .env

OPENAI_API_KEY="" # for OpenAI LLM backend
SEARCHAPI_API_KEY="" # for Web Search

Getting started with GPTSwarm is easy. Quickly run a predefined swarm

from swarm.graph.swarm import Swarm

swarm = Swarm(["IO", "IO", "IO"], "gaia")
task = "What is the capital of Jordan?"
inputs = {"task": task}
answer = await swarm.arun(inputs)

or make use of tools, such as the file analyzer

from swarm.graph.swarm import Swarm
swarm = Swarm(["IO", "TOT"], "gaia")
task = "Tell me more about this image and summarize it in 3 sentences."
files = ["./datasets/demos/js.png"]
inputs = {"task": task, "files": files}
danswer = swarm.run(inputs)

Check out the minimal Swarm example in Colab here: Open In Colab.

See how to create a custom Agent and run a Swarm with it here: Open In Colab.

Here is a Youtube video on how to run the demo notebooks:

<img src="assets/youtube_preview.png" width="75%">

πŸ”₯πŸ”₯πŸ”₯ See our experiments for more advanced use of our framework.

Class diagram

<img src="assets/class_diagram.png" alt="Edge optimization" width="700">

Example of the Swarm

<img src="assets/swarm_v3.png" alt="Edge optimization" width="500">

Running with a local LLM

We support local LM inference via LM Studio. Download their desktop app for Mac or Windows, choose a model from the Huggingface repository and start the server. Use model_name='lmstudio' in GPTSwarm code to run with the local LLM.

<img src="assets/lm_studio.png" alt="Edge optimization" width="800">

Contributors

<a href="https://github.com/metauto-ai/gptswarm/graphs/contributors"> <img src="https://contrib.rocks/image?repo=metauto-ai/gptswarm&max=200" /> </a>

Please read our developer document if you are interested in contributing.

Citation

Please cite our paper if you find the library useful or interesting.

@inproceedings{zhugegptswarm,
  title={GPTSwarm: Language Agents as Optimizable Graphs},
  author={Zhuge, Mingchen and Wang, Wenyi and Kirsch, Louis and Faccio, Francesco and Khizbullin, Dmitrii and Schmidhuber, J{\"u}rgen},
  booktitle={Forty-first International Conference on Machine Learning}
}