UNPKG

jcrewai

Version:

Multi-agent automation framework written in TypeScript. Patterned after CrewAI.

65 lines (64 loc) 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Crew = void 0; const Process_1 = require("./Process"); const I18N_1 = require("./utilities/I18N"); class Crew { constructor(agents, tasks, process = Process_1.Process.Sequential, verbose = false, customPrompts = {}) { this.agents = agents; this.tasks = tasks; this.process = process; this.verbose = verbose; this.customPrompts = customPrompts; this.taskOutputs = []; } async kickoff(inputs) { console.log(`Crew.kickoff: ${JSON.stringify(inputs)}`); // interpolate inputs if (inputs) { this.interpolateInputs(inputs); } const i18n = new I18N_1.I18N(this.customPrompts ?? {}); // loop through all agents to set i18n, crew, knowledge, function_calling_llm, step_callback, agent_executor for (const agent of this.agents) { agent.i18n = i18n; agent.crew = this; agent.createAgentExecutor(); } // run sequential process if (this.process === Process_1.Process.Sequential) { await this.runSequentialProcess(); } // TODO: Handle Process.Hierarchical } interpolateInputs(inputs) { for (const task of this.tasks) { task.interpolateInputs(inputs); } for (const agent of this.agents) { agent.interpolateInputs(inputs); } } async runSequentialProcess() { await this.executeTasks(this.tasks); } async executeTasks(tasks) { for (const task of tasks) { const agent = this.getAgent(task); if (agent) { const taskOutput = await task.execute(agent); this.taskOutputs.push(taskOutput); } else { throw new Error(`No agent available for task: ${task.description}. Ensure that either the task has an assigned agent or a manager agent is provided.`); } } } getAgent(task) { return this.agents.find(agent => agent.name === task.agent); } test() { console.log('Crew.test'); } } exports.Crew = Crew;