jcrewai
Version:
Multi-agent automation framework written in TypeScript. Patterned after CrewAI.
67 lines (66 loc) • 2.44 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CrewBase = void 0;
const node_fs_1 = require("node:fs");
const yaml_1 = __importDefault(require("yaml"));
class CrewBase {
constructor() {
this.agentsConfig = {};
this.tasksConfig = {};
this.agents = [];
this.tasks = [];
this.llms = [];
this.agentsConfigPath = this.agentsConfigPath ?? './config/agents.yaml';
this.tasksConfigPath = this.tasksConfigPath ?? './config/tasks.yaml';
this.loadConfigs();
this.iterateDecorators();
}
loadConfigs() {
try {
const agentsConfig = this.loadConfig(this.agentsConfigPath);
this.agentsConfig = agentsConfig;
}
catch (error) {
console.warn(`Agent config file not found at ${this.agentsConfigPath}. Proceeding with empty agent configurations.`);
}
try {
const tasksConfig = this.loadConfig(this.tasksConfigPath);
this.tasksConfig = tasksConfig;
}
catch (error) {
console.warn(`Task config file not found at ${this.tasksConfigPath}. Proceeding with empty task configurations.`);
}
}
loadConfig(configPath) {
const file = (0, node_fs_1.readFileSync)(configPath, 'utf8');
return yaml_1.default.parse(file);
}
iterateDecorators() {
const agents = this.getDecoratedMethods('agent:methods');
this.agents = agents;
const tasks = this.getDecoratedMethods('task:methods');
this.tasks = tasks;
const crews = this.getDecoratedMethods('crew:methods');
this.crew = crews[0];
const llms = this.getDecoratedMethods('llm:methods');
this.llms = llms;
}
getDecoratedMethods(metadataKey) {
const list = [];
const agentMethods = Reflect.getMetadata(metadataKey, this) || [];
for (const methodName of agentMethods) {
if (typeof this[methodName] === 'function') {
// execute the method
const result = this[methodName]();
// set the name
result.name = methodName;
list.push(result);
}
}
return list;
}
}
exports.CrewBase = CrewBase;