curaflow/backend/agents/InventoryAgent.js

35 lines
1.1 KiB
JavaScript

const BaseAgent = require('./BaseAgent');
class InventoryAgent extends BaseAgent {
constructor() {
super('InventoryAgent');
}
async execute(config, payload) {
const { itemName, currentStock, salesVelocity } = payload;
// config can hold the threshold
const threshold = config.low_stock_threshold || 10;
console.log(`[InventoryAgent] Checking stock for ${itemName} (Current: ${currentStock}, Threshold: ${threshold})`);
if (currentStock < threshold) {
console.log(`[InventoryAgent] 🚨 Stock is below threshold! Generating purchase order...`);
// In a real scenario, this would draft an email or WhatsApp to the vendor
const orderQty = (config.restock_amount || 50) + (salesVelocity || 0);
return {
action: 'DRAFT_PO',
item: itemName,
quantity: orderQty,
urgency: currentStock === 0 ? 'CRITICAL' : 'HIGH'
};
}
return { action: 'NONE', status: 'Healthy' };
}
}
module.exports = new InventoryAgent();