function checkItemForSingleAgent(data, agent) {
    function isTargetDictionaryWithQuantities(target) {
        return typeof target === 'object' && 
               !Array.isArray(target) && 
               target !== null &&
               Object.values(target).every(value => typeof value === 'number');
    }
    
    function normalizeTargets(target) {
        if (typeof target === 'string') {
            return { [target]: 1 };
        } else if (Array.isArray(target)) {
            return target.reduce((acc, item) => {
                acc[item] = 1;
                return acc;
            }, {});
        } else if (typeof target === 'object' && target !== null) {
            return target;
        }
        throw new Error('Invalid target format');
    }
    
    function normalizeQuantities(targets, quantities) {
        if (quantities === undefined) {
            return Object.keys(targets).reduce((acc, key) => {
                acc[key] = 1;
                return acc;
            }, {});
        } else if (typeof quantities === 'number') {
            return Object.keys(targets).reduce((acc, key) => {
                acc[key] = quantities;
                return acc;
            }, {});
        } else if (typeof quantities === 'object' && quantities !== null) {
            return quantities;
        }
        throw new Error('Invalid number_of_target format');
    }
    
    // First normalize targets to always have a consistent format
    const targets = normalizeTargets(data.target);
    
    // Determine the required quantities
    const requiredQuantities = isTargetDictionaryWithQuantities(data.target) 
        ? data.target 
        : normalizeQuantities(targets, data.number_of_target);

    // Count items in inventory
    const inventoryCount = {};
    agent.bot.inventory.slots.forEach((slot) => {
        if (slot) {
            const itemName = slot.name.toLowerCase();
            inventoryCount[itemName] = (inventoryCount[itemName] || 0) + slot.count;
        }
    });

    // Check if all required items are present in sufficient quantities
    const missingItems = [];
    let allTargetsMet = true;

    for (const [item, requiredCount] of Object.entries(requiredQuantities)) {
        const itemName = item.toLowerCase();
        const currentCount = inventoryCount[itemName] || 0;
        if (currentCount < requiredCount) {
            allTargetsMet = false;
            missingItems.push({
                item: itemName,
                required: requiredCount,
                current: currentCount,
                missing: requiredCount - currentCount
            });
        }
    }

    return {
        success: allTargetsMet,
        missingItems: missingItems
    };
}
Helper function to check a single agent's inventory
Extracted from the original checkItemPresence logic