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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
task_categories:
|
| 3 |
+
- question-answering
|
| 4 |
+
- translation
|
| 5 |
+
- summarization
|
| 6 |
+
- text-generation
|
| 7 |
+
- text2text-generation
|
| 8 |
+
- conversational
|
| 9 |
+
tags:
|
| 10 |
+
- agent
|
| 11 |
+
- multi-agent
|
| 12 |
+
- autogpt
|
| 13 |
+
- autogen
|
| 14 |
+
- agentgpt
|
| 15 |
+
- gptq
|
| 16 |
+
- wizard
|
| 17 |
+
- code-generation
|
| 18 |
+
- retrieval-augmented-generation
|
| 19 |
+
- humaneval
|
| 20 |
+
---
|
| 21 |
+
# [Roy: Rapid Prototyping of Agents with Hotswappable Components](https://github.com/JosefAlbers/Roy)
|
| 22 |
+
|
| 23 |
+
[<img src="https://colab.research.google.com/assets/colab-badge.svg" />](https://colab.research.google.com/github/JosefAlbers/Roy/blob/main/quickstart.ipynb)
|
| 24 |
+
[](https://zenodo.org/badge/latestdoi/699801819)
|
| 25 |
+
|
| 26 |
+
Roy is a lightweight alternative to `autogen` for developing advanced multi-agent systems using language models. It aims to simplify and democratize the development of emergent collective intelligence.
|
| 27 |
+
|
| 28 |
+
## Features
|
| 29 |
+
|
| 30 |
+
- **Model Agnostic**: Use any LLM, no external APIs required. Defaults to a 4-bit quantized wizard-coder-python model for efficiency.
|
| 31 |
+
|
| 32 |
+
- **Modular and Composable**: Roy decomposes agent interactions into reusable building blocks - templating, retrieving, generating, executing.
|
| 33 |
+
|
| 34 |
+
- **Transparent and Customizable**: Every method has a clear purpose. Easily swap out components or add new capabilities.
|
| 35 |
+
|
| 36 |
+
## Quickstart
|
| 37 |
+
|
| 38 |
+
```sh
|
| 39 |
+
git clone https://github.com/JosefAlbers/Roy
|
| 40 |
+
cd Roy
|
| 41 |
+
pip install -r requirements.txt
|
| 42 |
+
pip install -U transformers optimum accelerate auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
from roy import Roy, Roys
|
| 47 |
+
roy = Roy()
|
| 48 |
+
s = '"What date is today? Which big tech stock has the largest year-to-date gain this year? How much is the gain?'
|
| 49 |
+
roy.generate(roy.format(s))
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
### **Rapid Benchmarking**
|
| 53 |
+
|
| 54 |
+
Roy provides a simple way to evaluate and iterate on your model architecture.. This allows you to:
|
| 55 |
+
|
| 56 |
+
- Easily swap out components, such as language models, prompt formats, agent architectures, etc
|
| 57 |
+
|
| 58 |
+
- Benchmark on different tasks like arithmetic, python coding, etc (default is OpenAI's HumanEval)
|
| 59 |
+
|
| 60 |
+
- Identify agent's areas of strengths and weaknesses
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
from Roy.util import piecewise_human_eval
|
| 64 |
+
|
| 65 |
+
# Comparing different language models
|
| 66 |
+
piecewise_human_eval(0, lm_id='TheBloke/WizardCoder-Python-7B-V1.0-GPTQ')
|
| 67 |
+
# -> {'pass@1': 0.6341463414634146}
|
| 68 |
+
piecewise_human_eval(0, lm_id='TheBloke/tora-code-7B-v1.0-GPTQ')
|
| 69 |
+
# -> {'pass@1': 0.5609756097560976}
|
| 70 |
+
piecewise_human_eval(0, lm_id='TheBloke/Arithmo-Mistral-7B-GPTQ')
|
| 71 |
+
# -> {'pass@1': 0.5121951219512195}
|
| 72 |
+
|
| 73 |
+
# Testing a custom agent architecture
|
| 74 |
+
piecewise_human_eval(0, fx=<your_custom_Roy_agent>)
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
*Takes around 30 minutes each on a free Google Colab runtime.*
|
| 78 |
+
|
| 79 |
+
### **Constrained Beam Search**
|
| 80 |
+
|
| 81 |
+
Use templates to structure conversations (control output length, format, etc)
|
| 82 |
+
|
| 83 |
+
```python
|
| 84 |
+
roy.generate(s, ('\n```python', '\n```')) # Generate a python code block
|
| 85 |
+
roy.generate(s, (('\n```python', '\n```javascript'), '\n```')) # Generate python or javascript codes
|
| 86 |
+
roy.generate(s, ('\n```python', 100, '\n```')) # Generate a code block of size less than 100 tokens
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
### **Retrieval Augmented Generation**
|
| 90 |
+
|
| 91 |
+
Enhance generation with relevant knowledge.
|
| 92 |
+
|
| 93 |
+
```python
|
| 94 |
+
s = 'Create a text to image generator.'
|
| 95 |
+
r = roy.retrieve(s, n_topk=3, src='huggingface')
|
| 96 |
+
[roy.generate(s) for s in r]
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
### **Auto-Feedback**
|
| 100 |
+
|
| 101 |
+
Agents recursively improve via critiquing each other.
|
| 102 |
+
|
| 103 |
+
```python
|
| 104 |
+
s = "Create a secure and unique secret code word with a Python script that involves multiple steps to ensure the highest level of confidentiality and protection.\n"
|
| 105 |
+
for i in range(2):
|
| 106 |
+
c = roy.generate(s, prohibitions=['input'])
|
| 107 |
+
s += roy.execute(c)
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
### **Auto-Grinding**
|
| 111 |
+
|
| 112 |
+
Agents collaborate in tight loops to iteratively refine outputs to specification.
|
| 113 |
+
|
| 114 |
+
```python
|
| 115 |
+
user_request = "Compare the year-to-date gain for META and TESLA."
|
| 116 |
+
ai_response = roy.generate(user_request, ('\n```python', ' yfinance', '\n```'))
|
| 117 |
+
for i in range(2):
|
| 118 |
+
shell_execution = roy.execute(ai_response)
|
| 119 |
+
if 'ModuleNotFoundError' in shell_execution:
|
| 120 |
+
roy.execute(roy.generate(roy.format(f'Write a shell command to address the error encountered while running this Python code:\n\n{shell_execution}')))
|
| 121 |
+
elif 'Error' in shell_execution:
|
| 122 |
+
ai_response = roy.generate(roy.format(f'Modify the code to address the error encountered:\n\n{shell_execution}'))
|
| 123 |
+
else:
|
| 124 |
+
break
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
### **Multi-Agent**
|
| 128 |
+
|
| 129 |
+
Flexible primitives to build ecosystems of agents.
|
| 130 |
+
|
| 131 |
+
```python
|
| 132 |
+
roys = Roys()
|
| 133 |
+
|
| 134 |
+
# AutoFeedback
|
| 135 |
+
roys.create(agents = {'Coder': 'i = execute(generate(i))'})
|
| 136 |
+
roys.start(requests = {'i': 'Create a mobile application that can track the health of elderly people living alone in rural areas.'})
|
| 137 |
+
|
| 138 |
+
# Retrieval Augmented Generation
|
| 139 |
+
roys.create(
|
| 140 |
+
agents = {
|
| 141 |
+
'Retriever': 'r = retrieve(i)',
|
| 142 |
+
'Generator': 'o = generate(r)',
|
| 143 |
+
})
|
| 144 |
+
roys.start(requests = {'i': 'Create a Deutsch to English translator.'})
|
| 145 |
+
|
| 146 |
+
# Providing a custom tool to one of the agents using lambda
|
| 147 |
+
roys.create(
|
| 148 |
+
agents = {
|
| 149 |
+
'Coder': 'c = generate(i)',
|
| 150 |
+
'Proxy': 'c = custom(execute(c))',
|
| 151 |
+
},
|
| 152 |
+
tools = {'custom': lambda x:f'Modify the code to address the error encountered:\n\n{x}' if 'Error' in x else None})
|
| 153 |
+
roys.start(requests = {'i': 'Compare the year-to-date gain for META and TESLA.'})
|
| 154 |
+
|
| 155 |
+
# Another way to create a custom tool for agents
|
| 156 |
+
def custom_switch(self, c):
|
| 157 |
+
py_str = 'Modify the code to address the error encountered:\n\n'
|
| 158 |
+
sh_str = 'Write a shell command to address the error encountered while running this Python code:\n\n'
|
| 159 |
+
x = self.execute(c)
|
| 160 |
+
if 'ModuleNotFoundError' in x:
|
| 161 |
+
self.execute(self.generate(sh_str+x))
|
| 162 |
+
elif 'Error' in x:
|
| 163 |
+
self.dict_cache['i'] = [py_str+x]
|
| 164 |
+
else:
|
| 165 |
+
return '<<<Success>>>:\n\n'+x
|
| 166 |
+
|
| 167 |
+
roys.create(
|
| 168 |
+
agents = {
|
| 169 |
+
'Coder': 'c = generate(i)',
|
| 170 |
+
'Proxy': '_ = protocol(c)',
|
| 171 |
+
},
|
| 172 |
+
tools = {'protocol': custom_switch})
|
| 173 |
+
roys.start(requests = {'i': 'Compare the year-to-date gain for META and TESLA.'})
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
## Emergent Multi-Agent Dynamics
|
| 177 |
+
|
| 178 |
+
Roy aims to facilitate the emergence of complex, adaptive multi-agent systems. It draws inspiration from biological and AI concepts to enable decentralized coordination and continual learning.
|
| 179 |
+
|
| 180 |
+
- **Survival of the Fittest** - Periodically evaluate and selectively retain high-performing agents based on accuracy, speed etc. Agents adapt through peer interactions.
|
| 181 |
+
|
| 182 |
+
- **Mixture of Experts** - Designate agent expertise, dynamically assemble specialist teams, and route tasks to optimal experts. Continuously refine and augment experts.
|
| 183 |
+
|
| 184 |
+
These mechanisms facilitate the emergence of capable, adaptive, and efficient agent collectives.
|
| 185 |
+
|
| 186 |
+
## Get Involved
|
| 187 |
+
|
| 188 |
+
Roy is under active development. We welcome contributions - feel free to open issues and PRs!
|
| 189 |
+
|
| 190 |
+
## Support the Project
|
| 191 |
+
|
| 192 |
+
If you found this project helpful or interesting and want to support more of these experiments, feel free to buy me a coffee!
|
| 193 |
+
|
| 194 |
+
<a href="https://www.buymeacoffee.com/albersj66a" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="25" width="100"></a>
|