Openai Assistant Swarm Manager : OpenAI 조수를 군대로 바꾸는 도서관 .
| | Mintplex Labs Inc | NPM
OpenAi의 Assistant API는 자율적 인 AI 비서를 구축하거나 일반적으로 "에이전트"라고 불리는 개발자에게 놀라운 확신을 해제합니다. 이 노드 JS 라이브러리는 단일 API 호출을 통해 전체 사용자 정의 에이전트 레지스트리 및 해당 기능을 잠금 해제합니다. 한 에이전트 "관리자"는 이제 스마트하고 빠른 방법으로 한 또는 많은 다른 조수에게 작업을 쉽게 위임 할 수 있으므로 위임 된 작업의 작업을 쉽게 처리 할 수 있습니다.
어떤 조수가 현재 처리되고 활로 싸여 있는지 관리하는 모든 정신적 오버 헤드.
Swarm 관리자는 OpenAi Nodejs SDK의 확장 역할을합니다. beta.assistants 에서 사용할 수있는 새로운 .swarm 메소드를 사용할 수 있습니다.
먼저 Nodejs 용 OpenAi SDK를 설치하십시오
yarn add openai
# or
npm install openai 다음으로 openai-assistant-swarm 패키지를 설치하십시오
yarn add @mintplex-labs/openai-assistant-swarm
# or
npm install @mintplex-labs/openai-assistant-swarm이제 평소와 같이 SDK를 사용하고 확장 기능을 실행하고 에이전트 스와 암 관리자를 초기화하십시오.
// Enable the client for OpenAi as you normally would
const OpenAIClient = (
new OpenAI ( {
apiKey : process . env . OPEN_AI_KEY
} ) ) ;
// The simply call this function on the client to extend the OpenAI SDK to now have
// OpenAIClient.beta.assistants.swarm functions available.
EnableSwarmAbilities ( OpenAIClient , {
// all options are OPTIONAL
debug : false , // to see console log outputs of the process and playground links for debugging.
managerAssistantOptions : {
name : "[AUTOMATED] ___Swarm Manager" , // Name of created/maintained agent by the library
model : "gpt-4" , // Use gpt-4 for better reasoning and calling.
instructions : 'Instructions you are going to give the agent manager to delegate tasks to' ; // Override the default instructions.
} ;
} ) ;
// Initialize the swarm manager to create the swarm manager and also register it with
// your account. Swarm manager can be configured via options on `EnableSwarmAbilities`
await OpenAIClient . beta . assistants . swarm . init ( ) ;
// Now all swarm management function are available to you! 사용 가능한 3 명의 보조원 사이의 단일 입력을 위임하는 전체 예 ...
import OpenAI from 'openai' ;
import { EnableSwarmAbilities } from '@mintplex-labs/openai-assistant-swarm' ;
const OpenAIClient = new OpenAI ( { apiKey : process . env . OPEN_AI_KEY } ) ;
EnableSwarmAbilities ( OpenAIClient ) ;
await OpenAIClient . beta . assistants . swarm . init ( ) ;
// Optional - set up listeners here to wait for specific events to return to the user since streaming is not available yet.
// Run the main process on a single text prompt to have work delegate between all of your assistants that are available.
const response = OpenAIClient . beta . assistants . swarm . delegateWithPrompt ( 'What is the weather in New York city right now? Also what is the top stock for today?' ) ;
// For example. Given a Pirate bot, Weather Bot, and Stock Bot in your assistant registry on OpenAI.
// Run the below threads in parallel and return to you!
// |--> Will delegate to an existing Weather Bot
// |--> Will delegate to an existing Stock watcher Bot
// -> Pirate bot will not be invoked.
// -----
// The parent will respond with something like "I've arranged for two of our assistants to handle your requests. For assistance with stocks I have delegated that task to the Stock Bot, and for the weather update in San Francisco, our Weatherbot will provide the current conditions. They will take care of your needs shortly."
//
// You will then get a response once each child responds with either a completion or a `required_action` run you can handle in your codebase easily.
console . log ( {
parentRun : response . parentRun , // All information about the parent thread
subRuns : response . subRuns , // array of runs created and their status for each spun-out child thread!
} ) 프롬프트를 통한 위임
첫째, 아마도 당신이 관심있는 주요 - 하위 보조에 대한 대표단. 설정하기 쉽고 이벤트를 듣고 현재 워크 플로에 추가 할 수 있습니다.
// Set up an event listener for when the parent response is completed so you don't have to wait
// for parent + children responses to all complete.
// Useful to return the parent response early while you work on the subtask tool_calls that
// may or not be required depending on what happened.
OpenAIClient . beta . assistants . swarm . emitter . on ( 'parent_assistant_complete' , ( args ) => {
console . group ( 'Parent assistant response completed' ) ;
console . log ( args . parentRun . playground ) // => https://platform.openai.com/playground.... to debug thread & run in browser.
console . log ( args . parentRun . textResponse ) // => Yarrh! Want to be speaking to the captain do ya? Ill go fetch them ya land lubber.
// args.parentRun => The full Run object from OpenAI so you can get the thread_id and other properties like status.
console . log ( 'nn' )
console . groupEnd ( ) ;
} ) ;
// Set up an event listener for when the delegated assistant responses are completed so you don't have to wait
// for parent + children responses to all complete.
// From here you can handle all sub-run tool_calls if they are required to be run.
OpenAIClient . beta . assistants . swarm . emitter . on ( 'child_assistants_complete' , ( args ) => {
console . group ( 'Child assistant response completed' ) ;
console . log ( args . subRuns . map ( ( run ) => run . textResponse ) ) // => Yarrh! I am the captain of this vessel. Ye be after my treasure, Yar?
console . log ( args . subRuns . map ( ( run ) => run . playground ) ) // => https://platform.openai.com/playground.... to debug thread & run in browser.
// args.subRuns[x].run => The full Run object from OpenAI so you can get the thread_id and other properties like status.
console . log ( 'nn' )
console . groupEnd ( ) ;
} ) ;
// Set up and event listener to see every step event as it is completed:
OpenAIClient . beta . assistants . swarm . emitter . on ( 'poll_event' , ( { data } ) => {
console . group ( 'Poll event!' ) ;
console . log ( {
status : data . status ,
text : data . prompt || data . textResponse ,
runId : data ?. run ?. id ,
link : data . playground ,
runStatus : data ?. run ?. status ,
} )
console . log ( 'nn' )
console . groupEnd ( ) ;
} ) ;
// Run the main process on a single text prompt to have work delegate between all of the possible assistants that are available.
const response = OpenAIClient . beta . assistants . swarm . delegateWithPrompt ( 'Let me speak to the head pirate of this vessel! What say ye??' ) ;
// You can also just wait for the entire flow to finish instead of setting up listeners to keep the code more synchronous
console . log ( {
parentRun : response . parentRun ,
subRuns : response . subRuns ,
} )
// You can also focus the given task or prompt on a subset of assistants that you know you want to handle delegated work.
// OpenAIClient.beta.assistants.swarm.delegateWithPrompt('Let me speak to the head pirate of this vessel! What say ye??', ['asst_lead_pirate']);사용 가능한 모든 조교를 얻으십시오
지금은 질문에 대답하거나 과제를 처리하기 위해 누가 주변에 있는지 확인하기 위해 자격을 취득해야합니다. 이제 한 번만 전화를 걸 수 있고 우리는 당신을 위해 Pagination을 처리합니다.
const allAssistants = await OpenAIClient . beta . assistants . swarm . allAssistants ( ) ;
console . log ( `Found ${ allAssistants . length } assistants for this OpenAI Account` ) ;
// will be an array of assistant objects you can filter or manage. The Swarm Manager will not appear here.한 번에 많은 알려진 조수를 얻으십시오
API를 통해 한 번에 한 조수를 가져 오는 것으로 제한됩니다. 이제 한 번에 많은 것을 얻을 수 있습니다
const assistantIds = [ 'asst_customer_success' , 'asst_lead_pirate_manager' , 'asst_that_was_deleted' ]
const specificAssistants = await OpenAIClient . beta . assistants . swarm . getAssistants ( assistantIds ) ;
console . log ( `Found ${ specificAssistants . length } assistants from ${ assistantIds . length } ids given.` ) ;
// Will be an array of assistant objects you can filter or manage. The Swarm Manager will not appear here.
// Invalid assistants will not appear in the end result.