curaflow/backend/agents/BaseAgent.js

36 lines
1.2 KiB
JavaScript

class BaseAgent {
constructor(name) {
if (this.constructor === BaseAgent) {
throw new Error("Cannot instantiate abstract class BaseAgent");
}
this.name = name;
}
/**
* The core execution method that all agents must implement.
* @param {Object} config - The JSON configuration from the database.
* @param {Object} payload - Event specific data.
*/
async execute(config, payload) {
throw new Error(`Agent ${this.name} must implement execute() method.`);
}
/**
* Helper to mock LLM calls. In production, this would call OpenAI/Gemini.
*/
async mockLLMCall(prompt, responseMocks) {
console.log(`[${this.name}] Sending prompt to LLM...`);
// Simulate network delay
await new Promise(resolve => setTimeout(resolve, 800));
// Pick a mock response based on keywords or return default
const text = prompt.toLowerCase();
for (const [keyword, mockResponse] of Object.entries(responseMocks)) {
if (text.includes(keyword)) return mockResponse;
}
return responseMocks.default || "I cannot process this right now.";
}
}
module.exports = BaseAgent;