JosefAlbers/Roy
收藏资源简介:
--- task_categories: - question-answering - translation - summarization - text-generation - text2text-generation - conversational tags: - agent - multi-agent - autogpt - autogen - agentgpt - gptq - wizard - code-generation - retrieval-augmented-generation - humaneval --- # [Roy: Rapid Prototyping of Agents with Hotswappable Components](https://github.com/JosefAlbers/Roy) [<img src="https://colab.research.google.com/assets/colab-badge.svg" />](https://colab.research.google.com/github/JosefAlbers/Roy/blob/main/quickstart.ipynb) [](https://zenodo.org/badge/latestdoi/699801819) 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. ## Features - **Model Agnostic**: Use any LLM, no external APIs required. Defaults to a 4-bit quantized wizard-coder-python model for efficiency. - **Modular and Composable**: Roy decomposes agent interactions into reusable building blocks - templating, retrieving, generating, executing. - **Transparent and Customizable**: Every method has a clear purpose. Easily swap out components or add new capabilities. ## Quickstart ```sh git clone https://github.com/JosefAlbers/Roy cd Roy pip install -r requirements.txt pip install -U transformers optimum accelerate auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/ ``` ```python from roy import Roy, Roys roy = Roy() s = '"What date is today? Which big tech stock has the largest year-to-date gain this year? How much is the gain?' roy.generate(roy.format(s)) ``` ### **Rapid Benchmarking** Roy provides a simple way to evaluate and iterate on your model architecture.. This allows you to: - Easily swap out components, such as language models, prompt formats, agent architectures, etc - Benchmark on different tasks like arithmetic, python coding, etc (default is OpenAI's HumanEval) - Identify agent's areas of strengths and weaknesses ```python from Roy.util import piecewise_human_eval # Comparing different language models piecewise_human_eval(0, lm_id='TheBloke/WizardCoder-Python-7B-V1.0-GPTQ') # -> {'pass@1': 0.6341463414634146} piecewise_human_eval(0, lm_id='TheBloke/tora-code-7B-v1.0-GPTQ') # -> {'pass@1': 0.5609756097560976} piecewise_human_eval(0, lm_id='TheBloke/Arithmo-Mistral-7B-GPTQ') # -> {'pass@1': 0.5121951219512195} # Testing a custom agent architecture piecewise_human_eval(0, fx=<your_custom_Roy_agent>) ``` *Takes around 30 minutes each on a free Google Colab runtime.* ### **Constrained Beam Search** Use templates to structure conversations (control output length, format, etc) ```python roy.generate(s, ('\n```python', '\n```')) # Generate a python code block roy.generate(s, (('\n```python', '\n```javascript'), '\n```')) # Generate python or javascript codes roy.generate(s, ('\n```python', 100, '\n```')) # Generate a code block of size less than 100 tokens ``` ### **Retrieval Augmented Generation** Enhance generation with relevant knowledge. ```python s = 'Create a text to image generator.' r = roy.retrieve(s, n_topk=3, src='huggingface') [roy.generate(s) for s in r] ``` ### **Auto-Feedback** Agents recursively improve via critiquing each other. ```python 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" for i in range(2): c = roy.generate(s, prohibitions=['input']) s += roy.execute(c) ``` ### **Auto-Grinding** Agents collaborate in tight loops to iteratively refine outputs to specification. ```python user_request = "Compare the year-to-date gain for META and TESLA." ai_response = roy.generate(user_request, ('\n```python', ' yfinance', '\n```')) for i in range(2): shell_execution = roy.execute(ai_response) if 'ModuleNotFoundError' in shell_execution: 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}'))) elif 'Error' in shell_execution: ai_response = roy.generate(roy.format(f'Modify the code to address the error encountered:\n\n{shell_execution}')) else: break ``` ### **Multi-Agent** Flexible primitives to build ecosystems of agents. ```python roys = Roys() # AutoFeedback roys.create(agents = {'Coder': 'i = execute(generate(i))'}) roys.start(requests = {'i': 'Create a mobile application that can track the health of elderly people living alone in rural areas.'}) # Retrieval Augmented Generation roys.create( agents = { 'Retriever': 'r = retrieve(i)', 'Generator': 'o = generate(r)', }) roys.start(requests = {'i': 'Create a Deutsch to English translator.'}) # Providing a custom tool to one of the agents using lambda roys.create( agents = { 'Coder': 'c = generate(i)', 'Proxy': 'c = custom(execute(c))', }, tools = {'custom': lambda x:f'Modify the code to address the error encountered:\n\n{x}' if 'Error' in x else None}) roys.start(requests = {'i': 'Compare the year-to-date gain for META and TESLA.'}) # Another way to create a custom tool for agents def custom_switch(self, c): py_str = 'Modify the code to address the error encountered:\n\n' sh_str = 'Write a shell command to address the error encountered while running this Python code:\n\n' x = self.execute(c) if 'ModuleNotFoundError' in x: self.execute(self.generate(sh_str+x)) elif 'Error' in x: self.dict_cache['i'] = [py_str+x] else: return '<<<Success>>>:\n\n'+x roys.create( agents = { 'Coder': 'c = generate(i)', 'Proxy': '_ = protocol(c)', }, tools = {'protocol': custom_switch}) roys.start(requests = {'i': 'Compare the year-to-date gain for META and TESLA.'}) ``` ## Emergent Multi-Agent Dynamics 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. - **Survival of the Fittest** - Periodically evaluate and selectively retain high-performing agents based on accuracy, speed etc. Agents adapt through peer interactions. - **Mixture of Experts** - Designate agent expertise, dynamically assemble specialist teams, and route tasks to optimal experts. Continuously refine and augment experts. These mechanisms facilitate the emergence of capable, adaptive, and efficient agent collectives. ## Get Involved Roy is under active development. We welcome contributions - feel free to open issues and PRs! ## Support the Project If you found this project helpful or interesting and want to support more of these experiments, feel free to buy me a coffee! <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>
task_categories: - 问答 - 翻译 - 摘要生成 - 文本生成 - 文本到文本生成 - 对话式 tags: - 智能体 - 多智能体 - autogpt - autogen - agentgpt - gptq - wizard - 代码生成 - 检索增强生成 - humaneval --- # [Roy:支持热插拔组件的智能体快速原型开发框架](https://github.com/JosefAlbers/Roy) [<img src="https://colab.research.google.com/assets/colab-badge.svg" />](https://colab.research.google.com/github/JosefAlbers/Roy/blob/main/quickstart.ipynb) [](https://zenodo.org/badge/latestdoi/699801819) Roy是一款轻量级的`autogen`替代方案,用于基于语言模型开发高级多智能体系统。其旨在简化并普及涌现式集体智能的开发流程。 ## 特性 - **模型无关**:支持任意大语言模型(LLM),无需依赖外部API。默认采用4比特量化的wizard-coder-python模型以提升运行效率。 - **模块化与可组合性**:Roy将智能体交互拆解为可复用的构建模块——模板处理、信息检索、文本生成、代码执行。 - **透明可定制**:所有方法均具备清晰的功能定位,可轻松替换组件或新增功能。 ## 快速入门 sh git clone https://github.com/JosefAlbers/Roy cd Roy pip install -r requirements.txt pip install -U transformers optimum accelerate auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/ python from roy import Roy, Roys roy = Roy() s = "What date is today? Which big tech stock has the largest year-to-date gain this year? How much is the gain?" roy.generate(roy.format(s)) ### **快速基准测试** Roy提供了简便的方式用于评估并迭代模型架构,可实现以下功能: - 轻松替换各类组件,例如语言模型、提示词格式、智能体架构等 - 在算术、Python代码生成等多种任务上开展基准测试(默认采用OpenAI的HumanEval数据集) - 精准识别智能体的优势与短板领域 python from Roy.util import piecewise_human_eval # 对比不同语言模型的性能 piecewise_human_eval(0, lm_id='TheBloke/WizardCoder-Python-7B-V1.0-GPTQ') # -> {'pass@1': 0.6341463414634146} piecewise_human_eval(0, lm_id='TheBloke/tora-code-7B-v1.0-GPTQ') # -> {'pass@1': 0.5609756097560976} piecewise_human_eval(0, lm_id='TheBloke/Arithmo-Mistral-7B-GPTQ') # -> {'pass@1': 0.5121951219512195} # 测试自定义智能体架构 piecewise_human_eval(0, fx=<your_custom_Roy_agent>) *在免费的Google Colab运行时中,单次测试耗时约30分钟。* ### **约束束搜索** 通过模板结构化对话内容(可控制输出长度、格式等) python roy.generate(s, (' python', ' ')) # 生成Python代码块 roy.generate(s, ((' python', ' javascript'), ' ')) # 生成Python或JavaScript代码 roy.generate(s, (' python', 100, ' ')) # 生成长度不超过100个Token(Token)的代码块 ### **检索增强生成** 通过引入相关知识库增强生成内容的质量与相关性。 python s = "Create a text to image generator." r = roy.retrieve(s, n_topk=3, src='huggingface') [roy.generate(s) for s in r] ### **自动反馈机制** 智能体可通过互相批评实现递归式的自我优化。 python 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. " for i in range(2): c = roy.generate(s, prohibitions=['input']) s += roy.execute(c) ### **自动迭代优化** 智能体以紧密协作的循环模式,逐步迭代细化输出以匹配用户需求。 python user_request = "Compare the year-to-date gain for META and TESLA." ai_response = roy.generate(user_request, (' python', ' yfinance', ' ')) for i in range(2): shell_execution = roy.execute(ai_response) if 'ModuleNotFoundError' in shell_execution: roy.execute(roy.generate(roy.format(f'Write a shell command to address the error encountered while running this Python code: {shell_execution}'))) elif 'Error' in shell_execution: ai_response = roy.generate(roy.format(f'Modify the code to address the error encountered: {shell_execution}')) else: break ### **多智能体系统** 提供灵活的原语以构建智能体生态系统。 python roys = Roys() # 自动反馈多智能体架构 roys.create(agents = {'Coder': 'i = execute(generate(i))'}) roys.start(requests = {'i': 'Create a mobile application that can track the health of elderly people living alone in rural areas.'}) # 检索增强生成多智能体架构 roys.create( agents = { 'Retriever': 'r = retrieve(i)', 'Generator': 'o = generate(r)', }) roys.start(requests = {'i': 'Create a Deutsch to English translator.'}) # 通过Lambda为智能体自定义工具 roys.create( agents = { 'Coder': 'c = generate(i)', 'Proxy': 'c = custom(execute(c))', }, tools = {'custom': lambda x:f'Modify the code to address the error encountered: {x}' if 'Error' in x else None}) roys.start(requests = {'i': 'Compare the year-to-date gain for META and TESLA.'}) # 另一种为智能体自定义工具的方式 def custom_switch(self, c): py_str = 'Modify the code to address the error encountered: ' sh_str = 'Write a shell command to address the error encountered while running this Python code: ' x = self.execute(c) if 'ModuleNotFoundError' in x: self.execute(self.generate(sh_str+x)) elif 'Error' in x: self.dict_cache['i'] = [py_str+x] else: return '<<<Success>>>: '+x roys.create( agents = { 'Coder': 'c = generate(i)', 'Proxy': '_ = protocol(c)', }, tools = {'protocol': custom_switch}) roys.start(requests = {'i': 'Compare the year-to-date gain for META and TESLA.'}) ## 涌现式多智能体动态特性 Roy旨在助力复杂、自适应的多智能体系统的涌现。其借鉴了生物学与人工智能领域的相关概念,以实现去中心化协同与持续学习。 - **适者生存**:定期评估并基于准确率、运行速度等指标选择性保留高性能智能体,智能体可通过同伴交互实现自适应进化。 - **专家混合**:指定智能体的专业领域,动态组装专业团队,并将任务路由至最优专家。持续优化并扩充专家能力。 这些机制有助于催生具备高性能、自适应且高效的智能体集群。 ## 参与贡献 Roy仍处于活跃开发阶段,我们欢迎各类贡献——欢迎提交Issue与拉取请求(PR)! ## 项目赞助 如果您认为本项目有价值或有趣,并希望支持更多相关实验,请为我买杯咖啡! <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>
Roy: 快速原型化具有可热插拔组件的代理
特性
-
模型无关性:可以使用任何大型语言模型(LLM),无需外部API。默认使用4位量化的wizard-coder-python模型以提高效率。
-
模块化和可组合性:Roy将代理交互分解为可重用的构建块,包括模板化、检索、生成和执行。
-
透明和可定制性:每个方法都有明确的目的。可以轻松替换组件或添加新功能。
快速开始
sh git clone https://github.com/JosefAlbers/Roy cd Roy pip install -r requirements.txt pip install -U transformers optimum accelerate auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/
python from roy import Roy, Roys roy = Roy() s = "What date is today? Which big tech stock has the largest year-to-date gain this year? How much is the gain? roy.generate(roy.format(s))
快速基准测试
Roy提供了一种简单的方法来评估和迭代模型架构。这允许你:
- 轻松替换组件,如语言模型、提示格式、代理架构等
- 在不同的任务上进行基准测试,如算术、Python编程等(默认是OpenAI的HumanEval)
- 识别代理的优势和弱点
python from Roy.util import piecewise_human_eval
比较不同的语言模型
piecewise_human_eval(0, lm_id=TheBloke/WizardCoder-Python-7B-V1.0-GPTQ)
-> {pass@1: 0.6341463414634146}
piecewise_human_eval(0, lm_id=TheBloke/tora-code-7B-v1.0-GPTQ)
-> {pass@1: 0.5609756097560976}
piecewise_human_eval(0, lm_id=TheBloke/Arithmo-Mistral-7B-GPTQ)
-> {pass@1: 0.5121951219512195}
测试自定义代理架构
piecewise_human_eval(0, fx=<your_custom_Roy_agent>)
在免费Google Colab运行时上每次大约需要30分钟。
约束波束搜索
使用模板来结构化对话(控制输出长度、格式等)
python roy.generate(s, ( python, )) # 生成一个Python代码块 roy.generate(s, (( python, javascript), )) # 生成Python或JavaScript代码 roy.generate(s, ( python, 100, )) # 生成一个大小小于100个令牌的代码块
检索增强生成
通过相关知识增强生成。
python s = Create a text to image generator. r = roy.retrieve(s, n_topk=3, src=huggingface) [roy.generate(s) for s in r]
自动反馈
代理通过相互批评递归改进。
python 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. " for i in range(2): c = roy.generate(s, prohibitions=[input]) s += roy.execute(c)
自动磨练
代理在紧密循环中协作,迭代地细化输出以符合规范。
python user_request = "Compare the year-to-date gain for META and TESLA." ai_response = roy.generate(user_request, ( python, yfinance, )) for i in range(2): shell_execution = roy.execute(ai_response) if ModuleNotFoundError in shell_execution: roy.execute(roy.generate(roy.format(fWrite a shell command to address the error encountered while running this Python code:
{shell_execution}))) elif Error in shell_execution: ai_response = roy.generate(roy.format(fModify the code to address the error encountered:
{shell_execution})) else: break
多代理
灵活的原语来构建代理生态系统。
python roys = Roys()
自动反馈
roys.create(agents = {Coder: i = execute(generate(i))}) roys.start(requests = {i: Create a mobile application that can track the health of elderly people living alone in rural areas.})
检索增强生成
roys.create( agents = { Retriever: r = retrieve(i), Generator: o = generate(r), }) roys.start(requests = {i: Create a Deutsch to English translator.})
为代理提供自定义工具使用lambda
roys.create( agents = { Coder: c = generate(i), Proxy: c = custom(execute(c)), }, tools = {custom: lambda x:fModify the code to address the error encountered:
{x} if Error in x else None}) roys.start(requests = {i: Compare the year-to-date gain for META and TESLA.})
另一种为代理创建自定义工具的方法
def custom_switch(self, c): py_str = Modify the code to address the error encountered:
sh_str = Write a shell command to address the error encountered while running this Python code:
x = self.execute(c)
if ModuleNotFoundError in x:
self.execute(self.generate(sh_str+x))
elif Error in x:
self.dict_cache[i] = [py_str+x]
else:
return <<<Success>>>:
+x
roys.create( agents = { Coder: c = generate(i), Proxy: _ = protocol(c), }, tools = {protocol: custom_switch}) roys.start(requests = {i: Compare the year-to-date gain for META and TESLA.})
新兴多代理动态
Roy旨在促进复杂、自适应多代理系统的出现。它从生物学和AI概念中汲取灵感,以实现去中心化协调和持续学习。
-
适者生存:定期评估并选择性地保留高绩效代理,基于准确性、速度等。代理通过同行交互进行适应。
-
专家混合:指定代理专长,动态组建专家团队,并将任务路由到最佳专家。持续精炼和增强专家。
这些机制促进了能力、自适应和高效代理集体的出现。



