AIlice,一个自扩展的多智能体协作Agent框架 之二

最近因故导致更新较慢,多模态还没有做上.但是边边角角的抛光工作还是做了一些,AIlice的使用体验上应该是好一些了.今天重新实现了子agent “researcher”,这是一个最早在llama 13b上开发的组件,使用了非常极端的手段尝试节省context使用,但后来发现得不偿失,于是有了本次更新.这次更新后AIlice做调查任务更稳健了,而且能跟编程任务很好的配合,实现调查-执行混合型任务.

最近这些开发里逐渐意识到IACT架构还有一些当初始料不及的优点,除了在计算中提供优良的容错性,它对于context window的扩展也有很大的意义,这个意义可以直接以CPU上为类比来说明:CPU上的寄存器资源很有限,但它可以执行非常复杂的计算任务,原因在于我们在函数调用时把寄存器的内容保存到内存里,函数调用结束后再恢复现场.因而每个函数被调用后都有着干干净净的工作空间.IACT中agent之间可以动态的创建子agents,这类比于函数调用,虽然每个agents都只有有限的context window,但它们的组合可以解决非常复杂的问题.

IACT还有超出上述经典类比的深层意义.原因是IACT中的agent调用本质上其实是主调和被调agents之间的一种对话,而非简单的调用-返回.这种设计下,当子agent的context window耗尽,遗忘了自己的任务目标,它可以询问主agent,让后者重新告诉它自己的任务是什么.我们也可以实现对大量数据的处理,只需要让子agent分批处理并分批返回给主agent即可,而不是一次性处理全部数据再返回–那当然会耗尽context window.

我们今天更新一篇文章,从一个典型用例来展示IACT架构的运作.这个用例很简单,我让AIlice去寻找男神David Tong的量子场论讲义并下载.这是个简单任务,但它同时是一个调查-编程混合型任务,我们可以在这个例子中看到有趣的agents协作.

prompt: Find David Tong’s QFT lecture notes and download the pdf file to the “physics” folder in the current directory. You may need to create the folder first.

USER: Find David Tong’s QFT lecture notes and download the pdf file to the “physics” folder in the current directory. You may need to create the folder first.

ASSISTANT_AIlice: To accomplish this task, I will create and communicate with a “researcher” agent that can search the internet for David Tong’s Quantum Field Theory (QFT) lecture notes and download the PDF file. Additionally, I will instruct a “coder-proxy” agent to create the “physics” folder in the current directory if it does not already exist and to move the downloaded file into that folder.

First, I will instruct the “coder-proxy” agent to check for the existence of the “physics” folder and create it if necessary. Then, I will instruct the “researcher” agent to find and download the PDF file.

Let’s start with the “coder-proxy” agent to handle the folder creation.

!CALL<!|”coder-proxy”, “folder_creator”, “import os\n\nfolder_path = ‘physics’\nif not os.path.exists(folder_path):\n os.makedirs(folder_path)”|!>

ASSISTANT_folder_creator: It seems you want to create a directory named ‘physics’ if it does not already exist. I will execute the provided Python code to accomplish this task.

!PYTHON<!|

import os

folder_path = ‘physics’

if not os.path.exists(folder_path):

os.makedirs(folder_path)

|!>

SYSTEM_folder_creator: PYTHON_RESULT=[

Execution completed.

]

ASSISTANT_folder_creator: The directory named ‘physics’ has been successfully created. If you have any further instructions or need assistance with anything else, please let me know!

SYSTEM_AIlice: Agent folder_creator returned: The directory named ‘physics’ has been successfully created. If you have any further instructions or need assistance with anything else, please let me know!

ASSISTANT_AIlice: The “physics” folder has been successfully created. Now, I will instruct the “researcher” agent to find David Tong’s Quantum Field Theory (QFT) lecture notes and download the PDF file into the “physics” folder.

!CALL<!|”researcher”, “pdf_downloader”, “Please find David Tong’s Quantum Field Theory (QFT) lecture notes and download the PDF file into the ‘physics’ folder in the current directory.”|!>

