Metadata-Version: 2.1
Name: gptswarm
Version: 0.1.0
Summary: GPTSwarm: Language Agents as Optimizable Graphs
Author: Mingchen Zhuge
Author-email: mczhuge@gmail.com
Requires-Python: >=3.10,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: aiohttp (>=3.9.0,<4.0.0)
Requires-Dist: apscheduler (>=3.10.4,<4.0.0)
Requires-Dist: arxiv (>=2.0.0,<3.0.0)
Requires-Dist: astunparse (>=1.6.3,<2.0.0)
Requires-Dist: async-timeout (>=4.0.3,<5.0.0)
Requires-Dist: beautifulsoup4 (>=4.12.2,<5.0.0)
Requires-Dist: charset-normalizer (>=3.3.2,<4.0.0)
Requires-Dist: class-registry (>=2.1.2,<3.0.0)
Requires-Dist: docx (>=0.2.4,<0.3.0)
Requires-Dist: fastapi (==0.109.2)
Requires-Dist: func-timeout (>=4.3.5,<5.0.0)
Requires-Dist: google-api-python-client (>=2.111.0,<3.0.0)
Requires-Dist: gradio (>=4.11.0,<5.0.0)
Requires-Dist: httpx (>=0.25.2,<0.26.0)
Requires-Dist: jsonlines (>=4.0.0,<5.0.0)
Requires-Dist: loguru (==0.7.2)
Requires-Dist: markdown (>=3.5.1,<4.0.0)
Requires-Dist: networkx (==3.2.1)
Requires-Dist: openai (>=1.6.0,<2.0.0)
Requires-Dist: opencv-python (>=4.8.1.78,<5.0.0.0)
Requires-Dist: openpyxl (>=3.1.2,<4.0.0)
Requires-Dist: pandas (>=1.5.3,<2.0.0)
Requires-Dist: pydantic (>=2.5.3,<3.0.0)
Requires-Dist: pylatexenc (>=2.10,<3.0)
Requires-Dist: pypdf2 (>=3.0.1,<4.0.0)
Requires-Dist: python-docx (>=1.1.0,<2.0.0)
Requires-Dist: python-dotenv (==1.0.0)
Requires-Dist: python-pptx (==0.6.23)
Requires-Dist: pytube (==15.0.0)
Requires-Dist: pyvis (==0.3.2)
Requires-Dist: pyyaml (==6.0.1)
Requires-Dist: regex (==2023.10.3)
Requires-Dist: requests (>=2.31.0,<3.0.0)
Requires-Dist: scipy (>=1.12.0,<2.0.0)
Requires-Dist: seaborn (>=0.13.1,<0.14.0)
Requires-Dist: sentence-transformers (==2.2.2)
Requires-Dist: shortuuid (==1.0.11)
Requires-Dist: tenacity (>=8.2.3,<9.0.0)
Requires-Dist: termcolor (>=2.4.0,<3.0.0)
Requires-Dist: torch (>=2.1.0,<3.0.0)
Requires-Dist: tqdm (>=4.66.1,<5.0.0)
Requires-Dist: transformers (>=4.36.2,<5.0.0)
Requires-Dist: wikipedia (>=1.4.0,<2.0.0)
Description-Content-Type: text/markdown

[![Page](https://img.shields.io/badge/Project-Page-lightgreen.svg)](https://gptswarm.org)
[![arXiv](https://img.shields.io/badge/arXiv-Paper-gold.svg)](https://arxiv.org/abs/2402.16823)
[![License](https://img.shields.io/badge/License-MIT-orange.svg)](https://github.com/metauto-ai/GPTSwarm/blob/main/LICENSE)
[![Issues](https://img.shields.io/github/issues/metauto-ai/GPTSwarm?color=00afaa)](https://github.com/metauto-ai/gptswarm/issues)
[![Twitter Follow](https://img.shields.io/twitter/follow/AI_KAUST?style=social)](https://twitter.com/AI_KAUST)
[![Wechat](https://img.shields.io/badge/Wechat-7BB32E?logo=wechat&logoColor=white)](https://metauto.ai/images/wechat.jpeg)

<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:**

* It lets you build LLM-based agents from graphs.
* It enables the customized and automatic self-organization of agent swarms with self-improvement capabilities.

## News

🚀 Feb 27, 2024: Our academic paper: [Language Agents as Optimizable Graphs](https://arxiv.org/abs/2402.16823) is released.

## 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">

## 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: 


| Module | Description |
| ---- | --- |
| [**swarm.environment**](swarm/environment) | Domain-specific operations, agents, tools, and tasks |
| [**swarm.graph**](swarm/graph) | Graph-related functions for creating and executing agent graphs and swarm composite graphs |
| [**swarm.llm**](swarm/llm) | Interface for selecting LLM backends and calculating their operational costs |
| [**swarm.memory**](swarm/memory) | Index-based memory |
| [**swarm.optimizer**](swarm/optimizer) | Optimization algorithms designed to enhance agent performance and overall swarm efficiency |


## Quickstart

**Clone the repo**

```bash
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`**

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

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

```python
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**

```python
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](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/metauto-ai/GPTSwarm/blob/main/notebooks/demo_swarm.ipynb).

See how to create a custom Agent and run a Swarm with it here: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/metauto-ai/GPTSwarm/blob/main/notebooks/demo_custom_agent.ipynb).

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

[<img src="assets/youtube_preview.png" width="75%">](https://www.youtube.com/watch?v=QOLQse5ZBV8&t=8s&ab_channel=GPTSwarm "Running swarm inference")


**🛠 See [our experiments](https://github.com/metauto-ai/GPTSwarm/tree/main/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">

## More Visualizations

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

## Running with a local LLM

We support local LM inference via [LM Studio](https://lmstudio.ai). 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">

## Initial Contributors

* [Mingchen Zhuge](http://metauto.ai) (PhD Student, KAUST; Project Initiator)
* [Wenyi Wang](https://scholar.google.com/citations?user=79ODhuQAAAAJ&hl=en&oi=ao) (PhD Student, KAUST; Initial Participant)
* [Dmitrii Khizbullin](http://www.khizbullin.tech) (Research Engineer Lead, KAUST; Project Engineer Lead)
* [Louis Kirsch](http://louiskirsch.com) (PhD Student, IDSIA)
* [Francesco Faccio](https://scholar.google.com/citations?user=0z3DkrkAAAAJ&hl=en&oi=ao) (PostDoc, IDSIA; Visiting Researcher, KAUST)
* [Jürgen Schmidhuber](http://www.idsia.ch/~juergen/) (Director, KAUST AI Initiative; Scientific Director, IDSIA)

Please read our [developer document](DEVELOPMENT.md) if you are interested in contributing.


## Citation
Please cite our paper if you find the library useful or interesting.
```
@article{zhuge2024language,
  title={Language Agents as Optimizable Graphs},
  author={Zhuge, Mingchen and Wang, Wenyi and Kirsch, Louis and Faccio, Francesco and Khizbullin, Dmitrii and Schmidhuber, Jurgen},
  journal={arXiv preprint arXiv:2402.16823},
  year={2024}
}
```





