该项目是原始Autogen的叉子,但在打字稿中完成。
AIBITAT是一个无国状且可扩展的框架,旨在在允许人参与的同时在多个代理之间进行互动。
将其视为松弛,但对于AI代理商。创建代理,将它们添加到频道中,然后让他们相互聊天。您还可以在频道中添加顽固的代理商,并让他们参加对话。
有关更完整的示例,请查看示例文件夹。
您可以安装软件包:
# to install bun go to https://bun.sh and follow the instructions
# then run to start a new project:
mkdir my-project
cd my-project
bun init
# then install aibitat
bun install aibitat创建.env文件并添加您的OPENAI_API_KEY :
OPENAI_API_KEY=...然后创建一个称为index.ts的文件,并添加以下内容:
import { AIbitat } from 'aibitat'
import { cli } from 'aibitat/plugins'
const aibitat = new AIbitat ( )
. use ( cli ( ) )
. agent ( 'client' , {
interrupt : 'ALWAYS' ,
role : 'You are a human assistant. Reply "TERMINATE" when there is a correct answer or there`s no answer to the question.' ,
} )
. agent ( 'mathematician' , {
role : `You are a Mathematician and only solve math problems from @client` ,
} )
. agent ( 'reviewer' , {
role : `You are a Peer-Reviewer and you do not solve math problems.
Check the result from @mathematician and then confirm. Just confirm, no talk.` ,
} )
. channel ( 'management' , [ 'mathematician' , 'reviewer' , 'client' ] )
// aibitat.onMessage(console.log)
await aibitat . start ( {
from : 'client' ,
to : 'management' ,
content : 'How much is 2 + 2?' ,
} )
console . log ( aibitat . chats )然后运行:
bun run index.ts| 特征 | 它做什么 | 地位 |
|---|---|---|
| 直接消息 | 代理商直接交谈。 | ✅ |
| 反馈 | 保持聊天活力,直到某些代理商中断聊天为止。 | ✅ |
| 频道 | 代理商与许多其他人交谈,例如在松弛频道中。 | ✅ |
| 错误处理 | 平稳地管理速率限制而不会崩溃。 | ✅ |
| 函数执行 | 代理可以执行任务并了解结果。 | ✅ |
| 网络浏览 | 在互联网上导航。 | ? |
| 缓存 | 保存聊天历史记录以获取更快的API通话。 | ? |
| 文件交互 | 通过读/写/执行与本地文件进行交互 | ? |
| 代码执行 | 代理可以运行代码并共享结果。 | ? |
| 成本限制 | 按成本限制互动数量。 | ? |
| 提供者 | 地位 |
|---|---|
| Openai | ✅ |
| 人类 | ✅ |
| 共同 | ? |
| Fireworks.ai | ? |
| 拥抱脸 | ? |
| 复制 | ? |
本文档中使用的一些术语:
interrupt : NEVER , ALWAYS 。当NEVER ,代理人将永远不会中断对话。 ALWAYS ,代理商将始终中断对话。 (注意:如果他们回复“中断”或在回复“终止”时终止聊天,他们中的任何一个都可以中断对话。)role :代理人的角色。它用于描述代理商将在聊天中扮演的角色。maxRounds :代理商或组的最大聊天数量将回复对话。它用于防止循环。new AIbitat(config)创建一个新的AIBITAT实例。 config对象可用于配置实例。默认情况下,AIBITAT使用OpenAI和GPT-3.5-Turbo作为对话的提供商,以及GPT-4来预测下一个代理人会说话。您可以通过将provider和model传递给AIbitat构造函数或将其设置在特定代理/频道配置上来更改它。默认配置:
{
providers : 'openai' ,
model : 'gpt-3.5-turbo' ,
interrupt : 'NEVER' ,
maxRounds : 100 ,
chats : [
// {
// from: '?',
// to: '?',
// content: `Talk about something`,
// state: 'success',
// },
] ,
}.agent(name, config)创建一个新代理。 config对象可用于配置代理。默认情况下,代理使用来自AIbitat配置的interrupt 。
.channel(name, agents, config)创建一个新频道。 config对象可用于配置通道。默认情况下, maxRounds设置为100 。
.function(config)功能用于执行代码并将结果返回到对话中。要使用它,请调用传递该函数的定义的function方法,并将其名称添加到functions属性中:
const aibitat = new AIbitat ( )
. agent ( '...' , { functions : [ 'doSomething' ] } )
. function ( {
name : 'doSomething' ,
description : 'Let me do something for you.' ,
parameters : {
type : 'object' ,
properties : { } ,
} ,
async handler ( ) {
return '...'
} ,
} )结果将发送给提供商并返回对话。
.use(plugin)插件用于扩展AIBITAT的功能。它们可用于添加新功能或与其他服务集成。您可以通过实现AIbitatPlugin接口来创建自己的插件。
要使用插件,请调用use方法:
...
import { cli } from 'aibitat/plugins'
const aibitat = new AIbitat ( ) . use ( cli ( ) )您还可以通过实现AIbitatPlugin接口来创建自己的插件:
import { AIbitatPlugin } from 'aibitat'
export function myPlugin ( ) : AIbitatPlugin {
return {
name : 'my-plugin' ,
setup ( aibitat ) {
console . log ( `setting up my plugin` )
aibitat . onMessage ( ( { from , to , content } ) => {
console . log ( ` ${ from } : ${ content } ` )
} )
} ,
}
}可用插件列表:
cli :在聊天中添加CLI交互。fileHistory :将聊天历史记录保存到JSON文件中。默认为history记录文件夹”experimental_webBrowsing :在聊天中添加了web-browsing功能,使代理可以在Internet上进行搜索和导航。注意:此插件是实验性的,可能无法正常工作。AIBITAT支持生命周期事件,这在特定时刻触发。下图显示了对话的生命周期:

AIBITAT中的生命周期事件包括:
start :聊天开始时打电话。error :当存在已知错误时调用(请参阅src/error.ts )。要重试,请致电.retry() 。message :将消息添加到聊天历史记录时打电话。terminate :对话终止时打电话。通常意味着没有其他事情要做,应该开始新的对话。interrupt :当对话被代理商中断时打电话。通常意味着代理有问题或需要帮助。可以通过致电.continue(feedback)来恢复对话。 将.env.example文件复制到.env ,然后在其中添加您的键/令牌。
安装依赖项:
bun install运行:
bun run examples/beginner-chat.ts查看示例文件夹以获取更多示例。
该项目是在BUN V1.0.3中使用bun init创建的。 BUN是一个快速的多合一JavaScript运行时。
麻省理工学院