UNPKG

crewai-js

Version:

Unofficial CrewAI JavaScript SDK

58 lines (51 loc) 1.56 kB
// src/crews/Crew.ts import { Agent } from '../agents/Agent'; import { Task } from '../tasks/Task'; export interface CrewOptions { name: string; agents: Agent[]; // Array of agents tasks: Task[]; // Array of tasks verbose?: boolean; // Optional, default to false } export class Crew { name: string; agents: Agent[]; tasks: Task[]; verbose: boolean; constructor({ name, agents, tasks, verbose = false }: CrewOptions) { this.name = name; this.agents = agents; this.tasks = tasks; this.verbose = verbose; } // Method to kick off the crew and execute all tasks kickoff() { if (this.verbose) { console.log(`Crew ${this.name} is starting...`); } this.tasks.forEach(task => { if (this.verbose) { console.log(`Executing task: ${task.description}`); } const result = task.execute(); if (result instanceof Promise) { result.then(res => { if (this.verbose) { console.log(`Task result: ${res}`); } }); } else { if (this.verbose) { console.log(`Task result: ${result}`); } } }); } // Method to add a new task addTask(task: Task) { this.tasks.push(task); if (this.verbose) { console.log(`Task "${task.description}" added to Crew ${this.name}.`); } } }