ASSISTANT_pdf_downloader: To accomplish this task, I will first need to search for David Tong’s Quantum Field Theory lecture notes online. Once I find the correct PDF file, I will then download it into the specified ‘physics’ folder in the current directory.

I will start by searching for the lecture notes.

!CALL<!|”search-engine”, “QFTLectureNotesSearch”, “David Tong Quantum Field Theory lecture notes PDF”|!>

ASSISTANT_QFTLectureNotesSearch: To find the PDF of David Tong’s Quantum Field Theory lecture notes, I will use the GOOGLE command to search for it on the internet. Here is the command: !GOOGLE<!|”David Tong Quantum Field Theory lecture notes PDF”|!>.

SYSTEM_QFTLectureNotesSearch: GOOGLE_RESULT=[[SearchResult(url=https://www.damtp.cam.ac.uk/user/tong/qft.html, title=David Tong: Lectures on Quantum Field Theory – DAMTP, description=These lecture notes are based on an introductory course on quantum field theory, aimed at Part III (i.e. masters level) students. The full set of lecture notes …), SearchResult(url=https://www.damtp.cam.ac.uk/user/tong/qft/qft.pdf, title=Quantum Field Theory – DAMTP, description=by D Tong · Cited by 4 — Dr David Tong. Department of Applied Mathematics and Theoretical Physics … These lecture notes are far from original. My primary contribution has been …), SearchResult(url=https://www.damtp.cam.ac.uk/user/dbs26/AQFT/chap1.pdf, title=Quantum Field Theory II – DAMTP, description=by D Skinner · Cited by 14 — • Tong, D., Quantum Field Theory, http://www.damtp.cam.ac.uk/user/tong/qft.html. The lecture notes from the Michaelmas QFT course in Part III.), SearchResult(url=https://www.damtp.cam.ac.uk/user/tong/qft/qfthtml/qfthtml.html, title=Quantum Field Theory by David Tong, description=Quantum Field Theory by David Tong … If you’re not using speech conversion software then you will likely be better served by the lecture notes in pdf form.), SearchResult(url=https://knzhou.github.io/notes/qft.pdf, title=Quantum Field Theory, description=David Tong’s Gauge Theory lecture notes. An absolutely exceptional set of notes on special topics in quantum field theory, with many references to original …), SearchResult(url=http://www.damtp.cam.ac.uk/user/tong/teaching.html, title=David Tong: Lectures on Theoretical Physics, description=These notes provide an introduction to the fun bits of quantum field theory, in particular those topics related to topology and strong coupling. They are aimed …), SearchResult(url=https://archive.org/details/Dr_David_Tong__Quantum_Field_Theory, title=Dr David Tong – Quantum Field Theory, description=Oct 5, 2013 — This is a very clear and comprehensive book, covering everything in this course at the right level. It will also cover everything in the ” …), SearchResult(url=https://pirsa.org/c09033, title=09/10 PSI – Quantum Field Theory, description=Quantum Field Theory (PHYS 601) – Lecture 1 · David Tong University of Cambridge. September 28, 2009. PIRSA:09090108. Quantum Field Theory (PHYS 601) – Lecture …), SearchResult(url=https://www.e-booksdirectory.com/details.php?ebook=3941, title=Quantum Field Theory by David Tong – Download link, description=These notes are based on an introductory course on quantum field theory. … (PDF/PS). Similar books. Book cover: Introduction to Quantum Fields in Curved …), SearchResult(url=https://lim.physics.ucdavis.edu/teaching/files/qft-notes-partiii.pdf, title=qft-notes-partiii.pdf, description=May 20, 2019 — These notes were taken for the Quantum Field Theory course taught by Ben Allanach at the University of Cambridge as … David Tong’s notes. Under …), SearchResult(url=https://www.reddit.com/r/Physics/comments/qpzgr/qft_lecture_series_given_by_david_tong/, title=QFT lecture series given by David Tong : r/Physics, description=… especially the historical background for QFT and other theories. Edit: And here are his lecture notes in PDF. Upvote 10. Downvote Reply reply), SearchResult(url=https://www.ippp.dur.ac.uk/~mspannow/files/SkriptQFT_Weigand.pdf, title=Quantum Field Theory I + II, description=… course. Excellent lecture notes available online include. • A. Hebecker: Quantum Field Theory,. • D. Tong: Quantum Field Theory. … pdf. 2In short, a …), SearchResult(url=https://ocw.mit.edu/courses/8-323-relativistic-quantum-field-theory-i-spring-2008/pages/related-resources/, title=Related Resources | Relativistic Quantum Field Theory I, description=David Tong, High Energy Particle Physics Group, Department … In additon, handwritten lecture notes of the lectures are available as transcribed by Brian Hill.), SearchResult(url=https://cirosantilli.com/quantum-field-theory-lecture-notes-by-david-tong-2007, title=Quantum Field Theory lecture notes by David Tong (2007), description=Quantum Field Theory lecture notes

This is a page of the results. To browse more results, you can use the following functions.

#scroll down the page:

SCROLLDOWNGOOGLE<!||!>

]

ASSISTANT_QFTLectureNotesSearch: David Tong’s Quantum Field Theory lecture notes can be found on the DAMTP (Department of Applied Mathematics and Theoretical Physics, University of Cambridge) website. The full set of lecture notes is available in PDF format. You can directly access them through the following link: [David Tong: Lectures on Quantum Field Theory – DAMTP](https://www.damtp.cam.ac.uk/user/tong/qft/qft.pdf).

If you need more information or additional resources, please let me know, and I can continue the search.

SYSTEM_pdf_downloader: Agent QFTLectureNotesSearch returned: David Tong’s Quantum Field Theory lecture notes can be found on the DAMTP (Department of Applied Mathematics and Theoretical Physics, University of Cambridge) website. The full set of lecture notes is available in PDF format. You can directly access them through the following link: [David Tong: Lectures on Quantum Field Theory – DAMTP](https://www.damtp.cam.ac.uk/user/tong/qft/qft.pdf).

If you need more information or additional resources, please let me know, and I can continue the search.

ASSISTANT_pdf_downloader: Great, the PDF of David Tong’s Quantum Field Theory lecture notes has been found. I will now proceed to download the file into the ‘physics’ folder in the current directory.

!BASH<!|”wget -P ./physics/ https://www.damtp.cam.ac.uk/user/tong/qft/qft.pdf”|!>

SYSTEM_pdf_downloader: BASH_RESULT=[–2024-01-07 10:28:38– https://www.damtp.cam.ac.uk/user/tong/qft/qft.pdf

Resolving www.damtp.cam.ac.uk (www.damtp.cam.ac.uk)… 131.111.20.161

Connecting to www.damtp.cam.ac.uk (www.damtp.cam.ac.uk)|131.111.20.161|:443… connected.

HTTP request sent, awaiting response… 200 OK

Length: 1357194 (1.3M) [application/pdf]

Saving to: ‘./physics/qft.pdf.5’

0K ………. ………. ………. ………. ………. 3% 240K 5s

50K ………. ………. ………. ………. ………. 7% 499K 4s

100K ………. ………. ………. ………. ………. 11% 6.56M 2s

150K ………. ………. ………. ………. ………. 15% 9.16M 2s

200K ………. ………. ………. ………. ………. 18% 514K 2s

250K ………. ………. ………. ………. ………. 22% 5.44M 1s

300K ………. ………. ………. ………. ………. 26% 6.06M 1s

350K ………. ………. ………. ………. ………. 30% 8.76M 1s

400K ………. ………. ………. ………. ………. 33% 644K 1s

450K ………. ………. ………. ………. ………. 37% 9.75M 1s

500K ………. ………. ………. ………. ………. 41% 10.3M 1s

550K ………. ………. ………. ………. ………. 45% 9.53M 1s

600K ………. ………. ………. ………. ………. 49% 8.44M 1s

650K ………. ………. ………. ………. ………. 52% 8.82M 0s

700K ………. ………. ………. ………. ………. 56% 9.86M 0s

750K ………. ………. ………. ………. ………. 60% 9.98M 0s

800K ………. ………. ………. ………. ………. 64% 9.15M 0s

850K ………. ………. ………. ………. ………. 67% 908K 0s

900K ………. ………. ………. ………. ………. 71% 4.44M 0s

950K ………. ………. ………. ………. ………. 75% 3.44M 0s

1000K ………. ………. ………. ………. ………. 79% 11.4M 0s

1050K ………. ………. ………. ………. ………. 82% 8.45M 0s

1100K ………. ………. ………. ………. ………. 86% 11.2M 0s

1150K ………. ………. ………. ………. ………. 90% 9.59M 0s

1200K ………. ………. ………. ………. ………. 94% 10.3M 0s

1250K ………. ………. ………. ………. ………. 98% 11.3M 0s

1300K ………. ………. ….. 100% 9.51M=0.7s

2024-01-07 10:28:40 (1.93 MB/s) – ‘./physics/qft.pdf.5’ saved [1357194/1357194]

Execution completed.

]

ASSISTANT_pdf_downloader: The PDF file of David Tong’s Quantum Field Theory lecture notes has been successfully downloaded into the ‘physics’ folder in the current directory. If you need any further assistance, please let me know.

SYSTEM_AIlice: Agent pdf_downloader returned: The PDF file of David Tong’s Quantum Field Theory lecture notes has been successfully downloaded into the ‘physics’ folder in the current directory. If you need any further assistance, please let me know.

ASSISTANT_AIlice: The PDF file of David Tong’s Quantum Field Theory lecture notes has been successfully downloaded into the “physics” folder in the current directory. If you need any further assistance or have another task, please let me know.

AIlice接收到用户请求后,随即创建了coder-proxy类型的agent “folder_creator”,创建了我们要求的文件夹.当然,这个任务太简单,AIlice的主agent一时技痒自己把代码给写了,即便我们在系统prompt里告诫她不要这么做.这是gpt-4这个级别的LLM经常出现的一种情况,不爱遵循没道理的规矩.我们就不怪她了.

文件夹创建后AIlice又创建了researcher类型的agent “pdf_downloader”,让他去找David Tong QFT讲义并下载到刚才创建的文件夹里.pdf_downloader创建了search-engine类型的”QFTLectureNotesSearch”让他去找链接,一通google后找到了,pdf_downloader连coder-proxy都不想调,自己随手写了个命令给下载了.

这就完了.

很简单是吧,就是函数调用嘛.其实并不是,只是用例太简单,根本没给更复杂的交互一个机会.太冗长的用例不适合拿来写文章,毕竟这里空间太小,写不下.

你还是去玩玩吧.

GitHub – myshell-ai/AIlice: A lightweight AI Agent

AIlice,一个自扩展的多智能体协作Agent框架

AIlice(GitHub – stevenlu137/AIlice: A lightweight AI Agent).

一天没陪儿子玩,成效显著,AIlice终于如愿支持自扩展了—她自己可以完成外部环境交互模块的构建,并且立即加载使用!而今天统计了下代码量,竟然还在2300行左右,可以说是相当的轻量级了.

AIlice的构建初衷是基于开源模型构建一款Agent框架,要足够的轻,从而开发者能清楚的明白系统整体的运转,从而具有足够可控性;同时要足够灵活,在一个相当泛化的框架基础上再做特化,即应用层agents.另一方面,我非常希望未来的agents能一次性帮我调研一个学术方向,它自己去收集文献阅读文献,回头再在对话里教给我.这就要求agents具有长时间针对一个主题做深入调研的能力,这种任务需要大量的计算时间,用眼下的商业LLM显然不合适,因而这就要求有一个充分强大的开源LLM做保障,当然这还没有.但我觉得,眼下这个时代,构建任何软件系统都要面向未来,我们的时间轴在加速,你无法预期明天是不是就会出来一个开源的GPT4级别LLM,而你知道,这早晚会发生.所以,AIlice就这样被做出来了.她尚且无法帮我调研一个学术方向,但能针对一个主题做长时间的探索了,而且具有极佳的编程/脚本执行能力,在自我扩展做上后,我想,是时候让她出来面对世界了.

基本特性

  1. 自然且高度容错的IACT(Interactive Agents Calling Tree)架构。
  2. 以最灵活的方式解析LLM输出,支持更多种多样的函数调用机制.
  3. 自我构建并动态加载环境交互模块,为功能扩展提供无限潜力。
  4. 专为开源模型设计,但可以无缝支持商业模型,如GPT-4。
  5. 支持对特定主题进行深入调查。
  6. 自动化编程和脚本执行。它是一个全能的coder和系统管理工具,掌握所有系统命令——你可以把它看作一个人工智能操作系统。

接下来我还会加上多模态支持,届时AIlice的基本框架就差不多完成了,代码量会控制在3k行之内.

AIlice能做什么?

我们来罗列一些典型的用例.我经常用这些例子来对开发中的AIlice做测试,确保性能的稳定.但即便如此,执行结果仍然和你选择的模型,所用的代码版本,甚至是测试时间有关(chatgpt疑似在高负荷下会降智,当然开源模型没这个问题,它们的智力是一直低).另外,AIlice是一个基于多智能体对话协作的Agent,这里作为用户的你,也是”智能体”之一(不承认?),所以,当它需要额外信息时,会来询问你,你充分详细的信息是她成功的关键.另外,当任务执行的不尽人意,你也可以告诉她正确的做法,她会回头纠正的.

最后一个需要注意的地方是,AIlice目前没有运行时间控制机制,因此她可能陷入死循环或长期运行,在使用商业LLM运行时你需要关注她的运行.

  • “Please search the internet for 100 tutorials in various branches of physics and report the URLs for the PDF files you find. There is no need to verify these URLs, we only need a rough collection for now.”
  • “Please conduct an investigation on open-source PDF OCR tools, with a focus on those capable of recognizing mathematical formulas and converting them into LaTeX code. Consolidate the findings into a report.”
  • “Deploy a straightforward website on this machine using the Flask framework. Ensure accessibility at 0.0.0.0:2006. The website should have a single page capable of displaying all images located in the ‘images’ directory.” 在docker环境里执行绘图任务是比较麻烦的,我们只能把图像存盘,然后docker cp出来查看.这个例子给了另一种玩法:让AIlice自己构建一个简易网站并运行,这个网站将images下的图像显示在它的页面上.你只需要在宿主机上用浏览器就可以查看结果啦.
  • “Please use python programming to solve the following tasks: obtain the price data of BTC-USDT for six months and draw it into a graph, and save it in the ‘images’ directory.” 如果你成功构建了前面的网站,这一步是可以直接看到结果的.如果看不到,请检查网站的images文件夹是否和这里的images文件夹不是一个(比如可能是在static/images下)?
  • “Please use cadquery to implement a cup.” 这是个比较有趣的玩法,Cadquery是个用python构建3d模型的CAD软件,你可以通过这个例子了解LLM对物理世界3d结构的理解.当然,接下来我实现了多模态后,我们可以让AIlice看到她自己建模出来的效果,从而能继续调整模型,形成一个非常有效的反馈机制,这样或许就可以实现真正可用的语言控制3D建模了.
  • “Please write an external interactive module. The function of the module is to obtain the content of related pages on the wiki through keywords.” 这就是自动扩展机制.AIlice可以自己构建外部交互模块并动态加载使用,而这只需要你的几句prompt提示和引导.这打开了无限的可能性空间.

架构设计

设计AIlice时的基本原则包括:
1. 通过高度动态的提示构建机制丰富LLM的行为;

2. 尽可能分离不同的计算任务,使用从传统计算中的递归和分而治之来解决复杂问题。

3. 代理间应能够双向交互